2 * SPDX-License-Identifier: GPL-2.0-or-later
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * Copyright (C) 1992 Peter Orbaek <poe@daimi.aau.dk>
10 * Copyright (C) 1992-1993 Rickard E. Faith <faith@cs.unc.edu>
12 * Set the function of the Ctrl-Alt-Del combination
20 #include <sys/reboot.h>
23 #include "closestream.h"
24 #include "pathnames.h"
27 #define LINUX_REBOOT_CMD_CAD_ON 0x89ABCDEF
28 #define LINUX_REBOOT_CMD_CAD_OFF 0x00000000
30 static void __attribute__((__noreturn__
)) usage(void)
33 fputs(USAGE_HEADER
, out
);
34 fprintf(out
, _(" %s hard|soft\n"), program_invocation_short_name
);
36 fputs(USAGE_SEPARATOR
, out
);
37 fprintf(out
, _("Set the function of the Ctrl-Alt-Del combination.\n"));
39 fputs(USAGE_OPTIONS
, out
);
40 fprintf(out
, USAGE_HELP_OPTIONS(16));
41 fprintf(out
, USAGE_MAN_TAIL("ctrlaltdel(8)"));
45 static int get_cad(void)
49 if (ul_path_read_u64(NULL
, &val
, _PATH_PROC_CTRL_ALT_DEL
) != 0)
50 err(EXIT_FAILURE
, _("cannot read %s"), _PATH_PROC_CTRL_ALT_DEL
);
54 fputs("soft\n", stdout
);
57 fputs("hard\n", stdout
);
60 printf("%s hard\n", _("implicit"));
61 warnx(_("unexpected value in %s: %ju"), _PATH_PROC_CTRL_ALT_DEL
, val
);
67 static int set_cad(const char *arg
)
72 warnx(_("You must be root to set the Ctrl-Alt-Del behavior"));
75 if (!strcmp("hard", arg
))
76 cmd
= LINUX_REBOOT_CMD_CAD_ON
;
77 else if (!strcmp("soft", arg
))
78 cmd
= LINUX_REBOOT_CMD_CAD_OFF
;
80 warnx(_("unknown argument: %s"), arg
);
83 if (reboot(cmd
) < 0) {
90 int main(int argc
, char **argv
)
93 static const struct option longopts
[] = {
94 {"version", no_argument
, NULL
, 'V'},
95 {"help", no_argument
, NULL
, 'h'},
99 setlocale(LC_ALL
, "");
100 bindtextdomain(PACKAGE
, LOCALEDIR
);
102 close_stdout_atexit();
104 while ((ch
= getopt_long(argc
, argv
, "Vh", longopts
, NULL
)) != -1)
107 print_version(EXIT_SUCCESS
);
111 errtryhelp(EXIT_FAILURE
);
117 ret
= set_cad(argv
[1]);