Erik Andersen | ccc7488 | 2000-01-27 02:40:21 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | c499601 | 1999-10-20 22:08:37 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Mini init implementation for busybox |
| 4 | * |
Eric Andersen | c499601 | 1999-10-20 22:08:37 +0000 | [diff] [blame] | 5 | * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>. |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 6 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> |
Eric Andersen | c499601 | 1999-10-20 22:08:37 +0000 | [diff] [blame] | 7 | * Adjusted by so many folks, it's impossible to keep track. |
| 8 | * |
Rob Landley | 2edf526 | 2006-01-22 02:41:51 +0000 | [diff] [blame] | 9 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Eric Andersen | c499601 | 1999-10-20 22:08:37 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 12 | #include "libbb.h" |
Bernhard Reutner-Fischer | f470196 | 2008-01-27 12:50:12 +0000 | [diff] [blame] | 13 | #include <syslog.h> |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 14 | #include <paths.h> |
Eric Andersen | 85e5e72 | 2003-07-22 08:56:55 +0000 | [diff] [blame] | 15 | #include <sys/reboot.h> |
Denis Vlasenko | 6c62246 | 2009-01-29 02:01:04 +0000 | [diff] [blame] | 16 | #include <sys/resource.h> |
Eric Andersen | 2c1de61 | 2003-04-24 11:41:28 +0000 | [diff] [blame] | 17 | |
Denis Vlasenko | 5cb54b5 | 2008-10-21 17:14:26 +0000 | [diff] [blame] | 18 | /* Was a CONFIG_xxx option. A lot of people were building |
| 19 | * not fully functional init by switching it on! */ |
| 20 | #define DEBUG_INIT 0 |
| 21 | |
Denis Vlasenko | 6c62246 | 2009-01-29 02:01:04 +0000 | [diff] [blame] | 22 | #define COMMAND_SIZE 256 |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 23 | #define CONSOLE_NAME_SIZE 32 |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 24 | |
Erik Andersen | 96e2abd | 2000-01-07 11:40:44 +0000 | [diff] [blame] | 25 | #ifndef INIT_SCRIPT |
Glenn L McGrath | baf55a8 | 2002-08-22 18:22:10 +0000 | [diff] [blame] | 26 | #define INIT_SCRIPT "/etc/init.d/rcS" /* Default sysinit script. */ |
Erik Andersen | 96e2abd | 2000-01-07 11:40:44 +0000 | [diff] [blame] | 27 | #endif |
Erik Andersen | 9c88cac | 1999-12-30 09:25:17 +0000 | [diff] [blame] | 28 | |
Erik Andersen | 7dc1607 | 2000-01-04 01:10:25 +0000 | [diff] [blame] | 29 | /* Allowed init action types */ |
Denis Vlasenko | ad4da98 | 2008-04-05 04:24:23 +0000 | [diff] [blame] | 30 | #define SYSINIT 0x01 |
| 31 | #define RESPAWN 0x02 |
| 32 | /* like respawn, but wait for <Enter> to be pressed on tty: */ |
| 33 | #define ASKFIRST 0x04 |
| 34 | #define WAIT 0x08 |
| 35 | #define ONCE 0x10 |
| 36 | #define CTRLALTDEL 0x20 |
| 37 | #define SHUTDOWN 0x40 |
| 38 | #define RESTART 0x80 |
Erik Andersen | 7dc1607 | 2000-01-04 01:10:25 +0000 | [diff] [blame] | 39 | |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 40 | /* Set up a linked list of init_actions, to be read from inittab */ |
| 41 | struct init_action { |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 42 | struct init_action *next; |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 43 | pid_t pid; |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 44 | uint8_t action_type; |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 45 | char terminal[CONSOLE_NAME_SIZE]; |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 46 | char command[COMMAND_SIZE]; |
Erik Andersen | 7dc1607 | 2000-01-04 01:10:25 +0000 | [diff] [blame] | 47 | }; |
Erik Andersen | 7dc1607 | 2000-01-04 01:10:25 +0000 | [diff] [blame] | 48 | |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 49 | static struct init_action *init_action_list = NULL; |
Glenn L McGrath | baf55a8 | 2002-08-22 18:22:10 +0000 | [diff] [blame] | 50 | |
Denis Vlasenko | 4c97863 | 2007-02-03 03:31:13 +0000 | [diff] [blame] | 51 | static const char *log_console = VC_5; |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 52 | |
| 53 | enum { |
Denis Vlasenko | ec27feb | 2007-02-17 15:52:02 +0000 | [diff] [blame] | 54 | L_LOG = 0x1, |
| 55 | L_CONSOLE = 0x2, |
Denis Vlasenko | b2b2c40 | 2009-01-28 23:56:31 +0000 | [diff] [blame] | 56 | MAYBE_CONSOLE = L_CONSOLE * !ENABLE_FEATURE_EXTRA_QUIET, |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 57 | #ifndef RB_HALT_SYSTEM |
Bernhard Reutner-Fischer | cf1f2ac | 2006-06-02 10:43:17 +0000 | [diff] [blame] | 58 | RB_HALT_SYSTEM = 0xcdef0123, /* FIXME: this overflows enum */ |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 59 | RB_ENABLE_CAD = 0x89abcdef, |
| 60 | RB_DISABLE_CAD = 0, |
| 61 | RB_POWER_OFF = 0x4321fedc, |
| 62 | RB_AUTOBOOT = 0x01234567, |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 63 | #endif |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 64 | }; |
Erik Andersen | 42094cd | 2000-03-20 21:34:52 +0000 | [diff] [blame] | 65 | |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 66 | static void halt_reboot_pwoff(int sig) NORETURN; |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 67 | |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 68 | static void loop_forever(void) NORETURN; |
Eric Andersen | 74400cc | 2001-10-18 04:11:39 +0000 | [diff] [blame] | 69 | static void loop_forever(void) |
Matt Kraai | 67a4640 | 2001-06-03 05:55:52 +0000 | [diff] [blame] | 70 | { |
| 71 | while (1) |
Glenn L McGrath | baf55a8 | 2002-08-22 18:22:10 +0000 | [diff] [blame] | 72 | sleep(1); |
Matt Kraai | 67a4640 | 2001-06-03 05:55:52 +0000 | [diff] [blame] | 73 | } |
Eric Andersen | 7ef1a5b | 2001-03-20 17:39:08 +0000 | [diff] [blame] | 74 | |
Erik Andersen | 42094cd | 2000-03-20 21:34:52 +0000 | [diff] [blame] | 75 | /* Print a message to the specified device. |
Denis Vlasenko | 671ca33 | 2008-02-19 14:13:20 +0000 | [diff] [blame] | 76 | * "where" may be bitwise-or'd from L_LOG | L_CONSOLE |
| 77 | * NB: careful, we can be called after vfork! |
| 78 | */ |
Denis Vlasenko | 5cb54b5 | 2008-10-21 17:14:26 +0000 | [diff] [blame] | 79 | #define messageD(...) do { if (DEBUG_INIT) message(__VA_ARGS__); } while (0) |
Denis Vlasenko | 671ca33 | 2008-02-19 14:13:20 +0000 | [diff] [blame] | 80 | static void message(int where, const char *fmt, ...) |
Glenn L McGrath | baf55a8 | 2002-08-22 18:22:10 +0000 | [diff] [blame] | 81 | __attribute__ ((format(printf, 2, 3))); |
Denis Vlasenko | 671ca33 | 2008-02-19 14:13:20 +0000 | [diff] [blame] | 82 | static void message(int where, const char *fmt, ...) |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 83 | { |
Eric Andersen | 2223701 | 2003-01-23 07:08:26 +0000 | [diff] [blame] | 84 | static int log_fd = -1; |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 85 | va_list arguments; |
Denis Vlasenko | b8d1a4c | 2008-09-20 16:28:59 +0000 | [diff] [blame] | 86 | unsigned l; |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 87 | char msg[128]; |
| 88 | |
Glenn L McGrath | b4a1baa | 2003-01-13 22:09:50 +0000 | [diff] [blame] | 89 | msg[0] = '\r'; |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 90 | va_start(arguments, fmt); |
Denis Vlasenko | 1bcdcd2 | 2008-12-09 21:23:31 +0000 | [diff] [blame] | 91 | l = 1 + vsnprintf(msg + 1, sizeof(msg) - 2, fmt, arguments); |
| 92 | if (l > sizeof(msg) - 1) |
| 93 | l = sizeof(msg) - 1; |
Denis Vlasenko | b8d1a4c | 2008-09-20 16:28:59 +0000 | [diff] [blame] | 94 | msg[l] = '\0'; |
Denis Vlasenko | ec27feb | 2007-02-17 15:52:02 +0000 | [diff] [blame] | 95 | va_end(arguments); |
Glenn L McGrath | b4a1baa | 2003-01-13 22:09:50 +0000 | [diff] [blame] | 96 | |
Mike Frysinger | bb50fdf | 2007-12-25 04:30:14 +0000 | [diff] [blame] | 97 | if (ENABLE_FEATURE_INIT_SYSLOG) { |
Denis Vlasenko | 671ca33 | 2008-02-19 14:13:20 +0000 | [diff] [blame] | 98 | if (where & L_LOG) { |
Denis Vlasenko | 1bcdcd2 | 2008-12-09 21:23:31 +0000 | [diff] [blame] | 99 | /* Log the message to syslogd */ |
| 100 | openlog("init", 0, LOG_DAEMON); |
| 101 | /* don't print "\r" */ |
| 102 | syslog(LOG_INFO, "%s", msg + 1); |
Mike Frysinger | bb50fdf | 2007-12-25 04:30:14 +0000 | [diff] [blame] | 103 | closelog(); |
| 104 | } |
| 105 | msg[l++] = '\n'; |
| 106 | msg[l] = '\0'; |
| 107 | } else { |
| 108 | msg[l++] = '\n'; |
| 109 | msg[l] = '\0'; |
| 110 | /* Take full control of the log tty, and never close it. |
| 111 | * It's mine, all mine! Muhahahaha! */ |
| 112 | if (log_fd < 0) { |
| 113 | if (!log_console) { |
Bernhard Reutner-Fischer | ad2fa65 | 2008-07-21 11:16:39 +0000 | [diff] [blame] | 114 | log_fd = STDERR_FILENO; |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 115 | } else { |
Mike Frysinger | bb50fdf | 2007-12-25 04:30:14 +0000 | [diff] [blame] | 116 | log_fd = device_open(log_console, O_WRONLY | O_NONBLOCK | O_NOCTTY); |
| 117 | if (log_fd < 0) { |
| 118 | bb_error_msg("can't log to %s", log_console); |
Denis Vlasenko | 671ca33 | 2008-02-19 14:13:20 +0000 | [diff] [blame] | 119 | where = L_CONSOLE; |
Mike Frysinger | bb50fdf | 2007-12-25 04:30:14 +0000 | [diff] [blame] | 120 | } else { |
| 121 | close_on_exec_on(log_fd); |
| 122 | } |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 123 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 124 | } |
Denis Vlasenko | 671ca33 | 2008-02-19 14:13:20 +0000 | [diff] [blame] | 125 | if (where & L_LOG) { |
Mike Frysinger | bb50fdf | 2007-12-25 04:30:14 +0000 | [diff] [blame] | 126 | full_write(log_fd, msg, l); |
Bernhard Reutner-Fischer | ad2fa65 | 2008-07-21 11:16:39 +0000 | [diff] [blame] | 127 | if (log_fd == STDERR_FILENO) |
Mike Frysinger | bb50fdf | 2007-12-25 04:30:14 +0000 | [diff] [blame] | 128 | return; /* don't print dup messages */ |
| 129 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 130 | } |
Eric Andersen | 4c78147 | 1999-11-26 08:12:56 +0000 | [diff] [blame] | 131 | |
Denis Vlasenko | 671ca33 | 2008-02-19 14:13:20 +0000 | [diff] [blame] | 132 | if (where & L_CONSOLE) { |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 133 | /* Send console messages to console so people will see them. */ |
Bernhard Reutner-Fischer | 5e25ddb | 2008-05-19 09:48:17 +0000 | [diff] [blame] | 134 | full_write(STDERR_FILENO, msg, l); |
Eric Andersen | 3ae0c78 | 1999-11-04 01:13:21 +0000 | [diff] [blame] | 135 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 138 | /* From <linux/serial.h> */ |
| 139 | struct serial_struct { |
| 140 | int type; |
| 141 | int line; |
| 142 | unsigned int port; |
| 143 | int irq; |
| 144 | int flags; |
| 145 | int xmit_fifo_size; |
| 146 | int custom_divisor; |
| 147 | int baud_base; |
| 148 | unsigned short close_delay; |
| 149 | char io_type; |
| 150 | char reserved_char[1]; |
| 151 | int hub6; |
| 152 | unsigned short closing_wait; /* time to wait before closing */ |
| 153 | unsigned short closing_wait2; /* no longer used... */ |
| 154 | unsigned char *iomem_base; |
| 155 | unsigned short iomem_reg_shift; |
| 156 | unsigned int port_high; |
| 157 | unsigned long iomap_base; /* cookie passed into ioremap */ |
| 158 | int reserved[1]; |
| 159 | /* Paranoia (imagine 64bit kernel overwriting 32bit userspace stack) */ |
| 160 | uint32_t bbox_reserved[16]; |
| 161 | }; |
Eric Andersen | 74400cc | 2001-10-18 04:11:39 +0000 | [diff] [blame] | 162 | static void console_init(void) |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 163 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 164 | struct serial_struct sr; |
| 165 | char *s; |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 166 | |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 167 | s = getenv("CONSOLE"); |
Bernhard Reutner-Fischer | ad2fa65 | 2008-07-21 11:16:39 +0000 | [diff] [blame] | 168 | if (!s) |
| 169 | s = getenv("console"); |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 170 | if (s) { |
| 171 | int fd = open(s, O_RDWR | O_NONBLOCK | O_NOCTTY); |
| 172 | if (fd >= 0) { |
Bernhard Reutner-Fischer | ad2fa65 | 2008-07-21 11:16:39 +0000 | [diff] [blame] | 173 | dup2(fd, STDIN_FILENO); |
| 174 | dup2(fd, STDOUT_FILENO); |
| 175 | xmove_fd(fd, STDERR_FILENO); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 176 | } |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 177 | messageD(L_LOG, "console='%s'", s); |
Denis Vlasenko | d8540f7 | 2007-06-14 07:53:06 +0000 | [diff] [blame] | 178 | } else { |
Denis Vlasenko | fb274df | 2008-03-17 13:26:51 +0000 | [diff] [blame] | 179 | /* Make sure fd 0,1,2 are not closed |
| 180 | * (so that they won't be used by future opens) */ |
Denis Vlasenko | d48e81f | 2008-07-06 07:00:11 +0000 | [diff] [blame] | 181 | bb_sanitize_stdio(); |
Denis Vlasenko | a34b8a4 | 2008-11-29 23:14:37 +0000 | [diff] [blame] | 182 | // Users report problems |
| 183 | // /* Make sure init can't be blocked by writing to stderr */ |
| 184 | // fcntl(STDERR_FILENO, F_SETFL, fcntl(STDERR_FILENO, F_GETFL) | O_NONBLOCK); |
Eric Andersen | 07e5297 | 1999-11-07 07:38:08 +0000 | [diff] [blame] | 185 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 186 | |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 187 | s = getenv("TERM"); |
Denis Vlasenko | e421b5e | 2008-03-17 22:01:42 +0000 | [diff] [blame] | 188 | if (ioctl(STDIN_FILENO, TIOCGSERIAL, &sr) == 0) { |
Denis Vlasenko | 2afabe8 | 2007-12-10 07:06:04 +0000 | [diff] [blame] | 189 | /* Force the TERM setting to vt102 for serial console |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 190 | * if TERM is set to linux (the default) */ |
| 191 | if (!s || strcmp(s, "linux") == 0) |
| 192 | putenv((char*)"TERM=vt102"); |
Mike Frysinger | bb50fdf | 2007-12-25 04:30:14 +0000 | [diff] [blame] | 193 | if (!ENABLE_FEATURE_INIT_SYSLOG) |
| 194 | log_console = NULL; |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 195 | } else if (!s) |
| 196 | putenv((char*)"TERM=linux"); |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 197 | } |
Glenn L McGrath | baf55a8 | 2002-08-22 18:22:10 +0000 | [diff] [blame] | 198 | |
Denis Vlasenko | 671ca33 | 2008-02-19 14:13:20 +0000 | [diff] [blame] | 199 | /* Set terminal settings to reasonable defaults. |
| 200 | * NB: careful, we can be called after vfork! */ |
Denis Vlasenko | 2afabe8 | 2007-12-10 07:06:04 +0000 | [diff] [blame] | 201 | static void set_sane_term(void) |
Eric Andersen | 7ef1a5b | 2001-03-20 17:39:08 +0000 | [diff] [blame] | 202 | { |
Denis Vlasenko | 2afabe8 | 2007-12-10 07:06:04 +0000 | [diff] [blame] | 203 | struct termios tty; |
Eric Andersen | 7ef1a5b | 2001-03-20 17:39:08 +0000 | [diff] [blame] | 204 | |
Denis Vlasenko | 2afabe8 | 2007-12-10 07:06:04 +0000 | [diff] [blame] | 205 | tcgetattr(STDIN_FILENO, &tty); |
| 206 | |
| 207 | /* set control chars */ |
| 208 | tty.c_cc[VINTR] = 3; /* C-c */ |
| 209 | tty.c_cc[VQUIT] = 28; /* C-\ */ |
| 210 | tty.c_cc[VERASE] = 127; /* C-? */ |
| 211 | tty.c_cc[VKILL] = 21; /* C-u */ |
| 212 | tty.c_cc[VEOF] = 4; /* C-d */ |
| 213 | tty.c_cc[VSTART] = 17; /* C-q */ |
| 214 | tty.c_cc[VSTOP] = 19; /* C-s */ |
| 215 | tty.c_cc[VSUSP] = 26; /* C-z */ |
| 216 | |
Bernhard Reutner-Fischer | ad2fa65 | 2008-07-21 11:16:39 +0000 | [diff] [blame] | 217 | /* use line discipline 0 */ |
Denis Vlasenko | 2afabe8 | 2007-12-10 07:06:04 +0000 | [diff] [blame] | 218 | tty.c_line = 0; |
| 219 | |
| 220 | /* Make it be sane */ |
| 221 | tty.c_cflag &= CBAUD | CBAUDEX | CSIZE | CSTOPB | PARENB | PARODD; |
| 222 | tty.c_cflag |= CREAD | HUPCL | CLOCAL; |
| 223 | |
| 224 | /* input modes */ |
| 225 | tty.c_iflag = ICRNL | IXON | IXOFF; |
| 226 | |
| 227 | /* output modes */ |
| 228 | tty.c_oflag = OPOST | ONLCR; |
| 229 | |
| 230 | /* local modes */ |
| 231 | tty.c_lflag = |
| 232 | ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE | IEXTEN; |
| 233 | |
Denis Vlasenko | 202ac50 | 2008-11-05 13:20:58 +0000 | [diff] [blame] | 234 | tcsetattr_stdin_TCSANOW(&tty); |
Eric Andersen | 7ef1a5b | 2001-03-20 17:39:08 +0000 | [diff] [blame] | 235 | } |
| 236 | |
Denis Vlasenko | 671ca33 | 2008-02-19 14:13:20 +0000 | [diff] [blame] | 237 | /* Open the new terminal device. |
| 238 | * NB: careful, we can be called after vfork! */ |
Denis Vlasenko | d55268d | 2007-12-26 18:32:58 +0000 | [diff] [blame] | 239 | static void open_stdio_to_tty(const char* tty_name, int exit_on_failure) |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 240 | { |
| 241 | /* empty tty_name means "use init's tty", else... */ |
| 242 | if (tty_name[0]) { |
Denis Vlasenko | d55268d | 2007-12-26 18:32:58 +0000 | [diff] [blame] | 243 | int fd; |
Bernhard Reutner-Fischer | ad2fa65 | 2008-07-21 11:16:39 +0000 | [diff] [blame] | 244 | close(STDIN_FILENO); |
Denis Vlasenko | d55268d | 2007-12-26 18:32:58 +0000 | [diff] [blame] | 245 | /* fd can be only < 0 or 0: */ |
| 246 | fd = device_open(tty_name, O_RDWR); |
| 247 | if (fd) { |
Bernhard Reutner-Fischer | a53de7f | 2008-07-21 13:46:54 +0000 | [diff] [blame] | 248 | message(L_LOG | L_CONSOLE, "can't open %s: %s", |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 249 | tty_name, strerror(errno)); |
Denis Vlasenko | d55268d | 2007-12-26 18:32:58 +0000 | [diff] [blame] | 250 | if (exit_on_failure) |
Bernhard Reutner-Fischer | 636a1f8 | 2008-05-19 09:29:47 +0000 | [diff] [blame] | 251 | _exit(EXIT_FAILURE); |
Denis Vlasenko | 5cb54b5 | 2008-10-21 17:14:26 +0000 | [diff] [blame] | 252 | if (DEBUG_INIT) |
Mike Frysinger | bb50fdf | 2007-12-25 04:30:14 +0000 | [diff] [blame] | 253 | _exit(2); |
Bernhard Reutner-Fischer | ad2fa65 | 2008-07-21 11:16:39 +0000 | [diff] [blame] | 254 | /* NB: we don't reach this if we were called after vfork. |
| 255 | * Thus halt_reboot_pwoff() itself need not be vfork-safe. */ |
Denis Vlasenko | d55268d | 2007-12-26 18:32:58 +0000 | [diff] [blame] | 256 | halt_reboot_pwoff(SIGUSR1); /* halt the system */ |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 257 | } |
Bernhard Reutner-Fischer | ad2fa65 | 2008-07-21 11:16:39 +0000 | [diff] [blame] | 258 | dup2(STDIN_FILENO, STDOUT_FILENO); |
| 259 | dup2(STDIN_FILENO, STDERR_FILENO); |
Bernhard Reutner-Fischer | 0da069d | 2006-05-29 12:54:16 +0000 | [diff] [blame] | 260 | } |
Denis Vlasenko | d238a47 | 2007-03-05 19:22:04 +0000 | [diff] [blame] | 261 | set_sane_term(); |
Bernhard Reutner-Fischer | 0da069d | 2006-05-29 12:54:16 +0000 | [diff] [blame] | 262 | } |
| 263 | |
Denis Vlasenko | 671ca33 | 2008-02-19 14:13:20 +0000 | [diff] [blame] | 264 | /* Wrapper around exec: |
| 265 | * Takes string (max COMMAND_SIZE chars). |
| 266 | * If chars like '>' detected, execs '[-]/bin/sh -c "exec ......."'. |
| 267 | * Otherwise splits words on whitespace, deals with leading dash, |
| 268 | * and uses plain exec(). |
| 269 | * NB: careful, we can be called after vfork! |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 270 | */ |
| 271 | static void init_exec(const char *command) |
| 272 | { |
| 273 | char *cmd[COMMAND_SIZE / 2]; |
| 274 | char buf[COMMAND_SIZE + 6]; /* COMMAND_SIZE+strlen("exec ")+1 */ |
Denis Vlasenko | 671ca33 | 2008-02-19 14:13:20 +0000 | [diff] [blame] | 275 | int dash = (command[0] == '-' /* maybe? && command[1] == '/' */); |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 276 | |
| 277 | /* See if any special /bin/sh requiring characters are present */ |
| 278 | if (strpbrk(command, "~`!$^&*()=|\\{}[];\"'<>?") != NULL) { |
| 279 | strcpy(buf, "exec "); |
| 280 | strcpy(buf + 5, command + dash); /* excluding "-" */ |
Denis Vlasenko | 671ca33 | 2008-02-19 14:13:20 +0000 | [diff] [blame] | 281 | /* NB: LIBBB_DEFAULT_LOGIN_SHELL define has leading dash */ |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 282 | cmd[0] = (char*)(LIBBB_DEFAULT_LOGIN_SHELL + !dash); |
| 283 | cmd[1] = (char*)"-c"; |
| 284 | cmd[2] = buf; |
| 285 | cmd[3] = NULL; |
| 286 | } else { |
| 287 | /* Convert command (char*) into cmd (char**, one word per string) */ |
| 288 | char *word, *next; |
| 289 | int i = 0; |
| 290 | next = strcpy(buf, command); /* including "-" */ |
| 291 | while ((word = strsep(&next, " \t")) != NULL) { |
| 292 | if (*word != '\0') { /* not two spaces/tabs together? */ |
| 293 | cmd[i] = word; |
| 294 | i++; |
| 295 | } |
| 296 | } |
| 297 | cmd[i] = NULL; |
| 298 | } |
| 299 | /* If we saw leading "-", it is interactive shell. |
| 300 | * Try harder to give it a controlling tty. |
| 301 | * And skip "-" in actual exec call. */ |
| 302 | if (dash) { |
| 303 | /* _Attempt_ to make stdin a controlling tty. */ |
| 304 | if (ENABLE_FEATURE_INIT_SCTTY) |
| 305 | ioctl(STDIN_FILENO, TIOCSCTTY, 0 /*only try, don't steal*/); |
| 306 | } |
| 307 | BB_EXECVP(cmd[0] + dash, cmd); |
Bernhard Reutner-Fischer | a53de7f | 2008-07-21 13:46:54 +0000 | [diff] [blame] | 308 | message(L_LOG | L_CONSOLE, "cannot run '%s': %s", cmd[0], strerror(errno)); |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 309 | /* returns if execvp fails */ |
| 310 | } |
| 311 | |
Denis Vlasenko | 2afabe8 | 2007-12-10 07:06:04 +0000 | [diff] [blame] | 312 | /* Used only by run_actions */ |
Glenn L McGrath | b4a1baa | 2003-01-13 22:09:50 +0000 | [diff] [blame] | 313 | static pid_t run(const struct init_action *a) |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 314 | { |
Mike Frysinger | 10427ab | 2005-07-06 05:00:48 +0000 | [diff] [blame] | 315 | pid_t pid; |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 316 | sigset_t nmask, omask; |
Erik Andersen | ac6e71f | 2000-01-08 22:04:33 +0000 | [diff] [blame] | 317 | |
Denis Vlasenko | 2afabe8 | 2007-12-10 07:06:04 +0000 | [diff] [blame] | 318 | /* Block sigchild while forking (why?) */ |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 319 | sigemptyset(&nmask); |
| 320 | sigaddset(&nmask, SIGCHLD); |
| 321 | sigprocmask(SIG_BLOCK, &nmask, &omask); |
Denis Vlasenko | ad4da98 | 2008-04-05 04:24:23 +0000 | [diff] [blame] | 322 | if (BB_MMU && (a->action_type & ASKFIRST)) |
| 323 | pid = fork(); |
| 324 | else |
| 325 | pid = vfork(); |
Denis Vlasenko | 966bb43 | 2007-02-27 19:20:33 +0000 | [diff] [blame] | 326 | sigprocmask(SIG_SETMASK, &omask, NULL); |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 327 | |
Denis Vlasenko | 2afabe8 | 2007-12-10 07:06:04 +0000 | [diff] [blame] | 328 | if (pid < 0) |
Bernhard Reutner-Fischer | a53de7f | 2008-07-21 13:46:54 +0000 | [diff] [blame] | 329 | message(L_LOG | L_CONSOLE, "can't fork"); |
Denis Vlasenko | 966bb43 | 2007-02-27 19:20:33 +0000 | [diff] [blame] | 330 | if (pid) |
| 331 | return pid; |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 332 | |
Denis Vlasenko | 2afabe8 | 2007-12-10 07:06:04 +0000 | [diff] [blame] | 333 | /* Child */ |
| 334 | |
Denis Vlasenko | 966bb43 | 2007-02-27 19:20:33 +0000 | [diff] [blame] | 335 | /* Reset signal handlers that were set by the parent process */ |
Denis Vlasenko | 25591c3 | 2008-02-16 22:58:56 +0000 | [diff] [blame] | 336 | bb_signals(0 |
| 337 | + (1 << SIGUSR1) |
| 338 | + (1 << SIGUSR2) |
| 339 | + (1 << SIGINT) |
| 340 | + (1 << SIGTERM) |
| 341 | + (1 << SIGHUP) |
| 342 | + (1 << SIGQUIT) |
| 343 | + (1 << SIGCONT) |
| 344 | + (1 << SIGSTOP) |
| 345 | + (1 << SIGTSTP) |
| 346 | , SIG_DFL); |
Eric Andersen | 2f6c04f | 1999-11-01 23:59:44 +0000 | [diff] [blame] | 347 | |
Denis Vlasenko | 966bb43 | 2007-02-27 19:20:33 +0000 | [diff] [blame] | 348 | /* Create a new session and make ourself the process |
| 349 | * group leader */ |
| 350 | setsid(); |
Eric Andersen | 599e3ce | 2002-07-03 11:08:10 +0000 | [diff] [blame] | 351 | |
Denis Vlasenko | 966bb43 | 2007-02-27 19:20:33 +0000 | [diff] [blame] | 352 | /* Open the new terminal device */ |
Denis Vlasenko | 671ca33 | 2008-02-19 14:13:20 +0000 | [diff] [blame] | 353 | open_stdio_to_tty(a->terminal, 1 /* - exit if open fails */); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 354 | |
Denis Vlasenko | 671ca33 | 2008-02-19 14:13:20 +0000 | [diff] [blame] | 355 | // NB: do not enable unless you change vfork to fork above |
Denis Vlasenko | 2afabe8 | 2007-12-10 07:06:04 +0000 | [diff] [blame] | 356 | #ifdef BUT_RUN_ACTIONS_ALREADY_DOES_WAITING |
Denis Vlasenko | 966bb43 | 2007-02-27 19:20:33 +0000 | [diff] [blame] | 357 | /* If the init Action requires us to wait, then force the |
| 358 | * supplied terminal to be the controlling tty. */ |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 359 | if (a->action_type & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) { |
Denis Vlasenko | 966bb43 | 2007-02-27 19:20:33 +0000 | [diff] [blame] | 360 | /* Now fork off another process to just hang around */ |
Denis Vlasenko | 6bef3d1 | 2007-11-06 03:05:54 +0000 | [diff] [blame] | 361 | pid = fork(); |
Denis Vlasenko | f6ccc62 | 2007-11-10 01:57:35 +0000 | [diff] [blame] | 362 | if (pid < 0) { |
Bernhard Reutner-Fischer | a53de7f | 2008-07-21 13:46:54 +0000 | [diff] [blame] | 363 | message(L_LOG | L_CONSOLE, "can't fork"); |
Bernhard Reutner-Fischer | 636a1f8 | 2008-05-19 09:29:47 +0000 | [diff] [blame] | 364 | _exit(EXIT_FAILURE); |
Denis Vlasenko | 966bb43 | 2007-02-27 19:20:33 +0000 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | if (pid > 0) { |
Denis Vlasenko | 2afabe8 | 2007-12-10 07:06:04 +0000 | [diff] [blame] | 368 | /* Parent - wait till the child is done */ |
Denis Vlasenko | 25591c3 | 2008-02-16 22:58:56 +0000 | [diff] [blame] | 369 | bb_signals(0 |
| 370 | + (1 << SIGINT) |
| 371 | + (1 << SIGTSTP) |
| 372 | + (1 << SIGQUIT) |
| 373 | , SIG_IGN); |
Denis Vlasenko | 966bb43 | 2007-02-27 19:20:33 +0000 | [diff] [blame] | 374 | signal(SIGCHLD, SIG_DFL); |
| 375 | |
Denis Vlasenko | 2afabe8 | 2007-12-10 07:06:04 +0000 | [diff] [blame] | 376 | waitfor(pid); |
Denis Vlasenko | 966bb43 | 2007-02-27 19:20:33 +0000 | [diff] [blame] | 377 | /* See if stealing the controlling tty back is necessary */ |
| 378 | if (tcgetpgrp(0) != getpid()) |
Bernhard Reutner-Fischer | 636a1f8 | 2008-05-19 09:29:47 +0000 | [diff] [blame] | 379 | _exit(EXIT_SUCCESS); |
Denis Vlasenko | 966bb43 | 2007-02-27 19:20:33 +0000 | [diff] [blame] | 380 | |
| 381 | /* Use a temporary process to steal the controlling tty. */ |
Denis Vlasenko | 6bef3d1 | 2007-11-06 03:05:54 +0000 | [diff] [blame] | 382 | pid = fork(); |
| 383 | if (pid < 0) { |
Bernhard Reutner-Fischer | a53de7f | 2008-07-21 13:46:54 +0000 | [diff] [blame] | 384 | message(L_LOG | L_CONSOLE, "can't fork"); |
Bernhard Reutner-Fischer | 636a1f8 | 2008-05-19 09:29:47 +0000 | [diff] [blame] | 385 | _exit(EXIT_FAILURE); |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 386 | } |
Denis Vlasenko | 966bb43 | 2007-02-27 19:20:33 +0000 | [diff] [blame] | 387 | if (pid == 0) { |
| 388 | setsid(); |
| 389 | ioctl(0, TIOCSCTTY, 1); |
Bernhard Reutner-Fischer | 636a1f8 | 2008-05-19 09:29:47 +0000 | [diff] [blame] | 390 | _exit(EXIT_SUCCESS); |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 391 | } |
Denis Vlasenko | 2afabe8 | 2007-12-10 07:06:04 +0000 | [diff] [blame] | 392 | waitfor(pid); |
Bernhard Reutner-Fischer | 636a1f8 | 2008-05-19 09:29:47 +0000 | [diff] [blame] | 393 | _exit(EXIT_SUCCESS); |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 394 | } |
Denis Vlasenko | 2afabe8 | 2007-12-10 07:06:04 +0000 | [diff] [blame] | 395 | /* Child - fall though to actually execute things */ |
Denis Vlasenko | 966bb43 | 2007-02-27 19:20:33 +0000 | [diff] [blame] | 396 | } |
Denis Vlasenko | 5adfa44 | 2007-12-25 16:08:53 +0000 | [diff] [blame] | 397 | #endif |
Denis Vlasenko | 671ca33 | 2008-02-19 14:13:20 +0000 | [diff] [blame] | 398 | |
Denis Vlasenko | ad4da98 | 2008-04-05 04:24:23 +0000 | [diff] [blame] | 399 | /* NB: on NOMMU we can't wait for input in child, so |
| 400 | * "askfirst" will work the same as "respawn". */ |
Denis Vlasenko | 671ca33 | 2008-02-19 14:13:20 +0000 | [diff] [blame] | 401 | if (BB_MMU && (a->action_type & ASKFIRST)) { |
Denis Vlasenko | 6ca409e | 2007-08-12 20:58:27 +0000 | [diff] [blame] | 402 | static const char press_enter[] ALIGN1 = |
Denis Vlasenko | 966bb43 | 2007-02-27 19:20:33 +0000 | [diff] [blame] | 403 | #ifdef CUSTOMIZED_BANNER |
| 404 | #include CUSTOMIZED_BANNER |
Eric Andersen | 1f50e84 | 2004-08-16 09:29:42 +0000 | [diff] [blame] | 405 | #endif |
Denis Vlasenko | 966bb43 | 2007-02-27 19:20:33 +0000 | [diff] [blame] | 406 | "\nPlease press Enter to activate this console. "; |
| 407 | char c; |
| 408 | /* |
| 409 | * Save memory by not exec-ing anything large (like a shell) |
| 410 | * before the user wants it. This is critical if swap is not |
| 411 | * enabled and the system has low memory. Generally this will |
| 412 | * be run on the second virtual console, and the first will |
| 413 | * be allowed to start a shell or whatever an init script |
| 414 | * specifies. |
| 415 | */ |
| 416 | messageD(L_LOG, "waiting for enter to start '%s'" |
| 417 | "(pid %d, tty '%s')\n", |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 418 | a->command, getpid(), a->terminal); |
Bernhard Reutner-Fischer | 5e25ddb | 2008-05-19 09:48:17 +0000 | [diff] [blame] | 419 | full_write(STDOUT_FILENO, press_enter, sizeof(press_enter) - 1); |
| 420 | while (safe_read(STDIN_FILENO, &c, 1) == 1 && c != '\n') |
Denis Vlasenko | 2afabe8 | 2007-12-10 07:06:04 +0000 | [diff] [blame] | 421 | continue; |
Denis Vlasenko | 966bb43 | 2007-02-27 19:20:33 +0000 | [diff] [blame] | 422 | } |
Denis Vlasenko | 2afabe8 | 2007-12-10 07:06:04 +0000 | [diff] [blame] | 423 | |
Denis Vlasenko | 6c62246 | 2009-01-29 02:01:04 +0000 | [diff] [blame] | 424 | /* |
| 425 | * When a file named /.init_enable_core exists, setrlimit is called |
| 426 | * before processes are spawned to set core file size as unlimited. |
| 427 | * This is for debugging only. Don't use this is production, unless |
| 428 | * you want core dumps lying about.... |
| 429 | */ |
Mike Frysinger | bb50fdf | 2007-12-25 04:30:14 +0000 | [diff] [blame] | 430 | if (ENABLE_FEATURE_INIT_COREDUMPS) { |
Denis Vlasenko | 6c62246 | 2009-01-29 02:01:04 +0000 | [diff] [blame] | 431 | if (access("/.init_enable_core", F_OK) == 0) { |
Denis Vlasenko | 966bb43 | 2007-02-27 19:20:33 +0000 | [diff] [blame] | 432 | struct rlimit limit; |
Denis Vlasenko | 966bb43 | 2007-02-27 19:20:33 +0000 | [diff] [blame] | 433 | limit.rlim_cur = RLIM_INFINITY; |
| 434 | limit.rlim_max = RLIM_INFINITY; |
| 435 | setrlimit(RLIMIT_CORE, &limit); |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 436 | } |
Erik Andersen | 05df239 | 2000-01-13 04:43:48 +0000 | [diff] [blame] | 437 | } |
Mike Frysinger | bb50fdf | 2007-12-25 04:30:14 +0000 | [diff] [blame] | 438 | |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 439 | /* Log the process name and args */ |
| 440 | message(L_LOG, "starting pid %d, tty '%s': '%s'", |
| 441 | getpid(), a->terminal, a->command); |
| 442 | |
Denis Vlasenko | 966bb43 | 2007-02-27 19:20:33 +0000 | [diff] [blame] | 443 | /* Now run it. The new program will take over this PID, |
| 444 | * so nothing further in init.c should be run. */ |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 445 | init_exec(a->command); |
Denis Vlasenko | 966bb43 | 2007-02-27 19:20:33 +0000 | [diff] [blame] | 446 | /* We're still here? Some error happened. */ |
Denis Vlasenko | 966bb43 | 2007-02-27 19:20:33 +0000 | [diff] [blame] | 447 | _exit(-1); |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 448 | } |
| 449 | |
Bernhard Reutner-Fischer | 5259361 | 2008-07-21 11:53:04 +0000 | [diff] [blame] | 450 | static void delete_init_action(struct init_action *action) |
| 451 | { |
| 452 | struct init_action *a, *b = NULL; |
| 453 | |
| 454 | for (a = init_action_list; a; b = a, a = a->next) { |
| 455 | if (a == action) { |
| 456 | if (b == NULL) { |
| 457 | init_action_list = a->next; |
| 458 | } else { |
| 459 | b->next = a->next; |
| 460 | } |
| 461 | free(a); |
| 462 | break; |
| 463 | } |
| 464 | } |
| 465 | } |
| 466 | |
Denis Vlasenko | cab28aa | 2009-01-31 01:02:07 +0000 | [diff] [blame^] | 467 | static void waitfor(pid_t pid) |
| 468 | { |
| 469 | /* waitfor(run(x)): protect against failed fork inside run() */ |
| 470 | if (pid <= 0) |
| 471 | return; |
| 472 | |
| 473 | /* Wait for any child (prevent zombies from exiting orphaned processes) |
| 474 | * but exit the loop only when specified one has exited. */ |
| 475 | while (wait(NULL) != pid) |
| 476 | continue; |
| 477 | } |
| 478 | |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 479 | /* Run all commands of a particular type */ |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 480 | static void run_actions(int action_type) |
Eric Andersen | 219d6f5 | 1999-11-02 19:43:01 +0000 | [diff] [blame] | 481 | { |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 482 | struct init_action *a, *tmp; |
Eric Andersen | 219d6f5 | 1999-11-02 19:43:01 +0000 | [diff] [blame] | 483 | |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 484 | for (a = init_action_list; a; a = tmp) { |
| 485 | tmp = a->next; |
Denis Vlasenko | ad4da98 | 2008-04-05 04:24:23 +0000 | [diff] [blame] | 486 | if (a->action_type & action_type) { |
Denis Vlasenko | d7e2e12 | 2007-12-10 08:40:29 +0000 | [diff] [blame] | 487 | // Pointless: run() will error out if open of device fails. |
| 488 | ///* a->terminal of "" means "init's console" */ |
| 489 | //if (a->terminal[0] && access(a->terminal, R_OK | W_OK)) { |
| 490 | // //message(L_LOG | L_CONSOLE, "Device %s cannot be opened in RW mode", a->terminal /*, strerror(errno)*/); |
| 491 | // delete_init_action(a); |
| 492 | //} else |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 493 | if (a->action_type & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) { |
Denis Vlasenko | 2afabe8 | 2007-12-10 07:06:04 +0000 | [diff] [blame] | 494 | waitfor(run(a)); |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 495 | delete_init_action(a); |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 496 | } else if (a->action_type & ONCE) { |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 497 | run(a); |
| 498 | delete_init_action(a); |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 499 | } else if (a->action_type & (RESPAWN | ASKFIRST)) { |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 500 | /* Only run stuff with pid==0. If they have |
| 501 | * a pid, that means it is still running */ |
| 502 | if (a->pid == 0) { |
| 503 | a->pid = run(a); |
| 504 | } |
| 505 | } |
Erik Andersen | e132f4b | 2000-02-09 04:16:43 +0000 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | } |
| 509 | |
Denis Vlasenko | cab28aa | 2009-01-31 01:02:07 +0000 | [diff] [blame^] | 510 | static void low_level_reboot(unsigned long magic) |
Eric Andersen | 2c1de61 | 2003-04-24 11:41:28 +0000 | [diff] [blame] | 511 | { |
| 512 | pid_t pid; |
Bernhard Reutner-Fischer | 636a1f8 | 2008-05-19 09:29:47 +0000 | [diff] [blame] | 513 | /* We have to fork here, since the kernel calls do_exit(EXIT_SUCCESS) in |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 514 | * linux/kernel/sys.c, which can cause the machine to panic when |
Eric Andersen | 2c1de61 | 2003-04-24 11:41:28 +0000 | [diff] [blame] | 515 | * the init process is killed.... */ |
Denis Vlasenko | 9b1381f | 2007-01-03 02:56:00 +0000 | [diff] [blame] | 516 | pid = vfork(); |
| 517 | if (pid == 0) { /* child */ |
Eric Andersen | 2c1de61 | 2003-04-24 11:41:28 +0000 | [diff] [blame] | 518 | reboot(magic); |
Bernhard Reutner-Fischer | 636a1f8 | 2008-05-19 09:29:47 +0000 | [diff] [blame] | 519 | _exit(EXIT_SUCCESS); |
Eric Andersen | 2c1de61 | 2003-04-24 11:41:28 +0000 | [diff] [blame] | 520 | } |
Denis Vlasenko | fb0eba7 | 2008-01-02 19:55:04 +0000 | [diff] [blame] | 521 | waitfor(pid); |
Eric Andersen | 2c1de61 | 2003-04-24 11:41:28 +0000 | [diff] [blame] | 522 | } |
| 523 | |
Denis Vlasenko | d55268d | 2007-12-26 18:32:58 +0000 | [diff] [blame] | 524 | static void kill_all_processes(void) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 525 | { |
Eric Andersen | a9cc896 | 2002-09-16 06:49:06 +0000 | [diff] [blame] | 526 | /* run everything to be run at "shutdown". This is done _prior_ |
| 527 | * to killing everything, in case people wish to use scripts to |
| 528 | * shut things down gracefully... */ |
| 529 | run_actions(SHUTDOWN); |
| 530 | |
Eric Andersen | 72f9a42 | 2001-10-28 05:12:20 +0000 | [diff] [blame] | 531 | /* first disable all our signals */ |
Denis Vlasenko | 3f165fa | 2008-03-17 08:29:08 +0000 | [diff] [blame] | 532 | sigprocmask_allsigs(SIG_BLOCK); |
Erik Andersen | 7dc1607 | 2000-01-04 01:10:25 +0000 | [diff] [blame] | 533 | |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 534 | message(L_CONSOLE | L_LOG, "The system is going down NOW!"); |
| 535 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 536 | /* Allow Ctrl-Alt-Del to reboot system. */ |
Denis Vlasenko | cab28aa | 2009-01-31 01:02:07 +0000 | [diff] [blame^] | 537 | low_level_reboot(RB_ENABLE_CAD); |
Erik Andersen | e132f4b | 2000-02-09 04:16:43 +0000 | [diff] [blame] | 538 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 539 | /* Send signals to every process _except_ pid 1 */ |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 540 | message(L_CONSOLE | L_LOG, "Sending SIG%s to all processes", "TERM"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 541 | kill(-1, SIGTERM); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 542 | sync(); |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 543 | sleep(1); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 544 | |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 545 | message(L_CONSOLE | L_LOG, "Sending SIG%s to all processes", "KILL"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 546 | kill(-1, SIGKILL); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 547 | sync(); |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 548 | sleep(1); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 549 | } |
| 550 | |
Denis Vlasenko | d55268d | 2007-12-26 18:32:58 +0000 | [diff] [blame] | 551 | static void halt_reboot_pwoff(int sig) |
Denis Vlasenko | 2afabe8 | 2007-12-10 07:06:04 +0000 | [diff] [blame] | 552 | { |
Bernhard Reutner-Fischer | 54d50a0 | 2008-07-17 14:00:42 +0000 | [diff] [blame] | 553 | const char *m = "halt"; |
Denis Vlasenko | 2afabe8 | 2007-12-10 07:06:04 +0000 | [diff] [blame] | 554 | int rb; |
| 555 | |
Denis Vlasenko | d55268d | 2007-12-26 18:32:58 +0000 | [diff] [blame] | 556 | kill_all_processes(); |
Denis Vlasenko | 2afabe8 | 2007-12-10 07:06:04 +0000 | [diff] [blame] | 557 | |
Denis Vlasenko | 2afabe8 | 2007-12-10 07:06:04 +0000 | [diff] [blame] | 558 | rb = RB_HALT_SYSTEM; |
| 559 | if (sig == SIGTERM) { |
| 560 | m = "reboot"; |
| 561 | rb = RB_AUTOBOOT; |
| 562 | } else if (sig == SIGUSR2) { |
| 563 | m = "poweroff"; |
| 564 | rb = RB_POWER_OFF; |
| 565 | } |
| 566 | message(L_CONSOLE | L_LOG, "Requesting system %s", m); |
| 567 | /* allow time for last message to reach serial console */ |
| 568 | sleep(2); |
Denis Vlasenko | cab28aa | 2009-01-31 01:02:07 +0000 | [diff] [blame^] | 569 | low_level_reboot(rb); |
Denis Vlasenko | 2afabe8 | 2007-12-10 07:06:04 +0000 | [diff] [blame] | 570 | loop_forever(); |
| 571 | } |
| 572 | |
Denis Vlasenko | a58a637 | 2008-02-19 12:10:18 +0000 | [diff] [blame] | 573 | /* Handler for QUIT - exec "restart" action, |
Denis Vlasenko | d55268d | 2007-12-26 18:32:58 +0000 | [diff] [blame] | 574 | * else (no such action defined) do nothing */ |
Denis Vlasenko | cab28aa | 2009-01-31 01:02:07 +0000 | [diff] [blame^] | 575 | static void restart_handler(int sig UNUSED_PARAM) |
Eric Andersen | 730f826 | 2001-12-17 23:13:08 +0000 | [diff] [blame] | 576 | { |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 577 | struct init_action *a; |
Glenn L McGrath | baf55a8 | 2002-08-22 18:22:10 +0000 | [diff] [blame] | 578 | |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 579 | for (a = init_action_list; a; a = a->next) { |
| 580 | if (a->action_type & RESTART) { |
Denis Vlasenko | d55268d | 2007-12-26 18:32:58 +0000 | [diff] [blame] | 581 | kill_all_processes(); |
Eric Andersen | 5222d31 | 2002-07-03 05:15:23 +0000 | [diff] [blame] | 582 | |
Denis Vlasenko | d55268d | 2007-12-26 18:32:58 +0000 | [diff] [blame] | 583 | /* unblock all signals (blocked in kill_all_processes()) */ |
Denis Vlasenko | 3f165fa | 2008-03-17 08:29:08 +0000 | [diff] [blame] | 584 | sigprocmask_allsigs(SIG_UNBLOCK); |
Eric Andersen | 5222d31 | 2002-07-03 05:15:23 +0000 | [diff] [blame] | 585 | |
Eric Andersen | 3c8064f | 2003-07-05 08:29:01 +0000 | [diff] [blame] | 586 | /* Open the new terminal device */ |
Denis Vlasenko | d55268d | 2007-12-26 18:32:58 +0000 | [diff] [blame] | 587 | open_stdio_to_tty(a->terminal, 0 /* - halt if open fails */); |
Eric Andersen | 3c8064f | 2003-07-05 08:29:01 +0000 | [diff] [blame] | 588 | |
Denis Vlasenko | ec27feb | 2007-02-17 15:52:02 +0000 | [diff] [blame] | 589 | messageD(L_CONSOLE | L_LOG, "Trying to re-exec %s", a->command); |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 590 | init_exec(a->command); |
Eric Andersen | 730f826 | 2001-12-17 23:13:08 +0000 | [diff] [blame] | 591 | sleep(2); |
Denis Vlasenko | cab28aa | 2009-01-31 01:02:07 +0000 | [diff] [blame^] | 592 | low_level_reboot(RB_HALT_SYSTEM); |
Eric Andersen | 730f826 | 2001-12-17 23:13:08 +0000 | [diff] [blame] | 593 | loop_forever(); |
| 594 | } |
| 595 | } |
| 596 | } |
| 597 | |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 598 | static void ctrlaltdel_signal(int sig UNUSED_PARAM) |
Eric Andersen | c97ec34 | 2001-04-03 18:01:51 +0000 | [diff] [blame] | 599 | { |
| 600 | run_actions(CTRLALTDEL); |
| 601 | } |
| 602 | |
Denis Vlasenko | 3fa36e2 | 2008-11-09 00:15:11 +0000 | [diff] [blame] | 603 | /* The SIGCONT handler is set to record_signo(). |
| 604 | * It just sets bb_got_signal = SIGCONT. */ |
| 605 | |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 606 | /* The SIGSTOP & SIGTSTP handler */ |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 607 | static void stop_handler(int sig UNUSED_PARAM) |
Eric Andersen | ed8a9be | 2001-11-30 19:10:58 +0000 | [diff] [blame] | 608 | { |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 609 | int saved_errno = errno; |
Eric Andersen | ed8a9be | 2001-11-30 19:10:58 +0000 | [diff] [blame] | 610 | |
Denis Vlasenko | 3fa36e2 | 2008-11-09 00:15:11 +0000 | [diff] [blame] | 611 | bb_got_signal = 0; |
| 612 | while (bb_got_signal == 0) |
Glenn L McGrath | baf55a8 | 2002-08-22 18:22:10 +0000 | [diff] [blame] | 613 | pause(); |
Denis Vlasenko | 2afabe8 | 2007-12-10 07:06:04 +0000 | [diff] [blame] | 614 | |
Eric Andersen | ed8a9be | 2001-11-30 19:10:58 +0000 | [diff] [blame] | 615 | errno = saved_errno; |
| 616 | } |
| 617 | |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 618 | static void new_init_action(uint8_t action_type, const char *command, const char *cons) |
Erik Andersen | 7dc1607 | 2000-01-04 01:10:25 +0000 | [diff] [blame] | 619 | { |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 620 | struct init_action *a, *last; |
Erik Andersen | 9e73725 | 2000-01-06 01:16:13 +0000 | [diff] [blame] | 621 | |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 622 | // Why? |
| 623 | // if (strcmp(cons, bb_dev_null) == 0 && (action & ASKFIRST)) |
| 624 | // return; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 625 | |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 626 | /* Append to the end of the list */ |
Eric Andersen | 2271809 | 2004-10-08 08:17:39 +0000 | [diff] [blame] | 627 | for (a = last = init_action_list; a; a = a->next) { |
Eric Andersen | 82baf63 | 2004-10-08 08:21:54 +0000 | [diff] [blame] | 628 | /* don't enter action if it's already in the list, |
| 629 | * but do overwrite existing actions */ |
Denis Vlasenko | ec27feb | 2007-02-17 15:52:02 +0000 | [diff] [blame] | 630 | if ((strcmp(a->command, command) == 0) |
Denis Vlasenko | b74a2db | 2008-07-21 21:34:51 +0000 | [diff] [blame] | 631 | && (strcmp(a->terminal, cons) == 0) |
| 632 | ) { |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 633 | a->action_type = action_type; |
Eric Andersen | 6fd0e31 | 2003-07-22 09:48:56 +0000 | [diff] [blame] | 634 | return; |
| 635 | } |
Eric Andersen | 2271809 | 2004-10-08 08:17:39 +0000 | [diff] [blame] | 636 | last = a; |
Eric Andersen | 6fd0e31 | 2003-07-22 09:48:56 +0000 | [diff] [blame] | 637 | } |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 638 | |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 639 | a = xzalloc(sizeof(*a)); |
Eric Andersen | 2271809 | 2004-10-08 08:17:39 +0000 | [diff] [blame] | 640 | if (last) { |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 641 | last->next = a; |
Eric Andersen | 1644db9 | 2001-09-05 20:18:15 +0000 | [diff] [blame] | 642 | } else { |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 643 | init_action_list = a; |
Eric Andersen | 1644db9 | 2001-09-05 20:18:15 +0000 | [diff] [blame] | 644 | } |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 645 | a->action_type = action_type; |
| 646 | safe_strncpy(a->command, command, sizeof(a->command)); |
| 647 | safe_strncpy(a->terminal, cons, sizeof(a->terminal)); |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 648 | messageD(L_LOG | L_CONSOLE, "command='%s' action=%d tty='%s'\n", |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 649 | a->command, a->action_type, a->terminal); |
Erik Andersen | 7dc1607 | 2000-01-04 01:10:25 +0000 | [diff] [blame] | 650 | } |
| 651 | |
Eric Andersen | bdfd0d7 | 2001-10-24 05:00:29 +0000 | [diff] [blame] | 652 | /* NOTE that if CONFIG_FEATURE_USE_INITTAB is NOT defined, |
Erik Andersen | 9e73725 | 2000-01-06 01:16:13 +0000 | [diff] [blame] | 653 | * then parse_inittab() simply adds in some default |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 654 | * actions(i.e., runs INIT_SCRIPT and then starts a pair |
| 655 | * of "askfirst" shells). If CONFIG_FEATURE_USE_INITTAB |
| 656 | * _is_ defined, but /etc/inittab is missing, this |
Erik Andersen | 812d466 | 2000-01-07 18:30:40 +0000 | [diff] [blame] | 657 | * results in the same set of default behaviors. |
Glenn L McGrath | baf55a8 | 2002-08-22 18:22:10 +0000 | [diff] [blame] | 658 | */ |
Eric Andersen | 3e6ff90 | 2001-03-09 21:24:12 +0000 | [diff] [blame] | 659 | static void parse_inittab(void) |
Erik Andersen | 7dc1607 | 2000-01-04 01:10:25 +0000 | [diff] [blame] | 660 | { |
Denis Vlasenko | 6c62246 | 2009-01-29 02:01:04 +0000 | [diff] [blame] | 661 | #if ENABLE_FEATURE_USE_INITTAB |
Bernhard Reutner-Fischer | 54d50a0 | 2008-07-17 14:00:42 +0000 | [diff] [blame] | 662 | char *token[4]; |
Denis Vlasenko | 6c62246 | 2009-01-29 02:01:04 +0000 | [diff] [blame] | 663 | parser_t *parser = config_open2("/etc/inittab", fopen_for_read); |
Bernhard Reutner-Fischer | 54d50a0 | 2008-07-17 14:00:42 +0000 | [diff] [blame] | 664 | |
Denis Vlasenko | 6c62246 | 2009-01-29 02:01:04 +0000 | [diff] [blame] | 665 | if (parser == NULL) |
| 666 | #endif |
| 667 | { |
| 668 | /* No inittab file -- set up some default behavior */ |
Bernhard Reutner-Fischer | 54d50a0 | 2008-07-17 14:00:42 +0000 | [diff] [blame] | 669 | /* Reboot on Ctrl-Alt-Del */ |
| 670 | new_init_action(CTRLALTDEL, "reboot", ""); |
| 671 | /* Umount all filesystems on halt/reboot */ |
| 672 | new_init_action(SHUTDOWN, "umount -a -r", ""); |
| 673 | /* Swapoff on halt/reboot */ |
| 674 | if (ENABLE_SWAPONOFF) |
| 675 | new_init_action(SHUTDOWN, "swapoff -a", ""); |
| 676 | /* Prepare to restart init when a QUIT is received */ |
| 677 | new_init_action(RESTART, "init", ""); |
| 678 | /* Askfirst shell on tty1-4 */ |
| 679 | new_init_action(ASKFIRST, bb_default_login_shell, ""); |
Denis Vlasenko | a474b68 | 2008-07-17 17:58:44 +0000 | [diff] [blame] | 680 | //TODO: VC_1 instead of ""? "" is console -> ctty problems -> angry users |
Bernhard Reutner-Fischer | 54d50a0 | 2008-07-17 14:00:42 +0000 | [diff] [blame] | 681 | new_init_action(ASKFIRST, bb_default_login_shell, VC_2); |
| 682 | new_init_action(ASKFIRST, bb_default_login_shell, VC_3); |
| 683 | new_init_action(ASKFIRST, bb_default_login_shell, VC_4); |
| 684 | /* sysinit */ |
| 685 | new_init_action(SYSINIT, INIT_SCRIPT, ""); |
Bernhard Reutner-Fischer | 54d50a0 | 2008-07-17 14:00:42 +0000 | [diff] [blame] | 686 | return; |
| 687 | } |
Denis Vlasenko | 6c62246 | 2009-01-29 02:01:04 +0000 | [diff] [blame] | 688 | |
| 689 | #if ENABLE_FEATURE_USE_INITTAB |
Bernhard Reutner-Fischer | 54d50a0 | 2008-07-17 14:00:42 +0000 | [diff] [blame] | 690 | /* optional_tty:ignored_runlevel:action:command |
Denis Vlasenko | a474b68 | 2008-07-17 17:58:44 +0000 | [diff] [blame] | 691 | * Delims are not to be collapsed and need exactly 4 tokens |
Bernhard Reutner-Fischer | 54d50a0 | 2008-07-17 14:00:42 +0000 | [diff] [blame] | 692 | */ |
Denis Vlasenko | 084266e | 2008-07-26 23:08:31 +0000 | [diff] [blame] | 693 | while (config_read(parser, token, 4, 0, "#:", |
| 694 | PARSE_NORMAL & ~(PARSE_TRIM | PARSE_COLLAPSE))) { |
Denis Vlasenko | 6c62246 | 2009-01-29 02:01:04 +0000 | [diff] [blame] | 695 | /* order must correspond to SYSINIT..RESTART constants */ |
| 696 | static const char actions[] ALIGN1 = |
| 697 | "sysinit\0""respawn\0""askfirst\0""wait\0""once\0" |
| 698 | "ctrlaltdel\0""shutdown\0""restart\0"; |
Denis Vlasenko | a474b68 | 2008-07-17 17:58:44 +0000 | [diff] [blame] | 699 | int action; |
Bernhard Reutner-Fischer | 54d50a0 | 2008-07-17 14:00:42 +0000 | [diff] [blame] | 700 | char *tty = token[0]; |
Bernhard Reutner-Fischer | 54d50a0 | 2008-07-17 14:00:42 +0000 | [diff] [blame] | 701 | |
Denis Vlasenko | a474b68 | 2008-07-17 17:58:44 +0000 | [diff] [blame] | 702 | if (!token[3]) /* less than 4 tokens */ |
Bernhard Reutner-Fischer | 54d50a0 | 2008-07-17 14:00:42 +0000 | [diff] [blame] | 703 | goto bad_entry; |
Denis Vlasenko | a474b68 | 2008-07-17 17:58:44 +0000 | [diff] [blame] | 704 | action = index_in_strings(actions, token[2]); |
| 705 | if (action < 0 || !token[3][0]) /* token[3]: command */ |
| 706 | goto bad_entry; |
| 707 | /* turn .*TTY -> /dev/TTY */ |
| 708 | if (tty[0]) { |
| 709 | if (strncmp(tty, "/dev/", 5) == 0) |
Bernhard Reutner-Fischer | 54d50a0 | 2008-07-17 14:00:42 +0000 | [diff] [blame] | 710 | tty += 5; |
| 711 | tty = concat_path_file("/dev/", tty); |
Denis Vlasenko | a474b68 | 2008-07-17 17:58:44 +0000 | [diff] [blame] | 712 | } |
| 713 | new_init_action(1 << action, token[3], tty); |
| 714 | if (tty[0]) |
Bernhard Reutner-Fischer | 54d50a0 | 2008-07-17 14:00:42 +0000 | [diff] [blame] | 715 | free(tty); |
| 716 | continue; |
| 717 | bad_entry: |
Bernhard Reutner-Fischer | ad2fa65 | 2008-07-21 11:16:39 +0000 | [diff] [blame] | 718 | message(L_LOG | L_CONSOLE, "Bad inittab entry at line %d", |
| 719 | parser->lineno); |
Bernhard Reutner-Fischer | 54d50a0 | 2008-07-17 14:00:42 +0000 | [diff] [blame] | 720 | } |
| 721 | config_close(parser); |
Denis Vlasenko | 6c62246 | 2009-01-29 02:01:04 +0000 | [diff] [blame] | 722 | #endif |
Erik Andersen | 7dc1607 | 2000-01-04 01:10:25 +0000 | [diff] [blame] | 723 | } |
| 724 | |
Denis Vlasenko | ad4da98 | 2008-04-05 04:24:23 +0000 | [diff] [blame] | 725 | #if ENABLE_FEATURE_USE_INITTAB |
Denis Vlasenko | cab28aa | 2009-01-31 01:02:07 +0000 | [diff] [blame^] | 726 | static void reload_inittab(int sig UNUSED_PARAM) |
Eric Andersen | 6fd0e31 | 2003-07-22 09:48:56 +0000 | [diff] [blame] | 727 | { |
Eric Andersen | 82baf63 | 2004-10-08 08:21:54 +0000 | [diff] [blame] | 728 | struct init_action *a, *tmp; |
| 729 | |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 730 | message(L_LOG, "reloading /etc/inittab"); |
Eric Andersen | 82baf63 | 2004-10-08 08:21:54 +0000 | [diff] [blame] | 731 | |
| 732 | /* disable old entrys */ |
Denis Vlasenko | ec5631b | 2007-12-25 01:08:58 +0000 | [diff] [blame] | 733 | for (a = init_action_list; a; a = a->next) { |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 734 | a->action_type = ONCE; |
Eric Andersen | 82baf63 | 2004-10-08 08:21:54 +0000 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | parse_inittab(); |
| 738 | |
Mike Frysinger | bb50fdf | 2007-12-25 04:30:14 +0000 | [diff] [blame] | 739 | if (ENABLE_FEATURE_KILL_REMOVED) { |
Denis Vlasenko | d55268d | 2007-12-26 18:32:58 +0000 | [diff] [blame] | 740 | /* Be nice and send SIGTERM first */ |
Mike Frysinger | bb50fdf | 2007-12-25 04:30:14 +0000 | [diff] [blame] | 741 | for (a = init_action_list; a; a = a->next) { |
| 742 | pid_t pid = a->pid; |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 743 | if ((a->action_type & ONCE) && pid != 0) { |
Mike Frysinger | bb50fdf | 2007-12-25 04:30:14 +0000 | [diff] [blame] | 744 | kill(pid, SIGTERM); |
Denis Vlasenko | ec5631b | 2007-12-25 01:08:58 +0000 | [diff] [blame] | 745 | } |
Denis Vlasenko | ec5631b | 2007-12-25 01:08:58 +0000 | [diff] [blame] | 746 | } |
Denis Vlasenko | d55268d | 2007-12-26 18:32:58 +0000 | [diff] [blame] | 747 | #if CONFIG_FEATURE_KILL_DELAY |
Denis Vlasenko | 671ca33 | 2008-02-19 14:13:20 +0000 | [diff] [blame] | 748 | /* NB: parent will wait in NOMMU case */ |
| 749 | if ((BB_MMU ? fork() : vfork()) == 0) { /* child */ |
Denis Vlasenko | d55268d | 2007-12-26 18:32:58 +0000 | [diff] [blame] | 750 | sleep(CONFIG_FEATURE_KILL_DELAY); |
| 751 | for (a = init_action_list; a; a = a->next) { |
| 752 | pid_t pid = a->pid; |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 753 | if ((a->action_type & ONCE) && pid != 0) { |
Denis Vlasenko | d55268d | 2007-12-26 18:32:58 +0000 | [diff] [blame] | 754 | kill(pid, SIGKILL); |
| 755 | } |
| 756 | } |
Bernhard Reutner-Fischer | 636a1f8 | 2008-05-19 09:29:47 +0000 | [diff] [blame] | 757 | _exit(EXIT_SUCCESS); |
Denis Vlasenko | d55268d | 2007-12-26 18:32:58 +0000 | [diff] [blame] | 758 | } |
| 759 | #endif |
Denis Vlasenko | ec5631b | 2007-12-25 01:08:58 +0000 | [diff] [blame] | 760 | } |
Denis Vlasenko | ec5631b | 2007-12-25 01:08:58 +0000 | [diff] [blame] | 761 | |
Eric Andersen | 82baf63 | 2004-10-08 08:21:54 +0000 | [diff] [blame] | 762 | /* remove unused entrys */ |
| 763 | for (a = init_action_list; a; a = tmp) { |
| 764 | tmp = a->next; |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 765 | if ((a->action_type & (ONCE | SYSINIT | WAIT)) && a->pid == 0) { |
Eric Andersen | 82baf63 | 2004-10-08 08:21:54 +0000 | [diff] [blame] | 766 | delete_init_action(a); |
| 767 | } |
| 768 | } |
Denis Vlasenko | ad4da98 | 2008-04-05 04:24:23 +0000 | [diff] [blame] | 769 | run_actions(RESPAWN | ASKFIRST); |
Eric Andersen | 6fd0e31 | 2003-07-22 09:48:56 +0000 | [diff] [blame] | 770 | } |
Denis Vlasenko | b2b2c40 | 2009-01-28 23:56:31 +0000 | [diff] [blame] | 771 | #else |
Denis Vlasenko | cab28aa | 2009-01-31 01:02:07 +0000 | [diff] [blame^] | 772 | void reload_inittab(int sig); |
Denis Vlasenko | ad4da98 | 2008-04-05 04:24:23 +0000 | [diff] [blame] | 773 | #endif |
Eric Andersen | 82baf63 | 2004-10-08 08:21:54 +0000 | [diff] [blame] | 774 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 775 | int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 776 | int init_main(int argc UNUSED_PARAM, char **argv) |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 777 | { |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 778 | struct init_action *a; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 779 | pid_t wpid; |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 780 | |
Denis Vlasenko | 9b1381f | 2007-01-03 02:56:00 +0000 | [diff] [blame] | 781 | die_sleep = 30 * 24*60*60; /* if xmalloc will ever die... */ |
| 782 | |
Denis Vlasenko | 1d42665 | 2008-03-17 09:09:09 +0000 | [diff] [blame] | 783 | if (argv[1] && !strcmp(argv[1], "-q")) { |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 784 | return kill(1, SIGHUP); |
Eric Andersen | 730f826 | 2001-12-17 23:13:08 +0000 | [diff] [blame] | 785 | } |
Mike Frysinger | bb50fdf | 2007-12-25 04:30:14 +0000 | [diff] [blame] | 786 | |
Denis Vlasenko | 5cb54b5 | 2008-10-21 17:14:26 +0000 | [diff] [blame] | 787 | if (!DEBUG_INIT) { |
Mike Frysinger | bb50fdf | 2007-12-25 04:30:14 +0000 | [diff] [blame] | 788 | /* Expect to be invoked as init with PID=1 or be invoked as linuxrc */ |
| 789 | if (getpid() != 1 |
| 790 | && (!ENABLE_FEATURE_INITRD || !strstr(applet_name, "linuxrc")) |
| 791 | ) { |
| 792 | bb_show_usage(); |
| 793 | } |
| 794 | /* Set up sig handlers -- be sure to |
| 795 | * clear all of these in run() */ |
Denis Vlasenko | 6c62246 | 2009-01-29 02:01:04 +0000 | [diff] [blame] | 796 | // TODO: handlers should just set a flag variable. |
| 797 | // Move signal handling from handlers to main loop - |
| 798 | // we have bad races otherwise. |
| 799 | // E.g. parse_inittab() vs. delete_init_action()... |
Denis Vlasenko | cab28aa | 2009-01-31 01:02:07 +0000 | [diff] [blame^] | 800 | signal(SIGQUIT, restart_handler); |
Denis Vlasenko | 25591c3 | 2008-02-16 22:58:56 +0000 | [diff] [blame] | 801 | bb_signals(0 |
| 802 | + (1 << SIGUSR1) /* halt */ |
| 803 | + (1 << SIGUSR2) /* poweroff */ |
| 804 | + (1 << SIGTERM) /* reboot */ |
| 805 | , halt_reboot_pwoff); |
Mike Frysinger | bb50fdf | 2007-12-25 04:30:14 +0000 | [diff] [blame] | 806 | signal(SIGINT, ctrlaltdel_signal); |
Denis Vlasenko | 3fa36e2 | 2008-11-09 00:15:11 +0000 | [diff] [blame] | 807 | signal(SIGCONT, record_signo); |
Denis Vlasenko | 25591c3 | 2008-02-16 22:58:56 +0000 | [diff] [blame] | 808 | bb_signals(0 |
| 809 | + (1 << SIGSTOP) |
| 810 | + (1 << SIGTSTP) |
| 811 | , stop_handler); |
Mike Frysinger | bb50fdf | 2007-12-25 04:30:14 +0000 | [diff] [blame] | 812 | |
| 813 | /* Turn off rebooting via CTL-ALT-DEL -- we get a |
| 814 | * SIGINT on CAD so we can shut things down gracefully... */ |
Denis Vlasenko | cab28aa | 2009-01-31 01:02:07 +0000 | [diff] [blame^] | 815 | low_level_reboot(RB_DISABLE_CAD); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 816 | } |
Denis Vlasenko | d8540f7 | 2007-06-14 07:53:06 +0000 | [diff] [blame] | 817 | |
Eric Andersen | 599e3ce | 2002-07-03 11:08:10 +0000 | [diff] [blame] | 818 | /* Figure out where the default console should be */ |
| 819 | console_init(); |
Denis Vlasenko | d238a47 | 2007-03-05 19:22:04 +0000 | [diff] [blame] | 820 | set_sane_term(); |
Bernhard Reutner-Fischer | 54d50a0 | 2008-07-17 14:00:42 +0000 | [diff] [blame] | 821 | xchdir("/"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 822 | setsid(); |
Denis Vlasenko | b8d1a4c | 2008-09-20 16:28:59 +0000 | [diff] [blame] | 823 | |
| 824 | /* Make sure environs is set to something sane */ |
| 825 | putenv((char *) "HOME=/"); |
| 826 | putenv((char *) bb_PATH_root_path); |
| 827 | putenv((char *) "SHELL=/bin/sh"); |
| 828 | putenv((char *) "USER=root"); /* needed? why? */ |
Rob Landley | cba1b96 | 2006-07-09 17:28:17 +0000 | [diff] [blame] | 829 | |
Bernhard Reutner-Fischer | 54d50a0 | 2008-07-17 14:00:42 +0000 | [diff] [blame] | 830 | if (argv[1]) |
Denis Vlasenko | b8d1a4c | 2008-09-20 16:28:59 +0000 | [diff] [blame] | 831 | xsetenv("RUNLEVEL", argv[1]); |
Rob Landley | cba1b96 | 2006-07-09 17:28:17 +0000 | [diff] [blame] | 832 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 833 | /* Hello world */ |
Denis Vlasenko | ca525b4 | 2007-06-13 12:27:17 +0000 | [diff] [blame] | 834 | message(MAYBE_CONSOLE | L_LOG, "init started: %s", bb_banner); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 835 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 836 | /* Make sure there is enough memory to do something useful. */ |
Rob Landley | c3386a4 | 2005-08-30 18:50:37 +0000 | [diff] [blame] | 837 | if (ENABLE_SWAPONOFF) { |
| 838 | struct sysinfo info; |
| 839 | |
Denis Vlasenko | 6c62246 | 2009-01-29 02:01:04 +0000 | [diff] [blame] | 840 | if (sysinfo(&info) == 0 |
| 841 | && (info.mem_unit ? : 1) * (long long)info.totalram < 1024*1024 |
| 842 | ) { |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 843 | message(L_CONSOLE, "Low memory, forcing swapon"); |
Rob Landley | c3386a4 | 2005-08-30 18:50:37 +0000 | [diff] [blame] | 844 | /* swapon -a requires /proc typically */ |
Denis Vlasenko | 2f0c0d0 | 2007-01-21 00:41:04 +0000 | [diff] [blame] | 845 | new_init_action(SYSINIT, "mount -t proc proc /proc", ""); |
Rob Landley | c3386a4 | 2005-08-30 18:50:37 +0000 | [diff] [blame] | 846 | /* Try to turn on swap */ |
Denis Vlasenko | 2f0c0d0 | 2007-01-21 00:41:04 +0000 | [diff] [blame] | 847 | new_init_action(SYSINIT, "swapon -a", ""); |
Rob Landley | c3386a4 | 2005-08-30 18:50:37 +0000 | [diff] [blame] | 848 | run_actions(SYSINIT); /* wait and removing */ |
| 849 | } |
| 850 | } |
Erik Andersen | 9e73725 | 2000-01-06 01:16:13 +0000 | [diff] [blame] | 851 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 852 | /* Check if we are supposed to be in single user mode */ |
Denis Vlasenko | 1d42665 | 2008-03-17 09:09:09 +0000 | [diff] [blame] | 853 | if (argv[1] |
Denis Vlasenko | bf66fbc | 2006-12-21 13:23:14 +0000 | [diff] [blame] | 854 | && (!strcmp(argv[1], "single") || !strcmp(argv[1], "-s") || LONE_CHAR(argv[1], '1')) |
| 855 | ) { |
Bernhard Reutner-Fischer | 54d50a0 | 2008-07-17 14:00:42 +0000 | [diff] [blame] | 856 | /* ??? shouldn't we set RUNLEVEL="b" here? */ |
Glenn L McGrath | b4a1baa | 2003-01-13 22:09:50 +0000 | [diff] [blame] | 857 | /* Start a shell on console */ |
Glenn L McGrath | dc4e75e | 2003-09-02 02:36:18 +0000 | [diff] [blame] | 858 | new_init_action(RESPAWN, bb_default_login_shell, ""); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 859 | } else { |
| 860 | /* Not in single user mode -- see what inittab says */ |
Eric Andersen | 8a8fbb8 | 1999-10-26 00:18:56 +0000 | [diff] [blame] | 861 | |
Eric Andersen | bdfd0d7 | 2001-10-24 05:00:29 +0000 | [diff] [blame] | 862 | /* NOTE that if CONFIG_FEATURE_USE_INITTAB is NOT defined, |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 863 | * then parse_inittab() simply adds in some default |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 864 | * actions(i.e., runs INIT_SCRIPT and then starts a pair |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 865 | * of "askfirst" shells */ |
| 866 | parse_inittab(); |
Eric Andersen | d00c262 | 1999-12-07 08:37:31 +0000 | [diff] [blame] | 867 | } |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 868 | |
Denis Vlasenko | 9b1381f | 2007-01-03 02:56:00 +0000 | [diff] [blame] | 869 | #if ENABLE_SELINUX |
Rob Landley | b3ede5a | 2006-03-27 23:09:12 +0000 | [diff] [blame] | 870 | if (getenv("SELINUX_INIT") == NULL) { |
| 871 | int enforce = 0; |
| 872 | |
Denis Vlasenko | d8540f7 | 2007-06-14 07:53:06 +0000 | [diff] [blame] | 873 | putenv((char*)"SELINUX_INIT=YES"); |
Rob Landley | b3ede5a | 2006-03-27 23:09:12 +0000 | [diff] [blame] | 874 | if (selinux_init_load_policy(&enforce) == 0) { |
Denis Vlasenko | 4921b54 | 2007-02-03 02:17:41 +0000 | [diff] [blame] | 875 | BB_EXECVP(argv[0], argv); |
Rob Landley | b3ede5a | 2006-03-27 23:09:12 +0000 | [diff] [blame] | 876 | } else if (enforce > 0) { |
| 877 | /* SELinux in enforcing mode but load_policy failed */ |
Bernhard Reutner-Fischer | a53de7f | 2008-07-21 13:46:54 +0000 | [diff] [blame] | 878 | message(L_CONSOLE, "cannot load SELinux Policy. " |
Denis Vlasenko | b716754 | 2007-02-27 19:20:00 +0000 | [diff] [blame] | 879 | "Machine is in enforcing mode. Halting now."); |
Bernhard Reutner-Fischer | 636a1f8 | 2008-05-19 09:29:47 +0000 | [diff] [blame] | 880 | exit(EXIT_FAILURE); |
Rob Landley | b3ede5a | 2006-03-27 23:09:12 +0000 | [diff] [blame] | 881 | } |
| 882 | } |
Denis Vlasenko | 6c62246 | 2009-01-29 02:01:04 +0000 | [diff] [blame] | 883 | #endif |
Rob Landley | b3ede5a | 2006-03-27 23:09:12 +0000 | [diff] [blame] | 884 | |
Denis Vlasenko | 2afabe8 | 2007-12-10 07:06:04 +0000 | [diff] [blame] | 885 | /* Make the command line just say "init" - thats all, nothing else */ |
| 886 | strncpy(argv[0], "init", strlen(argv[0])); |
| 887 | /* Wipe argv[1]-argv[N] so they don't clutter the ps listing */ |
| 888 | while (*++argv) |
| 889 | memset(*argv, 0, strlen(*argv)); |
Eric Andersen | 219d6f5 | 1999-11-02 19:43:01 +0000 | [diff] [blame] | 890 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 891 | /* Now run everything that needs to be run */ |
| 892 | |
| 893 | /* First run the sysinit command */ |
Eric Andersen | 1644db9 | 2001-09-05 20:18:15 +0000 | [diff] [blame] | 894 | run_actions(SYSINIT); |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 895 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 896 | /* Next run anything that wants to block */ |
Eric Andersen | 1644db9 | 2001-09-05 20:18:15 +0000 | [diff] [blame] | 897 | run_actions(WAIT); |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 898 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 899 | /* Next run anything to be run only once */ |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 900 | run_actions(ONCE); |
| 901 | |
Eric Andersen | 6fd0e31 | 2003-07-22 09:48:56 +0000 | [diff] [blame] | 902 | /* Redefine SIGHUP to reread /etc/inittab */ |
Denis Vlasenko | cab28aa | 2009-01-31 01:02:07 +0000 | [diff] [blame^] | 903 | signal(SIGHUP, ENABLE_FEATURE_USE_INITTAB ? reload_inittab : SIG_IGN); |
Eric Andersen | 82baf63 | 2004-10-08 08:21:54 +0000 | [diff] [blame] | 904 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 905 | /* Now run the looping stuff for the rest of forever */ |
| 906 | while (1) { |
Denis Vlasenko | ad4da98 | 2008-04-05 04:24:23 +0000 | [diff] [blame] | 907 | /* run the respawn/askfirst stuff */ |
| 908 | run_actions(RESPAWN | ASKFIRST); |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 909 | |
| 910 | /* Don't consume all CPU time -- sleep a bit */ |
| 911 | sleep(1); |
| 912 | |
Denis Vlasenko | fb0eba7 | 2008-01-02 19:55:04 +0000 | [diff] [blame] | 913 | /* Wait for any child process to exit */ |
Bernhard Reutner-Fischer | c58dbf2 | 2006-05-30 12:16:54 +0000 | [diff] [blame] | 914 | wpid = wait(NULL); |
Eric Andersen | 87812dc | 2004-04-12 19:21:54 +0000 | [diff] [blame] | 915 | while (wpid > 0) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 916 | /* Find out who died and clean up their corpse */ |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 917 | for (a = init_action_list; a; a = a->next) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 918 | if (a->pid == wpid) { |
Eric Andersen | 0298be8 | 2002-03-05 15:12:19 +0000 | [diff] [blame] | 919 | /* Set the pid to 0 so that the process gets |
| 920 | * restarted by run_actions() */ |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 921 | a->pid = 0; |
Denis Vlasenko | 7a2ca5e | 2007-02-21 00:15:20 +0000 | [diff] [blame] | 922 | message(L_LOG, "process '%s' (pid %d) exited. " |
Denis Vlasenko | a37e713 | 2008-02-19 02:57:07 +0000 | [diff] [blame] | 923 | "Scheduling for restart.", |
Glenn L McGrath | b4a1baa | 2003-01-13 22:09:50 +0000 | [diff] [blame] | 924 | a->command, wpid); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 925 | } |
| 926 | } |
Eric Andersen | cf1fee0 | 2002-12-17 09:48:16 +0000 | [diff] [blame] | 927 | /* see if anyone else is waiting to be reaped */ |
Denis Vlasenko | fb0eba7 | 2008-01-02 19:55:04 +0000 | [diff] [blame] | 928 | wpid = wait_any_nohang(NULL); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 929 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 930 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 931 | } |