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
)
71 if (!strcmp("hard", arg
))
72 cmd
= LINUX_REBOOT_CMD_CAD_ON
;
73 else if (!strcmp("soft", arg
))
74 cmd
= LINUX_REBOOT_CMD_CAD_OFF
;
76 warnx(_("unknown argument: %s"), arg
);
79 if (reboot(cmd
) < 0) {
86 int main(int argc
, char **argv
)
89 static const struct option longopts
[] = {
90 {"version", no_argument
, NULL
, 'V'},
91 {"help", no_argument
, NULL
, 'h'},
95 setlocale(LC_ALL
, "");
96 bindtextdomain(PACKAGE
, LOCALEDIR
);
98 close_stdout_atexit();
100 while ((ch
= getopt_long(argc
, argv
, "Vh", longopts
, NULL
)) != -1)
103 print_version(EXIT_SUCCESS
);
107 errtryhelp(EXIT_FAILURE
);
113 ret
= set_cad(argv
[1]);