1 /* vi: set sw=4 ts=4: */
3 * Poweroff reboot and halt, oh my.
5 * Copyright 2006 by Rob Landley <rob@landley.net>
7 * Licensed under GPL version 2, see file LICENSE in this tarball for details.
11 #include <sys/reboot.h>
13 int halt_main(int argc, char **argv);
14 int halt_main(int argc, char **argv)
16 static const int magic[] = {
24 #elif defined RB_POWERDOWN
29 static const int signals[] = { SIGUSR1, SIGUSR2, SIGTERM };
32 int which, flags, rc = 1;
34 /* Figure out which applet we're running */
35 for (which = 0; "hpr"[which] != *applet_name; which++);
37 /* Parse and handle arguments */
38 flags = getopt32(argc, argv, "d:nf", &delay);
39 if (flags & 1) sleep(xatou(delay));
40 if (!(flags & 2)) sync();
43 if (ENABLE_INIT && !(flags & 4)) {
44 if (ENABLE_FEATURE_INITRD) {
45 pid_t *pidlist = find_pid_by_name("linuxrc");
47 rc = kill(pidlist[0], signals[which]);
48 if (ENABLE_FEATURE_CLEAN_UP)
52 rc = kill(1, signals[which]);
54 rc = reboot(magic[which]);