summaryrefslogtreecommitdiffstats
path: root/sys-utils/ctrlaltdel.c
diff options
context:
space:
mode:
authorMarek Polacek2010-10-17 11:01:22 +0200
committerKarel Zak2010-10-21 13:28:45 +0200
commit0c3e5202406ce5ad9ee5ce018ce383607fd84c8c (patch)
tree63f103cf91a5aff3833f4b9a5f01140176534f24 /sys-utils/ctrlaltdel.c
parentlook: fix conflict between locally defined err() and glibc's version (diff)
downloadkernel-qcow2-util-linux-0c3e5202406ce5ad9ee5ce018ce383607fd84c8c.tar.gz
kernel-qcow2-util-linux-0c3e5202406ce5ad9ee5ce018ce383607fd84c8c.tar.xz
kernel-qcow2-util-linux-0c3e5202406ce5ad9ee5ce018ce383607fd84c8c.zip
ctrlaltdel: use err() instead of fprintf() and exit()
[kzak@redhat.com: - remove unnecessary program name from err(), - use program_invocation_short_name] Signed-off-by: Marek Polacek <mmpolacek@gmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/ctrlaltdel.c')
-rw-r--r--sys-utils/ctrlaltdel.c47
1 files changed, 18 insertions, 29 deletions
diff --git a/sys-utils/ctrlaltdel.c b/sys-utils/ctrlaltdel.c
index beabc6059..cfab79a3e 100644
--- a/sys-utils/ctrlaltdel.c
+++ b/sys-utils/ctrlaltdel.c
@@ -1,48 +1,37 @@
/*
* ctrlaltdel.c - Set the function of the Ctrl-Alt-Del combination
* Created 4-Jul-92 by Peter Orbaek <poe@daimi.aau.dk>
- * ftp://ftp.daimi.aau.dk/pub/linux/poe/
* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
* - added Native Language Support
- *
*/
+#include <err.h>
#include <stdio.h>
-#include <unistd.h>
#include <stdlib.h>
#include <string.h>
+#include <errno.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, "reboot");
+ } else if (argc == 2 && !strcmp("soft", argv[1])) {
+ if (my_reboot(LINUX_REBOOT_CMD_CAD_OFF) < 0)
+ err(EXIT_FAILURE, "reboot");
+ } else
+ errx(EXIT_FAILURE, _("Usage: %s hard|soft"),
+ program_invocation_short_name);
+ return EXIT_SUCCESS;
+}