diff options
Diffstat (limited to 'init')
-rw-r--r-- | init/Config.src | 12 | ||||
-rw-r--r-- | init/bootchartd.c | 19 | ||||
-rw-r--r-- | init/halt.c | 14 | ||||
-rw-r--r-- | init/init.c | 35 | ||||
-rw-r--r-- | init/reboot.h | 30 |
5 files changed, 81 insertions, 29 deletions
diff --git a/init/Config.src b/init/Config.src index 590e29890..2cac3573e 100644 --- a/init/Config.src +++ b/init/Config.src | |||
@@ -89,6 +89,18 @@ config FEATURE_INITRD | |||
89 | This does not apply to initramfs, which runs /init as PID 1 and | 89 | This does not apply to initramfs, which runs /init as PID 1 and |
90 | requires no special support. | 90 | requires no special support. |
91 | 91 | ||
92 | config INIT_TERMINAL_TYPE | ||
93 | string "Initial terminal type" | ||
94 | default "linux" | ||
95 | depends on INIT | ||
96 | help | ||
97 | This is the initial value set by init for the TERM environment | ||
98 | variable. This variable is used by programs which make use of | ||
99 | extended terminal capabilities. | ||
100 | |||
101 | Note that on Linux, init attempts to detect serial terminal and | ||
102 | sets TERM to "vt102" if one is found. | ||
103 | |||
92 | config HALT | 104 | config HALT |
93 | bool "poweroff, halt, and reboot" | 105 | bool "poweroff, halt, and reboot" |
94 | default y | 106 | default y |
diff --git a/init/bootchartd.c b/init/bootchartd.c index dae2fe6e9..465a34979 100644 --- a/init/bootchartd.c +++ b/init/bootchartd.c | |||
@@ -45,12 +45,15 @@ | |||
45 | #include "libbb.h" | 45 | #include "libbb.h" |
46 | /* After libbb.h, since it needs sys/types.h on some systems */ | 46 | /* After libbb.h, since it needs sys/types.h on some systems */ |
47 | #include <sys/utsname.h> | 47 | #include <sys/utsname.h> |
48 | #include <sys/mount.h> | 48 | |
49 | #ifndef MS_SILENT | 49 | #ifdef __linux__ |
50 | # define MS_SILENT (1 << 15) | 50 | # include <sys/mount.h> |
51 | #endif | 51 | # ifndef MS_SILENT |
52 | #ifndef MNT_DETACH | 52 | # define MS_SILENT (1 << 15) |
53 | # define MNT_DETACH 0x00000002 | 53 | # endif |
54 | # ifndef MNT_DETACH | ||
55 | # define MNT_DETACH 0x00000002 | ||
56 | # endif | ||
54 | #endif | 57 | #endif |
55 | 58 | ||
56 | #define BC_VERSION_STR "0.8" | 59 | #define BC_VERSION_STR "0.8" |
@@ -174,6 +177,7 @@ static char *make_tempdir(void) | |||
174 | char template[] = "/tmp/bootchart.XXXXXX"; | 177 | char template[] = "/tmp/bootchart.XXXXXX"; |
175 | char *tempdir = xstrdup(mkdtemp(template)); | 178 | char *tempdir = xstrdup(mkdtemp(template)); |
176 | if (!tempdir) { | 179 | if (!tempdir) { |
180 | #ifdef __linux__ | ||
177 | /* /tmp is not writable (happens when we are used as init). | 181 | /* /tmp is not writable (happens when we are used as init). |
178 | * Try to mount a tmpfs, them cd and lazily unmount it. | 182 | * Try to mount a tmpfs, them cd and lazily unmount it. |
179 | * Since we unmount it at once, we can mount it anywhere. | 183 | * Since we unmount it at once, we can mount it anywhere. |
@@ -191,6 +195,9 @@ static char *make_tempdir(void) | |||
191 | if (umount2(try_dir, MNT_DETACH) != 0) { | 195 | if (umount2(try_dir, MNT_DETACH) != 0) { |
192 | bb_perror_msg_and_die("can't %smount tmpfs", "un"); | 196 | bb_perror_msg_and_die("can't %smount tmpfs", "un"); |
193 | } | 197 | } |
198 | #else | ||
199 | bb_perror_msg_and_die("can't create temporary directory"); | ||
200 | #endif | ||
194 | } else { | 201 | } else { |
195 | xchdir(tempdir); | 202 | xchdir(tempdir); |
196 | } | 203 | } |
diff --git a/init/halt.c b/init/halt.c index f1bb2c4a8..abd801fda 100644 --- a/init/halt.c +++ b/init/halt.c | |||
@@ -8,7 +8,7 @@ | |||
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include "libbb.h" | 10 | #include "libbb.h" |
11 | #include <sys/reboot.h> | 11 | #include "reboot.h" |
12 | 12 | ||
13 | #if ENABLE_FEATURE_WTMP | 13 | #if ENABLE_FEATURE_WTMP |
14 | #include <sys/utsname.h> | 14 | #include <sys/utsname.h> |
@@ -36,18 +36,6 @@ static void write_wtmp(void) | |||
36 | #define write_wtmp() ((void)0) | 36 | #define write_wtmp() ((void)0) |
37 | #endif | 37 | #endif |
38 | 38 | ||
39 | #ifndef RB_HALT_SYSTEM | ||
40 | #define RB_HALT_SYSTEM RB_HALT | ||
41 | #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 | ||
48 | # define RB_POWER_OFF RB_POWERDOWN | ||
49 | #endif | ||
50 | |||
51 | 39 | ||
52 | int halt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 40 | int halt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
53 | int halt_main(int argc UNUSED_PARAM, char **argv) | 41 | int halt_main(int argc UNUSED_PARAM, char **argv) |
diff --git a/init/init.c b/init/init.c index 2eb8f1a54..fa1af6d7c 100644 --- a/init/init.c +++ b/init/init.c | |||
@@ -12,13 +12,21 @@ | |||
12 | #include "libbb.h" | 12 | #include "libbb.h" |
13 | #include <syslog.h> | 13 | #include <syslog.h> |
14 | #include <paths.h> | 14 | #include <paths.h> |
15 | #include <sys/reboot.h> | ||
16 | #include <sys/resource.h> | 15 | #include <sys/resource.h> |
16 | #ifdef __linux__ | ||
17 | #include <linux/vt.h> | 17 | #include <linux/vt.h> |
18 | #endif | ||
18 | #if ENABLE_FEATURE_UTMP | 19 | #if ENABLE_FEATURE_UTMP |
19 | # include <utmp.h> /* DEAD_PROCESS */ | 20 | # include <utmp.h> /* DEAD_PROCESS */ |
20 | #endif | 21 | #endif |
22 | #include "reboot.h" /* reboot() constants */ | ||
21 | 23 | ||
24 | /* Used only for sanitizing purposes in set_sane_term() below. On systems where | ||
25 | * the baud rate is stored in a separate field, we can safely disable them. */ | ||
26 | #ifndef CBAUD | ||
27 | # define CBAUD 0 | ||
28 | # define CBAUDEX 0 | ||
29 | #endif | ||
22 | 30 | ||
23 | /* Was a CONFIG_xxx option. A lot of people were building | 31 | /* Was a CONFIG_xxx option. A lot of people were building |
24 | * not fully functional init by switching it on! */ | 32 | * not fully functional init by switching it on! */ |
@@ -89,13 +97,6 @@ static const char *log_console = VC_5; | |||
89 | enum { | 97 | enum { |
90 | L_LOG = 0x1, | 98 | L_LOG = 0x1, |
91 | L_CONSOLE = 0x2, | 99 | L_CONSOLE = 0x2, |
92 | #ifndef RB_HALT_SYSTEM | ||
93 | RB_HALT_SYSTEM = 0xcdef0123, /* FIXME: this overflows enum */ | ||
94 | RB_ENABLE_CAD = 0x89abcdef, | ||
95 | RB_DISABLE_CAD = 0, | ||
96 | RB_POWER_OFF = 0x4321fedc, | ||
97 | RB_AUTOBOOT = 0x01234567, | ||
98 | #endif | ||
99 | }; | 100 | }; |
100 | 101 | ||
101 | /* Print a message to the specified device. | 102 | /* Print a message to the specified device. |
@@ -166,7 +167,9 @@ static void message(int where, const char *fmt, ...) | |||
166 | 167 | ||
167 | static void console_init(void) | 168 | static void console_init(void) |
168 | { | 169 | { |
170 | #ifdef VT_OPENQRY | ||
169 | int vtno; | 171 | int vtno; |
172 | #endif | ||
170 | char *s; | 173 | char *s; |
171 | 174 | ||
172 | s = getenv("CONSOLE"); | 175 | s = getenv("CONSOLE"); |
@@ -190,6 +193,7 @@ static void console_init(void) | |||
190 | } | 193 | } |
191 | 194 | ||
192 | s = getenv("TERM"); | 195 | s = getenv("TERM"); |
196 | #ifdef VT_OPENQRY | ||
193 | if (ioctl(STDIN_FILENO, VT_OPENQRY, &vtno) != 0) { | 197 | if (ioctl(STDIN_FILENO, VT_OPENQRY, &vtno) != 0) { |
194 | /* Not a linux terminal, probably serial console. | 198 | /* Not a linux terminal, probably serial console. |
195 | * Force the TERM setting to vt102 | 199 | * Force the TERM setting to vt102 |
@@ -198,8 +202,10 @@ static void console_init(void) | |||
198 | putenv((char*)"TERM=vt102"); | 202 | putenv((char*)"TERM=vt102"); |
199 | if (!ENABLE_FEATURE_INIT_SYSLOG) | 203 | if (!ENABLE_FEATURE_INIT_SYSLOG) |
200 | log_console = NULL; | 204 | log_console = NULL; |
201 | } else if (!s) | 205 | } else |
202 | putenv((char*)"TERM=linux"); | 206 | #endif |
207 | if (!s) | ||
208 | putenv((char*)"TERM=" CONFIG_INIT_TERMINAL_TYPE); | ||
203 | } | 209 | } |
204 | 210 | ||
205 | /* Set terminal settings to reasonable defaults. | 211 | /* Set terminal settings to reasonable defaults. |
@@ -220,8 +226,10 @@ static void set_sane_term(void) | |||
220 | tty.c_cc[VSTOP] = 19; /* C-s */ | 226 | tty.c_cc[VSTOP] = 19; /* C-s */ |
221 | tty.c_cc[VSUSP] = 26; /* C-z */ | 227 | tty.c_cc[VSUSP] = 26; /* C-z */ |
222 | 228 | ||
229 | #ifdef __linux__ | ||
223 | /* use line discipline 0 */ | 230 | /* use line discipline 0 */ |
224 | tty.c_line = 0; | 231 | tty.c_line = 0; |
232 | #endif | ||
225 | 233 | ||
226 | /* Make it be sane */ | 234 | /* Make it be sane */ |
227 | tty.c_cflag &= CBAUD | CBAUDEX | CSIZE | CSTOPB | PARENB | PARODD; | 235 | tty.c_cflag &= CBAUD | CBAUDEX | CSIZE | CSTOPB | PARENB | PARODD; |
@@ -709,10 +717,12 @@ static void restart_handler(int sig UNUSED_PARAM) | |||
709 | 717 | ||
710 | run_shutdown_and_kill_processes(); | 718 | run_shutdown_and_kill_processes(); |
711 | 719 | ||
720 | #ifdef RB_ENABLE_CAD | ||
712 | /* Allow Ctrl-Alt-Del to reboot the system. | 721 | /* Allow Ctrl-Alt-Del to reboot the system. |
713 | * This is how kernel sets it up for init, we follow suit. | 722 | * This is how kernel sets it up for init, we follow suit. |
714 | */ | 723 | */ |
715 | reboot(RB_ENABLE_CAD); /* misnomer */ | 724 | reboot(RB_ENABLE_CAD); /* misnomer */ |
725 | #endif | ||
716 | 726 | ||
717 | if (open_stdio_to_tty(a->terminal)) { | 727 | if (open_stdio_to_tty(a->terminal)) { |
718 | dbg_message(L_CONSOLE, "Trying to re-exec %s", a->command); | 728 | dbg_message(L_CONSOLE, "Trying to re-exec %s", a->command); |
@@ -855,9 +865,11 @@ int init_main(int argc UNUSED_PARAM, char **argv) | |||
855 | ) { | 865 | ) { |
856 | bb_show_usage(); | 866 | bb_show_usage(); |
857 | } | 867 | } |
868 | #ifdef RB_DISABLE_CAD | ||
858 | /* Turn off rebooting via CTL-ALT-DEL - we get a | 869 | /* Turn off rebooting via CTL-ALT-DEL - we get a |
859 | * SIGINT on CAD so we can shut things down gracefully... */ | 870 | * SIGINT on CAD so we can shut things down gracefully... */ |
860 | reboot(RB_DISABLE_CAD); /* misnomer */ | 871 | reboot(RB_DISABLE_CAD); /* misnomer */ |
872 | #endif | ||
861 | } | 873 | } |
862 | 874 | ||
863 | /* Figure out where the default console should be */ | 875 | /* Figure out where the default console should be */ |
@@ -880,6 +892,8 @@ int init_main(int argc UNUSED_PARAM, char **argv) | |||
880 | message(L_CONSOLE | L_LOG, "init started: %s", bb_banner); | 892 | message(L_CONSOLE | L_LOG, "init started: %s", bb_banner); |
881 | #endif | 893 | #endif |
882 | 894 | ||
895 | /* struct sysinfo is linux-specific */ | ||
896 | #ifdef __linux__ | ||
883 | /* Make sure there is enough memory to do something useful. */ | 897 | /* Make sure there is enough memory to do something useful. */ |
884 | if (ENABLE_SWAPONOFF) { | 898 | if (ENABLE_SWAPONOFF) { |
885 | struct sysinfo info; | 899 | struct sysinfo info; |
@@ -895,6 +909,7 @@ int init_main(int argc UNUSED_PARAM, char **argv) | |||
895 | run_actions(SYSINIT); /* wait and removing */ | 909 | run_actions(SYSINIT); /* wait and removing */ |
896 | } | 910 | } |
897 | } | 911 | } |
912 | #endif | ||
898 | 913 | ||
899 | /* Check if we are supposed to be in single user mode */ | 914 | /* Check if we are supposed to be in single user mode */ |
900 | if (argv[1] | 915 | if (argv[1] |
diff --git a/init/reboot.h b/init/reboot.h new file mode 100644 index 000000000..949763949 --- /dev/null +++ b/init/reboot.h | |||
@@ -0,0 +1,30 @@ | |||
1 | /* | ||
2 | * Definitions related to the reboot() system call, | ||
3 | * shared between init.c and halt.c. | ||
4 | */ | ||
5 | |||
6 | #include <sys/reboot.h> | ||
7 | |||
8 | #ifndef RB_HALT_SYSTEM | ||
9 | # if defined(__linux__) | ||
10 | # define RB_HALT_SYSTEM 0xcdef0123 | ||
11 | # define RB_ENABLE_CAD 0x89abcdef | ||
12 | # define RB_DISABLE_CAD 0 | ||
13 | # define RB_POWER_OFF 0x4321fedc | ||
14 | # define RB_AUTOBOOT 0x01234567 | ||
15 | # elif defined(RB_HALT) | ||
16 | # define RB_HALT_SYSTEM RB_HALT | ||
17 | # endif | ||
18 | #endif | ||
19 | |||
20 | /* Stop system and switch power off if possible. */ | ||
21 | #ifndef RB_POWER_OFF | ||
22 | # if defined(RB_POWERDOWN) | ||
23 | # define RB_POWER_OFF RB_POWERDOWN | ||
24 | # elif defined(__linux__) | ||
25 | # define RB_POWER_OFF 0x4321fedc | ||
26 | # else | ||
27 | # warning "poweroff unsupported, using halt as fallback" | ||
28 | # define RB_POWER_OFF RB_HALT_SYSTEM | ||
29 | # endif | ||
30 | #endif | ||