From 46bb09c331f0466e6fd6a43d80b01f93f9046313 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 14 Feb 2021 04:20:42 +0100 Subject: [PATCH] Fix #145: default to power-off system, fix -h for shutdown command - Default to power-off the system, even for shutdown command - Fix -h switch for SysV init shutdown command compatibility - Add -P switch for systemd shutdown command compatibility Signed-off-by: Joachim Wiberg --- src/reboot.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/reboot.c b/src/reboot.c index e1c53e6d..aac059ba 100644 --- a/src/reboot.c +++ b/src/reboot.c @@ -51,9 +51,9 @@ static void transform(char *nm) nm = prognm; if (cmd == CMD_UNKNOWN) { - if (!strcmp(nm, "halt") || !strcmp(nm, "shutdown")) + if (!strcmp(nm, "halt")) cmd = CMD_HALT; - else if (!strcmp(nm, "poweroff")) + else if (!strcmp(nm, "poweroff") || !strcmp(nm, "shutdown")) cmd = CMD_POWEROFF; else if (!strcmp(nm, "suspend")) cmd = CMD_SUSPEND; @@ -94,11 +94,12 @@ static int usage(int rc) { fprintf(stderr, "Usage: %s [OPTIONS]\n\n" "Options:\n" - " -h, --help This help text\n" + " --help This help text\n" " -f, --force Force unsafe %s now, do not contact the init system.\n" " --halt Halt system, regardless of how the command is called.\n" - " -p, --poweroff Power-off system, regardless of how the command is called.\n" - " --reboot Reboot system, regardless of how the command is called.\n" + " -h Halt or power off after shutdown.\n" + " -P, --poweroff Power-off system, regardless of how the command is called.\n" + " -r, --reboot Reboot system, regardless of how the command is called.\n" "\n", prognm, msg); return rc; @@ -119,9 +120,8 @@ int main(int argc, char *argv[]) /* Initial command taken from program name */ transform(progname(argv[0])); - while ((c = getopt_long(argc, argv, "h?fHpr", long_options, NULL)) != EOF) { + while ((c = getopt_long(argc, argv, "h?fHPpr", long_options, NULL)) != EOF) { switch(c) { - case 'h': case '?': return usage(0); @@ -133,6 +133,8 @@ int main(int argc, char *argv[]) cmd = CMD_HALT; break; + case 'h': + case 'P': case 'p': cmd = CMD_POWEROFF; break;