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[])
15 static const int magic[] = {
23 #elif defined RB_POWERDOWN
28 static const int signals[] = { SIGUSR1, SIGUSR2, SIGTERM };
31 int which, flags, rc = 1;
33 /* Figure out which applet we're running */
34 for (which = 0; "hpr"[which] != *applet_name; which++);
36 /* Parse and handle arguments */
37 flags = getopt32(argc, argv, "d:nf", &delay);
38 if (flags & 1) sleep(xatou(delay));
39 if (!(flags & 2)) sync();
42 if (ENABLE_INIT && !(flags & 4)) {
43 if (ENABLE_FEATURE_INITRD) {
44 pid_t *pidlist = find_pid_by_name("linuxrc");
46 rc = kill(pidlist[0], signals[which]);
47 if (ENABLE_FEATURE_CLEAN_UP)
51 rc = kill(1, signals[which]);
53 rc = reboot(magic[which]);