[PATCH] ctrlaltdel: Use err() instead of fprintf() and exit()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Marek Polacek <mmpolacek@xxxxxxxxx>
---
 sys-utils/ctrlaltdel.c |   45 ++++++++++++++++-----------------------------
 1 files changed, 16 insertions(+), 29 deletions(-)

diff --git a/sys-utils/ctrlaltdel.c b/sys-utils/ctrlaltdel.c
index beabc60..76b0048 100644
--- a/sys-utils/ctrlaltdel.c
+++ b/sys-utils/ctrlaltdel.c
@@ -1,48 +1,35 @@
 /*
  * ctrlaltdel.c - Set the function of the Ctrl-Alt-Del combination
  * Created 4-Jul-92 by Peter Orbaek <poe@xxxxxxxxxxxx>
- * ftp://ftp.daimi.aau.dk/pub/linux/poe/
  * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@xxxxxxxxxx>
  * - added Native Language Support
- *
  */

+#include <err.h>
 #include <stdio.h>
-#include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 #include "linux_reboot.h"
 #include "nls.h"

-int
-main(int argc, char *argv[]) {
-
+int main(int argc, char *argv[])
+{
 	setlocale(LC_ALL, "");
 	bindtextdomain(PACKAGE, LOCALEDIR);
 	textdomain(PACKAGE);
-	
-
-	if(geteuid()) {
-		fprintf(stderr,
-		    _("You must be root to set the Ctrl-Alt-Del behaviour.\n"));
-		exit(1);
-	}

-	if(argc == 2 && !strcmp("hard", argv[1])) {
-		if(my_reboot(LINUX_REBOOT_CMD_CAD_ON) < 0) {
-			perror("ctrlaltdel: reboot");
-			exit(1);
-		}
-	} else if(argc == 2 && !strcmp("soft", argv[1])) {
-		if(my_reboot(LINUX_REBOOT_CMD_CAD_OFF) < 0) {
-			perror("ctrlaltdel: reboot");
-			exit(1);
-		}
-	} else {
-		fprintf(stderr, _("Usage: ctrlaltdel hard|soft\n"));
-		exit(1);
-	}
-	exit(0);
-}
+	if (geteuid())
+		errx(EXIT_FAILURE,
+		     _("You must be root to set the Ctrl-Alt-Del behaviour"));

+	if (argc == 2 && !strcmp("hard", argv[1])) {
+		if (my_reboot(LINUX_REBOOT_CMD_CAD_ON) < 0)
+			err(EXIT_FAILURE, "ctrlaltdel: reboot");
+	} else if (argc == 2 && !strcmp("soft", argv[1])) {
+		if (my_reboot(LINUX_REBOOT_CMD_CAD_OFF) < 0)
+			err(EXIT_FAILURE, "ctrlaltdel: reboot");
+	} else
+		errx(EXIT_FAILURE, _("Usage: %s hard|soft"), argv[0]);

+	return EXIT_SUCCESS;
+}
-- 
1.7.3.1
--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux