Refactor ctrlaltdel(8)

1) Rewrite the manpage, don't just copy the util-linux manpage.
2) Fix usage() to reflect exclusivity of flags
3) Style changes.
This commit is contained in:
FRIGN 2015-09-07 13:02:38 +02:00 committed by sin
parent 6dedded859
commit 2d38b7cb9e
2 changed files with 23 additions and 24 deletions

View File

@ -1,30 +1,31 @@
.Dd February 2, 2015 .Dd September 7, 2015
.Dt CTRLALTDEL 8 .Dt CTRLALTDEL 8
.Os ubase .Os ubase
.Sh NAME .Sh NAME
.Nm ctrlaltdel .Nm ctrlaltdel
.Nd set the function of Ctrl-Alt-Del combination .Nd toggle Ctrl-Alt-Del behaviour
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl hs .Fl h | s
.Sh DESCRIPTION .Sh DESCRIPTION
Based on examination of the .Nm
.Pa linux/kernel/sys.c toggles the function of Ctrl-Alt-Del based on the
code, it is clear that there two choices given in
are two supported functions that the Ctrl-Alt-Del sequence can perform: a .Pa linux/kernel/sys.c :
hard reset, which immediately reboots the computer without calling .Bl -tag -width Ds
.Xr sync 2 .It hard reset
and without any other preparation; and a soft reset, which sends the reboot the computer immediately without calling
SIGINT (interrupt) signal to the init process (this is always the process .Xr sync 2 .
with PID 1). If this option is used, the .It soft reset
.Xr init 8 send SIGINT to
program must support this feature. .Xr init 8 .
.El
.Sh OPTIONS .Sh OPTIONS
.Bl -tag -width Ds .Bl -tag -width Ds
.It Fl h .It Fl h
Perform a hard reset. Set to hard reset.
.It Fl s .It Fl s
Perform a soft reset. Set to soft reset.
.El .El
.Sh SEE ALSO .Sh SEE ALSO
.Xr sync 2 , .Xr sync 2 ,

View File

@ -2,7 +2,6 @@
#include <sys/syscall.h> #include <sys/syscall.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include "reboot.h" #include "reboot.h"
@ -11,15 +10,13 @@
static void static void
usage(void) usage(void)
{ {
eprintf("usage: %s [-hs]\n", argv0); eprintf("usage: %s -h | -s\n", argv0);
} }
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int hflag = 0; int hflag = 0, sflag = 0, cmd;
int sflag = 0;
int cmd;
ARGBEGIN { ARGBEGIN {
case 'h': case 'h':
@ -32,13 +29,14 @@ main(int argc, char *argv[])
usage(); usage();
} ARGEND; } ARGEND;
if (argc > 0 || (hflag ^ sflag) == 0) if (argc || !(hflag ^ sflag))
usage(); usage();
cmd = hflag ? LINUX_REBOOT_CMD_CAD_ON : LINUX_REBOOT_CMD_CAD_OFF; cmd = hflag ? LINUX_REBOOT_CMD_CAD_ON : LINUX_REBOOT_CMD_CAD_OFF;
if (syscall(__NR_reboot, LINUX_REBOOT_MAGIC1, if (syscall(__NR_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,
LINUX_REBOOT_MAGIC2, cmd, NULL) < 0) cmd, NULL) < 0)
eprintf("reboot:"); eprintf("reboot:");
return 0; return 0;
} }