]> git.ipfire.org Git - thirdparty/util-linux.git/blob - sys-utils/ctrlaltdel.c
build-sys: fixes to USAGE_* macros
[thirdparty/util-linux.git] / sys-utils / ctrlaltdel.c
1 /*
2 * ctrlaltdel.c - Set the function of the Ctrl-Alt-Del combination
3 * Created 4-Jul-92 by Peter Orbaek <poe@daimi.aau.dk>
4 * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
5 * - added Native Language Support
6 */
7
8 #include <getopt.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <errno.h>
13 #include "linux_reboot.h"
14 #include "nls.h"
15 #include "c.h"
16
17 static void __attribute__ ((__noreturn__)) usage(FILE * out)
18 {
19 fprintf(out, USAGE_HEADER);
20 fprintf(out, _(" %s <hard|soft>\n"), program_invocation_short_name);
21 fprintf(out, USAGE_OPTIONS);
22 fprintf(out, USAGE_SEPARATOR);
23 fprintf(out, USAGE_HELP);
24 fprintf(out, USAGE_VERSION);
25 fprintf(out, USAGE_MAN_TAIL("ctrlaltdel(8)"));
26 exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
27 }
28
29 int main(int argc, char **argv)
30 {
31 int ch;
32 static const struct option longopts[] = {
33 {"version", no_argument, NULL, 'V'},
34 {"help", no_argument, NULL, 'h'},
35 {NULL, 0, NULL, 0}
36 };
37
38 setlocale(LC_ALL, "");
39 bindtextdomain(PACKAGE, LOCALEDIR);
40 textdomain(PACKAGE);
41
42 while ((ch = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
43 switch (ch) {
44 case 'V':
45 printf(UTIL_LINUX_VERSION);
46 return EXIT_SUCCESS;
47 case 'h':
48 usage(stdout);
49 default:
50 usage(stderr);
51 }
52
53 if (geteuid())
54 errx(EXIT_FAILURE,
55 _("You must be root to set the Ctrl-Alt-Del behaviour"));
56
57 if (argc == 2 && !strcmp("hard", argv[1])) {
58 if (my_reboot(LINUX_REBOOT_CMD_CAD_ON) < 0)
59 err(EXIT_FAILURE, "reboot");
60 } else if (argc == 2 && !strcmp("soft", argv[1])) {
61 if (my_reboot(LINUX_REBOOT_CMD_CAD_OFF) < 0)
62 err(EXIT_FAILURE, "reboot");
63 } else {
64 usage(stderr);
65 }
66
67 return EXIT_SUCCESS;
68 }