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.
11 #include <sys/reboot.h>
16 int halt_main(int argc, char *argv[])
19 int which, flags, magic[] = {RB_HALT_SYSTEM, RB_POWER_OFF, RB_AUTOBOOT},
20 signals[] = {SIGUSR1, SIGUSR2, SIGTERM}, rc = 1;
22 /* Figure out which applet we're running */
23 for(which=0;delay[which]!=*bb_applet_name;which++);
25 /* Parse and handle arguments */
26 flags = bb_getopt_ulflags(argc, argv, "d:nf", &delay);
27 if (flags&1) sleep(atoi(delay));
28 if (!(flags&2)) sync();
31 if (ENABLE_INIT && !(flags & 4)) {
32 if (ENABLE_FEATURE_INITRD) {
33 long *pidlist=find_pid_by_name("linuxrc");
34 if (*pidlist>0) rc = kill(*pidlist,signals[which]);
35 if (ENABLE_FEATURE_CLEAN_UP) free(pidlist);
37 if (rc) rc = kill(1,signals[which]);
38 } else rc = reboot(magic[which]);
40 if (rc) bb_error_msg("No.");