source: MondoRescue/branches/2.2.5/mindi-busybox/init/halt.c@ 3332

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

Update to busybox 1.7.2

File size: 1.2 KB
RevLine 
[821]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 *
[1765]7 * Licensed under GPL version 2, see file LICENSE in this tarball for details.
[821]8 */
9
[1765]10#include "libbb.h"
[821]11#include <sys/reboot.h>
12
[1765]13int halt_main(int argc, char **argv);
14int halt_main(int argc, char **argv)
[821]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 };
[1765]29 static const int signals[] = { SIGUSR1, SIGUSR2, SIGTERM };
[821]30
[1765]31 char *delay;
[821]32 int which, flags, rc = 1;
33
34 /* Figure out which applet we're running */
[1765]35 for (which = 0; "hpr"[which] != *applet_name; which++);
[821]36
37 /* Parse and handle arguments */
[1765]38 flags = getopt32(argv, "d:nf", &delay);
39 if (flags & 1) sleep(xatou(delay));
40 if (!(flags & 2)) sync();
[821]41
42 /* Perform action. */
43 if (ENABLE_INIT && !(flags & 4)) {
44 if (ENABLE_FEATURE_INITRD) {
[1765]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);
[821]50 }
[1765]51 if (rc)
52 rc = kill(1, signals[which]);
53 } else
54 rc = reboot(magic[which]);
[821]55
[1765]56 if (rc)
57 bb_error_msg("no");
[821]58 return rc;
59}
Note: See TracBrowser for help on using the repository browser.