2006-12-07 00:25:32 +01:00
|
|
|
|
/*
|
|
|
|
|
* ctrlaltdel.c - Set the function of the Ctrl-Alt-Del combination
|
|
|
|
|
* Created 4-Jul-92 by Peter Orbaek <poe@daimi.aau.dk>
|
2006-12-07 00:25:46 +01:00
|
|
|
|
* 1999-02-22 Arkadiusz Mi<EFBFBD>kiewicz <misiek@pld.ORG.PL>
|
2006-12-07 00:25:39 +01:00
|
|
|
|
* - added Native Language Support
|
2006-12-07 00:25:32 +01:00
|
|
|
|
*/
|
|
|
|
|
|
2011-08-31 20:52:01 +02:00
|
|
|
|
#include <getopt.h>
|
2006-12-07 00:25:32 +01:00
|
|
|
|
#include <stdio.h>
|
2006-12-07 00:25:44 +01:00
|
|
|
|
#include <stdlib.h>
|
2006-12-07 00:25:32 +01:00
|
|
|
|
#include <string.h>
|
2010-10-17 11:01:22 +02:00
|
|
|
|
#include <errno.h>
|
2006-12-07 00:25:37 +01:00
|
|
|
|
#include "linux_reboot.h"
|
2006-12-07 00:25:39 +01:00
|
|
|
|
#include "nls.h"
|
2011-01-25 22:44:52 +01:00
|
|
|
|
#include "c.h"
|
2006-12-07 00:25:32 +01:00
|
|
|
|
|
2011-08-31 20:52:01 +02:00
|
|
|
|
static void __attribute__ ((__noreturn__)) usage(FILE * out)
|
2010-10-17 11:01:22 +02:00
|
|
|
|
{
|
2011-08-31 20:52:01 +02:00
|
|
|
|
fprintf(out, USAGE_HEADER);
|
|
|
|
|
fprintf(out, _(" %s <hard|soft>\n"), program_invocation_short_name);
|
|
|
|
|
fprintf(out, USAGE_OPTIONS);
|
|
|
|
|
fprintf(out, USAGE_HELP);
|
|
|
|
|
fprintf(out, USAGE_VERSION);
|
2011-09-17 12:52:32 +02:00
|
|
|
|
fprintf(out, USAGE_MAN_TAIL("ctrlaltdel(8)"));
|
2011-08-31 20:52:01 +02:00
|
|
|
|
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
int ch;
|
|
|
|
|
static const struct option longopts[] = {
|
|
|
|
|
{"version", no_argument, NULL, 'V'},
|
|
|
|
|
{"help", no_argument, NULL, 'h'},
|
|
|
|
|
{NULL, 0, NULL, 0}
|
|
|
|
|
};
|
|
|
|
|
|
2006-12-07 00:25:39 +01:00
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
|
bindtextdomain(PACKAGE, LOCALEDIR);
|
|
|
|
|
textdomain(PACKAGE);
|
2006-12-07 00:25:32 +01:00
|
|
|
|
|
2011-08-31 20:52:01 +02:00
|
|
|
|
while ((ch = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
|
|
|
|
|
switch (ch) {
|
|
|
|
|
case 'V':
|
|
|
|
|
printf(UTIL_LINUX_VERSION);
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
|
case 'h':
|
|
|
|
|
usage(stdout);
|
|
|
|
|
default:
|
|
|
|
|
usage(stderr);
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-17 11:01:22 +02:00
|
|
|
|
if (geteuid())
|
|
|
|
|
errx(EXIT_FAILURE,
|
|
|
|
|
_("You must be root to set the Ctrl-Alt-Del behaviour"));
|
2006-12-07 00:25:32 +01:00
|
|
|
|
|
2010-10-17 11:01:22 +02:00
|
|
|
|
if (argc == 2 && !strcmp("hard", argv[1])) {
|
|
|
|
|
if (my_reboot(LINUX_REBOOT_CMD_CAD_ON) < 0)
|
|
|
|
|
err(EXIT_FAILURE, "reboot");
|
|
|
|
|
} else if (argc == 2 && !strcmp("soft", argv[1])) {
|
|
|
|
|
if (my_reboot(LINUX_REBOOT_CMD_CAD_OFF) < 0)
|
|
|
|
|
err(EXIT_FAILURE, "reboot");
|
2011-08-31 20:52:01 +02:00
|
|
|
|
} else {
|
|
|
|
|
usage(stderr);
|
|
|
|
|
}
|
2006-12-07 00:25:32 +01:00
|
|
|
|
|
2010-10-17 11:01:22 +02:00
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
|
}
|