]> git.ipfire.org Git - thirdparty/util-linux.git/blob - sys-utils/ctrlaltdel.c
merge coreutils' last GPL2 version of su.c
[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 #include "closestream.h"
17
18 static void __attribute__ ((__noreturn__)) usage(FILE * out)
19 {
20 fprintf(out, USAGE_HEADER);
21 fprintf(out, _(" %s <hard|soft>\n"), program_invocation_short_name);
22 fprintf(out, USAGE_OPTIONS);
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 atexit(close_stdout);
42
43 while ((ch = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
44 switch (ch) {
45 case 'V':
46 printf(UTIL_LINUX_VERSION);
47 return EXIT_SUCCESS;
48 case 'h':
49 usage(stdout);
50 default:
51 usage(stderr);
52 }
53
54 if (geteuid())
55 errx(EXIT_FAILURE,
56 _("You must be root to set the Ctrl-Alt-Del behaviour"));
57
58 if (argc == 2 && !strcmp("hard", argv[1])) {
59 if (my_reboot(LINUX_REBOOT_CMD_CAD_ON) < 0)
60 err(EXIT_FAILURE, "reboot");
61 } else if (argc == 2 && !strcmp("soft", argv[1])) {
62 if (my_reboot(LINUX_REBOOT_CMD_CAD_OFF) < 0)
63 err(EXIT_FAILURE, "reboot");
64 } else {
65 usage(stderr);
66 }
67
68 return EXIT_SUCCESS;
69 }