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;delay[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 long *pidlist=find_pid_by_name("linuxrc");
45 if (*pidlist>0) rc = kill(*pidlist,signals[which]);
46 if (ENABLE_FEATURE_CLEAN_UP) free(pidlist);
48 if (rc) rc = kill(1,signals[which]);
49 } else rc = reboot(magic[which]);
51 if (rc) bb_error_msg("no");