diff options
| author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2008-07-21 11:16:39 +0000 |
|---|---|---|
| committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2008-07-21 11:16:39 +0000 |
| commit | ad2fa65fc0faf4ebaad1697bec56d6aaebb7117a (patch) | |
| tree | 6f0bbeb34abfa67f231c78688ae4bd97cdb21305 | |
| parent | 1101d1c98068d7a49942d6e9e11ca2e789a9cdba (diff) | |
| download | busybox-w32-ad2fa65fc0faf4ebaad1697bec56d6aaebb7117a.tar.gz busybox-w32-ad2fa65fc0faf4ebaad1697bec56d6aaebb7117a.tar.bz2 busybox-w32-ad2fa65fc0faf4ebaad1697bec56d6aaebb7117a.zip | |
- no obj-code changes. Fix indentation, use existing defines.
| -rw-r--r-- | init/init.c | 139 |
1 files changed, 19 insertions, 120 deletions
diff --git a/init/init.c b/init/init.c index 0e4a8f1e5..607280752 100644 --- a/init/init.c +++ b/init/init.c | |||
| @@ -43,16 +43,6 @@ | |||
| 43 | #define SHUTDOWN 0x40 | 43 | #define SHUTDOWN 0x40 |
| 44 | #define RESTART 0x80 | 44 | #define RESTART 0x80 |
| 45 | 45 | ||
| 46 | /* | ||
| 47 | #define STR_SYSINIT "\x01" | ||
| 48 | #define STR_RESPAWN "\x02" | ||
| 49 | #define STR_ASKFIRST "\x04" | ||
| 50 | #define STR_WAIT "\x08" | ||
| 51 | #define STR_ONCE "\x10" | ||
| 52 | #define STR_CTRLALTDEL "\x20" | ||
| 53 | #define STR_SHUTDOWN "\x40" | ||
| 54 | #define STR_RESTART "\x80" | ||
| 55 | */ | ||
| 56 | /* Set up a linked list of init_actions, to be read from inittab */ | 46 | /* Set up a linked list of init_actions, to be read from inittab */ |
| 57 | struct init_action { | 47 | struct init_action { |
| 58 | struct init_action *next; | 48 | struct init_action *next; |
| @@ -142,7 +132,7 @@ static void message(int where, const char *fmt, ...) | |||
| 142 | if (ENABLE_FEATURE_INIT_SYSLOG) { | 132 | if (ENABLE_FEATURE_INIT_SYSLOG) { |
| 143 | /* Log the message to syslogd */ | 133 | /* Log the message to syslogd */ |
| 144 | if (where & L_LOG) { | 134 | if (where & L_LOG) { |
| 145 | /* don't out "\r" */ | 135 | /* don't print out "\r" */ |
| 146 | openlog(applet_name, 0, LOG_DAEMON); | 136 | openlog(applet_name, 0, LOG_DAEMON); |
| 147 | syslog(LOG_INFO, "init: %s", msg + 1); | 137 | syslog(LOG_INFO, "init: %s", msg + 1); |
| 148 | closelog(); | 138 | closelog(); |
| @@ -156,7 +146,7 @@ static void message(int where, const char *fmt, ...) | |||
| 156 | * It's mine, all mine! Muhahahaha! */ | 146 | * It's mine, all mine! Muhahahaha! */ |
| 157 | if (log_fd < 0) { | 147 | if (log_fd < 0) { |
| 158 | if (!log_console) { | 148 | if (!log_console) { |
| 159 | log_fd = 2; | 149 | log_fd = STDERR_FILENO; |
| 160 | } else { | 150 | } else { |
| 161 | log_fd = device_open(log_console, O_WRONLY | O_NONBLOCK | O_NOCTTY); | 151 | log_fd = device_open(log_console, O_WRONLY | O_NONBLOCK | O_NOCTTY); |
| 162 | if (log_fd < 0) { | 152 | if (log_fd < 0) { |
| @@ -169,7 +159,7 @@ static void message(int where, const char *fmt, ...) | |||
| 169 | } | 159 | } |
| 170 | if (where & L_LOG) { | 160 | if (where & L_LOG) { |
| 171 | full_write(log_fd, msg, l); | 161 | full_write(log_fd, msg, l); |
| 172 | if (log_fd == 2) | 162 | if (log_fd == STDERR_FILENO) |
| 173 | return; /* don't print dup messages */ | 163 | return; /* don't print dup messages */ |
| 174 | } | 164 | } |
| 175 | } | 165 | } |
| @@ -210,13 +200,14 @@ static void console_init(void) | |||
| 210 | char *s; | 200 | char *s; |
| 211 | 201 | ||
| 212 | s = getenv("CONSOLE"); | 202 | s = getenv("CONSOLE"); |
| 213 | if (!s) s = getenv("console"); | 203 | if (!s) |
| 204 | s = getenv("console"); | ||
| 214 | if (s) { | 205 | if (s) { |
| 215 | int fd = open(s, O_RDWR | O_NONBLOCK | O_NOCTTY); | 206 | int fd = open(s, O_RDWR | O_NONBLOCK | O_NOCTTY); |
| 216 | if (fd >= 0) { | 207 | if (fd >= 0) { |
| 217 | dup2(fd, 0); | 208 | dup2(fd, STDIN_FILENO); |
| 218 | dup2(fd, 1); | 209 | dup2(fd, STDOUT_FILENO); |
| 219 | xmove_fd(fd, 2); | 210 | xmove_fd(fd, STDERR_FILENO); |
| 220 | } | 211 | } |
| 221 | messageD(L_LOG, "console='%s'", s); | 212 | messageD(L_LOG, "console='%s'", s); |
| 222 | } else { | 213 | } else { |
| @@ -255,7 +246,7 @@ static void set_sane_term(void) | |||
| 255 | tty.c_cc[VSTOP] = 19; /* C-s */ | 246 | tty.c_cc[VSTOP] = 19; /* C-s */ |
| 256 | tty.c_cc[VSUSP] = 26; /* C-z */ | 247 | tty.c_cc[VSUSP] = 26; /* C-z */ |
| 257 | 248 | ||
| 258 | /* use line dicipline 0 */ | 249 | /* use line discipline 0 */ |
| 259 | tty.c_line = 0; | 250 | tty.c_line = 0; |
| 260 | 251 | ||
| 261 | /* Make it be sane */ | 252 | /* Make it be sane */ |
| @@ -282,7 +273,7 @@ static void open_stdio_to_tty(const char* tty_name, int exit_on_failure) | |||
| 282 | /* empty tty_name means "use init's tty", else... */ | 273 | /* empty tty_name means "use init's tty", else... */ |
| 283 | if (tty_name[0]) { | 274 | if (tty_name[0]) { |
| 284 | int fd; | 275 | int fd; |
| 285 | close(0); | 276 | close(STDIN_FILENO); |
| 286 | /* fd can be only < 0 or 0: */ | 277 | /* fd can be only < 0 or 0: */ |
| 287 | fd = device_open(tty_name, O_RDWR); | 278 | fd = device_open(tty_name, O_RDWR); |
| 288 | if (fd) { | 279 | if (fd) { |
| @@ -292,12 +283,12 @@ static void open_stdio_to_tty(const char* tty_name, int exit_on_failure) | |||
| 292 | _exit(EXIT_FAILURE); | 283 | _exit(EXIT_FAILURE); |
| 293 | if (ENABLE_DEBUG_INIT) | 284 | if (ENABLE_DEBUG_INIT) |
| 294 | _exit(2); | 285 | _exit(2); |
| 295 | /* NB: we don't reach this if we were called after vfork. | 286 | /* NB: we don't reach this if we were called after vfork. |
| 296 | * Thus halt_reboot_pwoff() itself need not be vfork-safe. */ | 287 | * Thus halt_reboot_pwoff() itself need not be vfork-safe. */ |
| 297 | halt_reboot_pwoff(SIGUSR1); /* halt the system */ | 288 | halt_reboot_pwoff(SIGUSR1); /* halt the system */ |
| 298 | } | 289 | } |
| 299 | dup2(0, 1); | 290 | dup2(STDIN_FILENO, STDOUT_FILENO); |
| 300 | dup2(0, 2); | 291 | dup2(STDIN_FILENO, STDERR_FILENO); |
| 301 | } | 292 | } |
| 302 | set_sane_term(); | 293 | set_sane_term(); |
| 303 | } | 294 | } |
| @@ -346,8 +337,7 @@ static void init_exec(const char *command) | |||
| 346 | ioctl(STDIN_FILENO, TIOCSCTTY, 0 /*only try, don't steal*/); | 337 | ioctl(STDIN_FILENO, TIOCSCTTY, 0 /*only try, don't steal*/); |
| 347 | } | 338 | } |
| 348 | BB_EXECVP(cmd[0] + dash, cmd); | 339 | BB_EXECVP(cmd[0] + dash, cmd); |
| 349 | message(L_LOG | L_CONSOLE, "Cannot run '%s': %s", | 340 | message(L_LOG | L_CONSOLE, "Cannot run '%s': %s", cmd[0], strerror(errno)); |
| 350 | cmd[0], strerror(errno)); | ||
| 351 | /* returns if execvp fails */ | 341 | /* returns if execvp fails */ |
| 352 | } | 342 | } |
| 353 | 343 | ||
| @@ -434,7 +424,6 @@ static pid_t run(const struct init_action *a) | |||
| 434 | waitfor(pid); | 424 | waitfor(pid); |
| 435 | _exit(EXIT_SUCCESS); | 425 | _exit(EXIT_SUCCESS); |
| 436 | } | 426 | } |
| 437 | |||
| 438 | /* Child - fall though to actually execute things */ | 427 | /* Child - fall though to actually execute things */ |
| 439 | } | 428 | } |
| 440 | #endif | 429 | #endif |
| @@ -640,8 +629,7 @@ static void new_init_action(uint8_t action_type, const char *command, const char | |||
| 640 | /* don't enter action if it's already in the list, | 629 | /* don't enter action if it's already in the list, |
| 641 | * but do overwrite existing actions */ | 630 | * but do overwrite existing actions */ |
| 642 | if ((strcmp(a->command, command) == 0) | 631 | if ((strcmp(a->command, command) == 0) |
| 643 | && (strcmp(a->terminal, cons) == 0) | 632 | && (strcmp(a->terminal, cons) == 0)) { |
| 644 | ) { | ||
| 645 | a->action_type = action_type; | 633 | a->action_type = action_type; |
| 646 | return; | 634 | return; |
| 647 | } | 635 | } |
| @@ -687,95 +675,6 @@ static void delete_init_action(struct init_action *action) | |||
| 687 | */ | 675 | */ |
| 688 | static void parse_inittab(void) | 676 | static void parse_inittab(void) |
| 689 | { | 677 | { |
| 690 | #if 0 | ||
| 691 | FILE *file; | ||
| 692 | char buf[COMMAND_SIZE]; | ||
| 693 | |||
| 694 | if (ENABLE_FEATURE_USE_INITTAB) | ||
| 695 | file = fopen(INITTAB, "r"); | ||
| 696 | else | ||
| 697 | file = NULL; | ||
| 698 | |||
| 699 | /* No inittab file -- set up some default behavior */ | ||
| 700 | if (file == NULL) { | ||
| 701 | /* Reboot on Ctrl-Alt-Del */ | ||
| 702 | new_init_action(CTRLALTDEL, "reboot", ""); | ||
| 703 | /* Umount all filesystems on halt/reboot */ | ||
| 704 | new_init_action(SHUTDOWN, "umount -a -r", ""); | ||
| 705 | /* Swapoff on halt/reboot */ | ||
| 706 | if (ENABLE_SWAPONOFF) | ||
| 707 | new_init_action(SHUTDOWN, "swapoff -a", ""); | ||
| 708 | /* Prepare to restart init when a QUIT is received */ | ||
| 709 | new_init_action(RESTART, "init", ""); | ||
| 710 | /* Askfirst shell on tty1-4 */ | ||
| 711 | new_init_action(ASKFIRST, bb_default_login_shell, ""); | ||
| 712 | new_init_action(ASKFIRST, bb_default_login_shell, VC_2); | ||
| 713 | new_init_action(ASKFIRST, bb_default_login_shell, VC_3); | ||
| 714 | new_init_action(ASKFIRST, bb_default_login_shell, VC_4); | ||
| 715 | /* sysinit */ | ||
| 716 | new_init_action(SYSINIT, INIT_SCRIPT, ""); | ||
| 717 | |||
| 718 | return; | ||
| 719 | } | ||
| 720 | |||
| 721 | while (fgets(buf, COMMAND_SIZE, file) != NULL) { | ||
| 722 | static const char actions[] = | ||
| 723 | STR_SYSINIT "sysinit\0" | ||
| 724 | STR_RESPAWN "respawn\0" | ||
| 725 | STR_ASKFIRST "askfirst\0" | ||
| 726 | STR_WAIT "wait\0" | ||
| 727 | STR_ONCE "once\0" | ||
| 728 | STR_CTRLALTDEL "ctrlaltdel\0" | ||
| 729 | STR_SHUTDOWN "shutdown\0" | ||
| 730 | STR_RESTART "restart\0" | ||
| 731 | ; | ||
| 732 | char tmpConsole[CONSOLE_NAME_SIZE]; | ||
| 733 | char *id, *runlev, *action, *command; | ||
| 734 | const char *a; | ||
| 735 | |||
| 736 | /* Skip leading spaces */ | ||
| 737 | id = skip_whitespace(buf); | ||
| 738 | /* Trim the trailing '\n' */ | ||
| 739 | *strchrnul(id, '\n') = '\0'; | ||
| 740 | /* Skip the line if it is a comment */ | ||
| 741 | if (*id == '#' || *id == '\0') | ||
| 742 | continue; | ||
| 743 | |||
| 744 | /* Line is: "id:runlevel_ignored:action:command" */ | ||
| 745 | runlev = strchr(id, ':'); | ||
| 746 | if (runlev == NULL /*|| runlev[1] == '\0' - not needed */) | ||
| 747 | goto bad_entry; | ||
| 748 | action = strchr(runlev + 1, ':'); | ||
| 749 | if (action == NULL /*|| action[1] == '\0' - not needed */) | ||
| 750 | goto bad_entry; | ||
| 751 | command = strchr(action + 1, ':'); | ||
| 752 | if (command == NULL || command[1] == '\0') | ||
| 753 | goto bad_entry; | ||
| 754 | |||
| 755 | *command = '\0'; /* action => ":action\0" now */ | ||
| 756 | for (a = actions; a[0]; a += strlen(a) + 1) { | ||
| 757 | if (strcmp(a + 1, action + 1) == 0) { | ||
| 758 | *runlev = '\0'; | ||
| 759 | if (*id != '\0') { | ||
| 760 | if (strncmp(id, "/dev/", 5) == 0) | ||
| 761 | id += 5; | ||
| 762 | strcpy(tmpConsole, "/dev/"); | ||
| 763 | safe_strncpy(tmpConsole + 5, id, | ||
| 764 | sizeof(tmpConsole) - 5); | ||
| 765 | id = tmpConsole; | ||
| 766 | } | ||
| 767 | new_init_action((uint8_t)a[0], command + 1, id); | ||
| 768 | goto next_line; | ||
| 769 | } | ||
| 770 | } | ||
| 771 | *command = ':'; | ||
| 772 | /* Choke on an unknown action */ | ||
| 773 | bad_entry: | ||
| 774 | message(L_LOG | L_CONSOLE, "Bad inittab entry: %s", id); | ||
| 775 | next_line: ; | ||
| 776 | } | ||
| 777 | fclose(file); | ||
| 778 | #else | ||
| 779 | char *token[4]; | 678 | char *token[4]; |
| 780 | /* order must correspond to SYSINIT..RESTART constants */ | 679 | /* order must correspond to SYSINIT..RESTART constants */ |
| 781 | static const char actions[] ALIGN1 = | 680 | static const char actions[] ALIGN1 = |
| @@ -808,7 +707,7 @@ static void parse_inittab(void) | |||
| 808 | /* optional_tty:ignored_runlevel:action:command | 707 | /* optional_tty:ignored_runlevel:action:command |
| 809 | * Delims are not to be collapsed and need exactly 4 tokens | 708 | * Delims are not to be collapsed and need exactly 4 tokens |
| 810 | */ | 709 | */ |
| 811 | while (config_read(parser, token, 4, 0, "#:", PARSE_DONT_TRIM|PARSE_DONT_REDUCE|PARSE_LAST_IS_GREEDY)) { | 710 | while (config_read(parser, token, 4, 0, "#:", PARSE_DONT_TRIM|PARSE_DONT_REDUCE|PARSE_LAST_IS_GREEDY)) { |
| 812 | int action; | 711 | int action; |
| 813 | char *tty = token[0]; | 712 | char *tty = token[0]; |
| 814 | 713 | ||
| @@ -828,10 +727,10 @@ static void parse_inittab(void) | |||
| 828 | free(tty); | 727 | free(tty); |
| 829 | continue; | 728 | continue; |
| 830 | bad_entry: | 729 | bad_entry: |
| 831 | message(L_LOG | L_CONSOLE, "Bad inittab entry at line %d", parser->lineno); | 730 | message(L_LOG | L_CONSOLE, "Bad inittab entry at line %d", |
| 731 | parser->lineno); | ||
| 832 | } | 732 | } |
| 833 | config_close(parser); | 733 | config_close(parser); |
| 834 | #endif | ||
| 835 | } | 734 | } |
| 836 | 735 | ||
| 837 | #if ENABLE_FEATURE_USE_INITTAB | 736 | #if ENABLE_FEATURE_USE_INITTAB |
