[hackers] [ubase] Refactor ctrlaltdel(8) || FRIGN

From: <git_AT_suckless.org>
Date: Mon, 7 Sep 2015 13:10:22 +0200 (CEST)

commit 2d38b7cb9e4083c060b412c150823396e82ee2e7
Author: FRIGN <dev_AT_frign.de>
AuthorDate: Mon Sep 7 13:02:38 2015 +0200
Commit: sin <sin_AT_2f30.org>
CommitDate: Mon Sep 7 12:09:59 2015 +0100

    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.

diff --git a/ctrlaltdel.8 b/ctrlaltdel.8
index c511bfb..d579113 100644
--- a/ctrlaltdel.8
+++ b/ctrlaltdel.8
_AT_@ -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 ,
diff --git a/ctrlaltdel.c b/ctrlaltdel.c
index 196b4d6..29a23c5 100644
--- a/ctrlaltdel.c
+++ b/ctrlaltdel.c
_AT_@ -2,7 +2,6 @@
 #include <sys/syscall.h>
 
 #include <stdio.h>
-#include <stdlib.h>
 #include <unistd.h>
 
 #include "reboot.h"
_AT_@ -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':
_AT_@ -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;
 }
Received on Mon Sep 07 2015 - 13:10:22 CEST

This archive was generated by hypermail 2.3.0 : Mon Sep 07 2015 - 13:12:12 CEST