diff options
author | Ron Yorston <rmy@pobox.com> | 2013-08-27 16:10:53 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2013-08-27 16:10:53 +0100 |
commit | 3fd34651ea72ea1c335d3170f234cb0517fd897f (patch) | |
tree | 36e8fc40cffd464ffda4759020777dd3ca23ca31 /init | |
parent | e3ac39098326de084a805d0dd31db9666b734f20 (diff) | |
parent | d6ae4fb446daedfe3073d67be655942e9fa7eb18 (diff) | |
download | busybox-w32-3fd34651ea72ea1c335d3170f234cb0517fd897f.tar.gz busybox-w32-3fd34651ea72ea1c335d3170f234cb0517fd897f.tar.bz2 busybox-w32-3fd34651ea72ea1c335d3170f234cb0517fd897f.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'init')
-rw-r--r-- | init/init.c | 68 |
1 files changed, 41 insertions, 27 deletions
diff --git a/init/init.c b/init/init.c index 15aad474f..edb5be696 100644 --- a/init/init.c +++ b/init/init.c | |||
@@ -140,12 +140,11 @@ | |||
140 | * not fully functional init by switching it on! */ | 140 | * not fully functional init by switching it on! */ |
141 | #define DEBUG_INIT 0 | 141 | #define DEBUG_INIT 0 |
142 | 142 | ||
143 | #define COMMAND_SIZE 256 | ||
144 | #define CONSOLE_NAME_SIZE 32 | 143 | #define CONSOLE_NAME_SIZE 32 |
145 | 144 | ||
146 | /* Default sysinit script. */ | 145 | /* Default sysinit script. */ |
147 | #ifndef INIT_SCRIPT | 146 | #ifndef INIT_SCRIPT |
148 | #define INIT_SCRIPT "/etc/init.d/rcS" | 147 | # define INIT_SCRIPT "/etc/init.d/rcS" |
149 | #endif | 148 | #endif |
150 | 149 | ||
151 | /* Each type of actions can appear many times. They will be | 150 | /* Each type of actions can appear many times. They will be |
@@ -195,7 +194,7 @@ struct init_action { | |||
195 | pid_t pid; | 194 | pid_t pid; |
196 | uint8_t action_type; | 195 | uint8_t action_type; |
197 | char terminal[CONSOLE_NAME_SIZE]; | 196 | char terminal[CONSOLE_NAME_SIZE]; |
198 | char command[COMMAND_SIZE]; | 197 | char command[1]; |
199 | }; | 198 | }; |
200 | 199 | ||
201 | static struct init_action *init_action_list = NULL; | 200 | static struct init_action *init_action_list = NULL; |
@@ -398,7 +397,7 @@ static void reset_sighandlers_and_unblock_sigs(void) | |||
398 | } | 397 | } |
399 | 398 | ||
400 | /* Wrapper around exec: | 399 | /* Wrapper around exec: |
401 | * Takes string (max COMMAND_SIZE chars). | 400 | * Takes string. |
402 | * If chars like '>' detected, execs '[-]/bin/sh -c "exec ......."'. | 401 | * If chars like '>' detected, execs '[-]/bin/sh -c "exec ......."'. |
403 | * Otherwise splits words on whitespace, deals with leading dash, | 402 | * Otherwise splits words on whitespace, deals with leading dash, |
404 | * and uses plain exec(). | 403 | * and uses plain exec(). |
@@ -406,10 +405,15 @@ static void reset_sighandlers_and_unblock_sigs(void) | |||
406 | */ | 405 | */ |
407 | static void init_exec(const char *command) | 406 | static void init_exec(const char *command) |
408 | { | 407 | { |
409 | char *cmd[COMMAND_SIZE / 2]; | 408 | /* +8 allows to write VLA sizes below more efficiently: */ |
410 | char buf[COMMAND_SIZE + 6]; /* COMMAND_SIZE+strlen("exec ")+1 */ | 409 | unsigned command_size = strlen(command) + 8; |
411 | int dash = (command[0] == '-' /* maybe? && command[1] == '/' */); | 410 | /* strlen(command) + strlen("exec ")+1: */ |
412 | 411 | char buf[command_size]; | |
412 | /* strlen(command) / 2 + 4: */ | ||
413 | char *cmd[command_size / 2]; | ||
414 | int dash; | ||
415 | |||
416 | dash = (command[0] == '-' /* maybe? && command[1] == '/' */); | ||
413 | command += dash; | 417 | command += dash; |
414 | 418 | ||
415 | /* See if any special /bin/sh requiring characters are present */ | 419 | /* See if any special /bin/sh requiring characters are present */ |
@@ -626,21 +630,21 @@ static void new_init_action(uint8_t action_type, const char *command, const char | |||
626 | nextp = &a->next; | 630 | nextp = &a->next; |
627 | } | 631 | } |
628 | 632 | ||
629 | a = xzalloc(sizeof(*a)); | 633 | a = xzalloc(sizeof(*a) + strlen(command)); |
630 | 634 | ||
631 | /* Append to the end of the list */ | 635 | /* Append to the end of the list */ |
632 | append: | 636 | append: |
633 | *nextp = a; | 637 | *nextp = a; |
634 | a->action_type = action_type; | 638 | a->action_type = action_type; |
635 | safe_strncpy(a->command, command, sizeof(a->command)); | 639 | strcpy(a->command, command); |
636 | safe_strncpy(a->terminal, cons, sizeof(a->terminal)); | 640 | safe_strncpy(a->terminal, cons, sizeof(a->terminal)); |
637 | dbg_message(L_LOG | L_CONSOLE, "command='%s' action=%d tty='%s'\n", | 641 | dbg_message(L_LOG | L_CONSOLE, "command='%s' action=%x tty='%s'\n", |
638 | a->command, a->action_type, a->terminal); | 642 | a->command, a->action_type, a->terminal); |
639 | } | 643 | } |
640 | 644 | ||
641 | /* NOTE that if CONFIG_FEATURE_USE_INITTAB is NOT defined, | 645 | /* NOTE that if CONFIG_FEATURE_USE_INITTAB is NOT defined, |
642 | * then parse_inittab() simply adds in some default | 646 | * then parse_inittab() simply adds in some default |
643 | * actions(i.e., runs INIT_SCRIPT and then starts a pair | 647 | * actions (i.e., runs INIT_SCRIPT and then starts a pair |
644 | * of "askfirst" shells). If CONFIG_FEATURE_USE_INITTAB | 648 | * of "askfirst" shells). If CONFIG_FEATURE_USE_INITTAB |
645 | * _is_ defined, but /etc/inittab is missing, this | 649 | * _is_ defined, but /etc/inittab is missing, this |
646 | * results in the same set of default behaviors. | 650 | * results in the same set of default behaviors. |
@@ -655,23 +659,22 @@ static void parse_inittab(void) | |||
655 | #endif | 659 | #endif |
656 | { | 660 | { |
657 | /* No inittab file - set up some default behavior */ | 661 | /* No inittab file - set up some default behavior */ |
658 | /* Reboot on Ctrl-Alt-Del */ | 662 | /* Sysinit */ |
659 | new_init_action(CTRLALTDEL, "reboot", ""); | 663 | new_init_action(SYSINIT, INIT_SCRIPT, ""); |
660 | /* Umount all filesystems on halt/reboot */ | ||
661 | new_init_action(SHUTDOWN, "umount -a -r", ""); | ||
662 | /* Swapoff on halt/reboot */ | ||
663 | if (ENABLE_SWAPONOFF) | ||
664 | new_init_action(SHUTDOWN, "swapoff -a", ""); | ||
665 | /* Prepare to restart init when a QUIT is received */ | ||
666 | new_init_action(RESTART, "init", ""); | ||
667 | /* Askfirst shell on tty1-4 */ | 664 | /* Askfirst shell on tty1-4 */ |
668 | new_init_action(ASKFIRST, bb_default_login_shell, ""); | 665 | new_init_action(ASKFIRST, bb_default_login_shell, ""); |
669 | //TODO: VC_1 instead of ""? "" is console -> ctty problems -> angry users | 666 | //TODO: VC_1 instead of ""? "" is console -> ctty problems -> angry users |
670 | new_init_action(ASKFIRST, bb_default_login_shell, VC_2); | 667 | new_init_action(ASKFIRST, bb_default_login_shell, VC_2); |
671 | new_init_action(ASKFIRST, bb_default_login_shell, VC_3); | 668 | new_init_action(ASKFIRST, bb_default_login_shell, VC_3); |
672 | new_init_action(ASKFIRST, bb_default_login_shell, VC_4); | 669 | new_init_action(ASKFIRST, bb_default_login_shell, VC_4); |
673 | /* sysinit */ | 670 | /* Reboot on Ctrl-Alt-Del */ |
674 | new_init_action(SYSINIT, INIT_SCRIPT, ""); | 671 | new_init_action(CTRLALTDEL, "reboot", ""); |
672 | /* Umount all filesystems on halt/reboot */ | ||
673 | new_init_action(SHUTDOWN, "umount -a -r", ""); | ||
674 | /* Swapoff on halt/reboot */ | ||
675 | new_init_action(SHUTDOWN, "swapoff -a", ""); | ||
676 | /* Restart init when a QUIT is received */ | ||
677 | new_init_action(RESTART, "init", ""); | ||
675 | return; | 678 | return; |
676 | } | 679 | } |
677 | 680 | ||
@@ -931,10 +934,17 @@ static void reload_inittab(void) | |||
931 | 934 | ||
932 | /* Remove stale entries and SYSINIT entries. | 935 | /* Remove stale entries and SYSINIT entries. |
933 | * We never rerun SYSINIT entries anyway, | 936 | * We never rerun SYSINIT entries anyway, |
934 | * removing them too saves a few bytes */ | 937 | * removing them too saves a few bytes |
938 | */ | ||
935 | nextp = &init_action_list; | 939 | nextp = &init_action_list; |
936 | while ((a = *nextp) != NULL) { | 940 | while ((a = *nextp) != NULL) { |
937 | if ((a->action_type & ~SYSINIT) == 0) { | 941 | /* |
942 | * Why pid == 0 check? | ||
943 | * Process can be removed from inittab and added *later*. | ||
944 | * If we delete its entry but process still runs, | ||
945 | * duplicate is spawned when the entry is re-added. | ||
946 | */ | ||
947 | if ((a->action_type & ~SYSINIT) == 0 && a->pid == 0) { | ||
938 | *nextp = a->next; | 948 | *nextp = a->next; |
939 | free(a); | 949 | free(a); |
940 | } else { | 950 | } else { |
@@ -1058,10 +1068,13 @@ int init_main(int argc UNUSED_PARAM, char **argv) | |||
1058 | message(L_CONSOLE | L_LOG, "init started: %s", bb_banner); | 1068 | message(L_CONSOLE | L_LOG, "init started: %s", bb_banner); |
1059 | #endif | 1069 | #endif |
1060 | 1070 | ||
1071 | #if 0 | ||
1072 | /* It's 2013, does anyone really still depend on this? */ | ||
1073 | /* If you do, consider adding swapon to sysinot actions then! */ | ||
1061 | /* struct sysinfo is linux-specific */ | 1074 | /* struct sysinfo is linux-specific */ |
1062 | #ifdef __linux__ | 1075 | # ifdef __linux__ |
1063 | /* Make sure there is enough memory to do something useful. */ | 1076 | /* Make sure there is enough memory to do something useful. */ |
1064 | if (ENABLE_SWAPONOFF) { | 1077 | /*if (ENABLE_SWAPONOFF) - WRONG: we may have non-bbox swapon*/ { |
1065 | struct sysinfo info; | 1078 | struct sysinfo info; |
1066 | 1079 | ||
1067 | if (sysinfo(&info) == 0 | 1080 | if (sysinfo(&info) == 0 |
@@ -1075,6 +1088,7 @@ int init_main(int argc UNUSED_PARAM, char **argv) | |||
1075 | run_actions(SYSINIT); /* wait and removing */ | 1088 | run_actions(SYSINIT); /* wait and removing */ |
1076 | } | 1089 | } |
1077 | } | 1090 | } |
1091 | # endif | ||
1078 | #endif | 1092 | #endif |
1079 | 1093 | ||
1080 | /* Check if we are supposed to be in single user mode */ | 1094 | /* Check if we are supposed to be in single user mode */ |