40 |
#define RB_HALT_SYSTEM RB_HALT |
#define RB_HALT_SYSTEM RB_HALT |
41 |
#endif |
#endif |
42 |
|
|
43 |
|
#ifndef RB_POWERDOWN |
44 |
|
/* Stop system and switch power off if possible. */ |
45 |
|
# define RB_POWERDOWN 0x4321fedc |
46 |
|
#endif |
47 |
#ifndef RB_POWER_OFF |
#ifndef RB_POWER_OFF |
48 |
#define RB_POWER_OFF RB_POWERDOWN |
# define RB_POWER_OFF RB_POWERDOWN |
49 |
#endif |
#endif |
50 |
|
|
51 |
|
|
52 |
int halt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
int halt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
53 |
int halt_main(int argc UNUSED_PARAM, char **argv) |
int halt_main(int argc UNUSED_PARAM, char **argv) |
54 |
{ |
{ |
68 |
|
|
69 |
/* Parse and handle arguments */ |
/* Parse and handle arguments */ |
70 |
opt_complementary = "d+"; /* -d N */ |
opt_complementary = "d+"; /* -d N */ |
71 |
/* We support -w even if !ENABLE_FEATURE_WTMP, in order |
/* We support -w even if !ENABLE_FEATURE_WTMP, |
72 |
* to not break scripts */ |
* in order to not break scripts. |
73 |
flags = getopt32(argv, "d:nfw", &delay); |
* -i (shut down network interfaces) is ignored. |
74 |
|
*/ |
75 |
|
flags = getopt32(argv, "d:nfwi", &delay); |
76 |
|
|
77 |
sleep(delay); |
sleep(delay); |
78 |
|
|
90 |
//TODO: I tend to think that signalling linuxrc is wrong |
//TODO: I tend to think that signalling linuxrc is wrong |
91 |
// pity original author didn't comment on it... |
// pity original author didn't comment on it... |
92 |
if (ENABLE_FEATURE_INITRD) { |
if (ENABLE_FEATURE_INITRD) { |
93 |
|
/* talk to linuxrc */ |
94 |
|
/* bbox init/linuxrc assumed */ |
95 |
pid_t *pidlist = find_pid_by_name("linuxrc"); |
pid_t *pidlist = find_pid_by_name("linuxrc"); |
96 |
if (pidlist[0] > 0) |
if (pidlist[0] > 0) |
97 |
rc = kill(pidlist[0], signals[which]); |
rc = kill(pidlist[0], signals[which]); |
98 |
if (ENABLE_FEATURE_CLEAN_UP) |
if (ENABLE_FEATURE_CLEAN_UP) |
99 |
free(pidlist); |
free(pidlist); |
100 |
} |
} |
101 |
if (rc) |
if (rc) { |
102 |
rc = kill(1, signals[which]); |
/* talk to init */ |
103 |
} else |
if (!ENABLE_FEATURE_CALL_TELINIT) { |
104 |
|
/* bbox init assumed */ |
105 |
|
rc = kill(1, signals[which]); |
106 |
|
} else { |
107 |
|
/* SysV style init assumed */ |
108 |
|
/* runlevels: |
109 |
|
* 0 == shutdown |
110 |
|
* 6 == reboot */ |
111 |
|
rc = execlp(CONFIG_TELINIT_PATH, |
112 |
|
CONFIG_TELINIT_PATH, |
113 |
|
which == 2 ? "6" : "0", |
114 |
|
(char *)NULL |
115 |
|
); |
116 |
|
} |
117 |
|
} |
118 |
|
} else { |
119 |
rc = reboot(magic[which]); |
rc = reboot(magic[which]); |
120 |
|
} |
121 |
|
|
122 |
if (rc) |
if (rc) |
123 |
bb_error_msg("no"); |
bb_perror_nomsg_and_die(); |
124 |
return rc; |
return rc; |
125 |
} |
} |