summaryrefslogtreecommitdiffstats
path: root/sys-utils/ctrlaltdel.c
diff options
context:
space:
mode:
authorSami Kerola2015-10-13 01:35:42 +0200
committerSami Kerola2015-10-18 19:03:47 +0200
commit8137c98f8391e49b296ec37c928dd0882c1f0376 (patch)
tree82b12ba1e27db5951b16b8a4bad262cecda1efb6 /sys-utils/ctrlaltdel.c
parentnologin: require /etc/nologin.txt to be file (diff)
downloadkernel-qcow2-util-linux-8137c98f8391e49b296ec37c928dd0882c1f0376.tar.gz
kernel-qcow2-util-linux-8137c98f8391e49b296ec37c928dd0882c1f0376.tar.xz
kernel-qcow2-util-linux-8137c98f8391e49b296ec37c928dd0882c1f0376.zip
ctrlaltdel: improve error messaging
Tell user what is wrong rather than print usage(). Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'sys-utils/ctrlaltdel.c')
-rw-r--r--sys-utils/ctrlaltdel.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/sys-utils/ctrlaltdel.c b/sys-utils/ctrlaltdel.c
index 8f646e5ac..64de94f79 100644
--- a/sys-utils/ctrlaltdel.c
+++ b/sys-utils/ctrlaltdel.c
@@ -21,7 +21,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
fprintf(out, _(" %s hard|soft\n"), program_invocation_short_name);
fprintf(out, USAGE_SEPARATOR);
- fprintf(out, "Set the function of the Ctrl-Alt-Del combination.\n");
+ fprintf(out, _("Set the function of the Ctrl-Alt-Del combination.\n"));
fprintf(out, USAGE_OPTIONS);
fprintf(out, USAGE_HELP);
@@ -33,6 +33,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
int main(int argc, char **argv)
{
int ch;
+ unsigned int cmd;
static const struct option longopts[] = {
{"version", no_argument, NULL, 'V'},
{"help", no_argument, NULL, 'h'},
@@ -59,15 +60,15 @@ int main(int argc, char **argv)
errx(EXIT_FAILURE,
_("You must be root to set the Ctrl-Alt-Del behavior"));
- 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");
- } else {
- usage(stderr);
- }
-
+ if (argc < 2)
+ errx(EXIT_FAILURE, _("not enough arguments"));
+ if (!strcmp("hard", argv[1]))
+ cmd = LINUX_REBOOT_CMD_CAD_ON;
+ else if (!strcmp("soft", argv[1]))
+ cmd = LINUX_REBOOT_CMD_CAD_OFF;
+ else
+ errx(EXIT_FAILURE, _("unknown argument: %s"), argv[1]);
+ if (my_reboot(cmd) < 0)
+ err(EXIT_FAILURE, "reboot");
return EXIT_SUCCESS;
}