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
14 #include <sys/reboot.h>
17 #include "closestream.h"
18 #include "pathnames.h"
21 #define LINUX_REBOOT_CMD_CAD_ON 0x89ABCDEF
22 #define LINUX_REBOOT_CMD_CAD_OFF 0x00000000
24 static void __attribute__((__noreturn__
)) usage(void)
27 fputs(USAGE_HEADER
, out
);
28 fprintf(out
, _(" %s hard|soft\n"), program_invocation_short_name
);
30 fputs(USAGE_SEPARATOR
, out
);
31 fprintf(out
, _("Set the function of the Ctrl-Alt-Del combination.\n"));
33 fputs(USAGE_OPTIONS
, out
);
34 fputs(USAGE_HELP
, out
);
35 fputs(USAGE_VERSION
,out
);
36 fprintf(out
, USAGE_MAN_TAIL("ctrlaltdel(8)"));
40 static int get_cad(void)
42 uint64_t val
= path_read_u64(_PATH_PROC_CTRL_ALT_DEL
);
46 fputs("soft\n", stdout
);
49 fputs("hard\n", stdout
);
52 printf("%s hard\n", _("implicit"));
53 warnx(_("unexpected value in %s: %ju"), _PATH_PROC_CTRL_ALT_DEL
, val
);
59 static int set_cad(const char *arg
)
64 warnx(_("You must be root to set the Ctrl-Alt-Del behavior"));
67 if (!strcmp("hard", arg
))
68 cmd
= LINUX_REBOOT_CMD_CAD_ON
;
69 else if (!strcmp("soft", arg
))
70 cmd
= LINUX_REBOOT_CMD_CAD_OFF
;
72 warnx(_("unknown argument: %s"), arg
);
75 if (reboot(cmd
) < 0) {
82 int main(int argc
, char **argv
)
85 static const struct option longopts
[] = {
86 {"version", no_argument
, NULL
, 'V'},
87 {"help", no_argument
, NULL
, 'h'},
91 setlocale(LC_ALL
, "");
92 bindtextdomain(PACKAGE
, LOCALEDIR
);
96 while ((ch
= getopt_long(argc
, argv
, "Vh", longopts
, NULL
)) != -1)
99 printf(UTIL_LINUX_VERSION
);
104 errtryhelp(EXIT_FAILURE
);
110 ret
= set_cad(argv
[1]);