source: MondoRescue/branches/2.2.8/mindi-busybox/init/halt.c@ 3628

Last change on this file since 3628 was 1765, checked in by Bruno Cornec, 16 years ago

Update to busybox 1.7.2

File size: 1.2 KB
Line 
1/* vi: set sw=4 ts=4: */
2/*
3 * Poweroff reboot and halt, oh my.
4 *
5 * Copyright 2006 by Rob Landley <rob@landley.net>
6 *
7 * Licensed under GPL version 2, see file LICENSE in this tarball for details.
8 */
9
10#include "libbb.h"
11#include <sys/reboot.h>
12
13int halt_main(int argc, char **argv);
14int halt_main(int argc, char **argv)
15{
16 static const int magic[] = {
17#ifdef RB_HALT_SYSTEM
18RB_HALT_SYSTEM,
19#elif defined RB_HALT
20RB_HALT,
21#endif
22#ifdef RB_POWER_OFF
23RB_POWER_OFF,
24#elif defined RB_POWERDOWN
25RB_POWERDOWN,
26#endif
27RB_AUTOBOOT
28 };
29 static const int signals[] = { SIGUSR1, SIGUSR2, SIGTERM };
30
31 char *delay;
32 int which, flags, rc = 1;
33
34 /* Figure out which applet we're running */
35 for (which = 0; "hpr"[which] != *applet_name; which++);
36
37 /* Parse and handle arguments */
38 flags = getopt32(argv, "d:nf", &delay);
39 if (flags & 1) sleep(xatou(delay));
40 if (!(flags & 2)) sync();
41
42 /* Perform action. */
43 if (ENABLE_INIT && !(flags & 4)) {
44 if (ENABLE_FEATURE_INITRD) {
45 pid_t *pidlist = find_pid_by_name("linuxrc");
46 if (pidlist[0] > 0)
47 rc = kill(pidlist[0], signals[which]);
48 if (ENABLE_FEATURE_CLEAN_UP)
49 free(pidlist);
50 }
51 if (rc)
52 rc = kill(1, signals[which]);
53 } else
54 rc = reboot(magic[which]);
55
56 if (rc)
57 bb_error_msg("no");
58 return rc;
59}
Note: See TracBrowser for help on using the repository browser.