diff options
Diffstat (limited to 'init/halt.c')
-rw-r--r-- | init/halt.c | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/init/halt.c b/init/halt.c index 89efdd64a..34479742e 100644 --- a/init/halt.c +++ b/init/halt.c | |||
@@ -1,28 +1,42 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * Mini halt implementation for busybox | 3 | * Poweroff reboot and halt, oh my. |
4 | * | 4 | * |
5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> | 5 | * Copyright 2006 by Rob Landley <rob@landley.net> |
6 | * | 6 | * |
7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <signal.h> | 10 | #include <signal.h> |
11 | #include <stdlib.h> | ||
12 | #include <unistd.h> | ||
13 | #include <getopt.h> | ||
14 | #include <sys/reboot.h> | 11 | #include <sys/reboot.h> |
15 | #include "busybox.h" | 12 | #include "busybox.h" |
16 | #include "init_shared.h" | ||
17 | 13 | ||
14 | #include <unistd.h> | ||
18 | 15 | ||
19 | extern int halt_main(int argc, char **argv) | 16 | int halt_main(int argc, char *argv[]) |
20 | { | 17 | { |
21 | char *delay; /* delay in seconds before rebooting */ | 18 | char *delay = "hpr"; |
19 | int which, flags, magic[] = {RB_HALT_SYSTEM, RB_POWER_OFF, RB_AUTOBOOT}, | ||
20 | signals[] = {SIGUSR1, SIGUSR2, SIGTERM}, rc = 1; | ||
21 | |||
22 | /* Figure out which applet we're running */ | ||
23 | for(which=0;delay[which]!=*bb_applet_name;which++); | ||
22 | 24 | ||
23 | if(bb_getopt_ulflags(argc, argv, "d:", &delay)) { | 25 | /* Parse and handle arguments */ |
24 | sleep(atoi(delay)); | 26 | flags = bb_getopt_ulflags(argc, argv, "d:nf", &delay); |
25 | } | 27 | if (flags&1) sleep(atoi(delay)); |
28 | if (!(flags&2)) sync(); | ||
29 | |||
30 | /* Perform action. */ | ||
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); | ||
36 | } | ||
37 | if (rc) rc = kill(1,signals[which]); | ||
38 | } else rc = reboot(magic[which]); | ||
26 | 39 | ||
27 | return ENABLE_INIT ? kill(1,SIGUSR1) : bb_shutdown_system(RB_HALT_SYSTEM); | 40 | if (rc) bb_error_msg("No."); |
41 | return rc; | ||
28 | } | 42 | } |