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

View File

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