Browse Source

halt: behave like poweroff

master 0.3.7
M. Herdiansyah 4 years ago
parent
commit
10f4ffc939
  1. 22
      halt.c

22
halt.c

@ -17,7 +17,7 @@
extern char *__progname;
typedef enum {NOOP, HALT, REBOOT, POWEROFF} action_type;
typedef enum {NOOP, REBOOT, POWEROFF} action_type;
typedef enum {OPENRC, RUNIT} initsys;
const char* get_init()
@ -56,11 +56,9 @@ int main(int argc, char *argv[])
init = RUNIT;
else init = OPENRC;
if (strcmp(__progname, "halt") == 0)
action = HALT;
else if (strcmp(__progname, "reboot") == 0)
if (strcmp(__progname, "reboot") == 0)
action = REBOOT;
else if (strcmp(__progname, "poweroff") == 0 || strcmp(__progname, "shutdown") == 0)
else if (strcmp(__progname, "halt") == 0 || strcmp(__progname, "poweroff") == 0 || strcmp(__progname, "shutdown") == 0)
action = POWEROFF;
else
warnx("No default behavior, needs to be called as halt/reboot/poweroff/shutdown.");
@ -94,20 +92,6 @@ int main(int argc, char *argv[])
sync();
switch (action) {
case HALT:
if (do_force)
reboot(RB_HALT_SYSTEM);
else
switch (init) {
case RUNIT:
execl("/usr/bin/runit-init", "init", "0", (char*)0);
break;
case OPENRC:
execl("/usr/bin/openrc-shutdown", "openrc-shutdown", "--halt", openrc_options, (char*)0);
break;
}
err(1, "halt failed");
break;
case POWEROFF:
if (do_force)
reboot(RB_POWER_OFF);