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 GPLv2 or later, see file LICENSE in this tarball for details.
12 #include <sys/reboot.h>
15 int halt_main(int argc, char *argv[])
17 static const int magic[] = {
25 #elif defined RB_POWERDOWN
30 static const int signals[] = {SIGUSR1, SIGUSR2, SIGTERM};
33 int which, flags, rc = 1;
35 /* Figure out which applet we're running */
36 for(which=0;delay[which]!=*bb_applet_name;which++);
38 /* Parse and handle arguments */
39 flags = bb_getopt_ulflags(argc, argv, "d:nf", &delay);
40 if (flags&1) sleep(atoi(delay));
41 if (!(flags&2)) sync();
44 if (ENABLE_INIT && !(flags & 4)) {
45 if (ENABLE_FEATURE_INITRD) {
46 long *pidlist=find_pid_by_name("linuxrc");
47 if (*pidlist>0) rc = kill(*pidlist,signals[which]);
48 if (ENABLE_FEATURE_CLEAN_UP) free(pidlist);
50 if (rc) rc = kill(1,signals[which]);
51 } else rc = reboot(magic[which]);
53 if (rc) bb_error_msg("No.");