source: MondoRescue/branches/stable/mindi-busybox/init/halt.c @ 821

Last change on this file since 821 was 821, checked in by Bruno Cornec, 14 years ago

Addition of busybox 1.2.1 as a mindi-busybox new package
This should avoid delivering binary files in mindi not built there (Fedora and Debian are quite serious about that)

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 GPLv2 or later, see file LICENSE in this tarball for details.
8 */
9
10#include "busybox.h"
11#include <signal.h>
12#include <sys/reboot.h>
13#include <unistd.h>
14
15int halt_main(int argc, char *argv[])
16{
17    static const int magic[] = {
18#ifdef RB_HALT_SYSTEM
19RB_HALT_SYSTEM,
20#elif defined RB_HALT
21RB_HALT,
22#endif
23#ifdef RB_POWER_OFF
24RB_POWER_OFF,
25#elif defined RB_POWERDOWN
26RB_POWERDOWN,
27#endif
28RB_AUTOBOOT
29    };
30    static const int signals[] = {SIGUSR1, SIGUSR2, SIGTERM};
31
32    char *delay = "hpr";
33    int which, flags, rc = 1;
34
35    /* Figure out which applet we're running */
36    for(which=0;delay[which]!=*bb_applet_name;which++);
37
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();
42
43    /* Perform action. */
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);
49        }
50        if (rc) rc = kill(1,signals[which]);
51    } else rc = reboot(magic[which]);
52
53    if (rc) bb_error_msg("No.");
54    return rc;
55}
Note: See TracBrowser for help on using the repository browser.