diff options
| author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2008-07-17 14:00:42 +0000 |
|---|---|---|
| committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2008-07-17 14:00:42 +0000 |
| commit | 54d50a0b476ec2e6015dffd9598edc2d7968047b (patch) | |
| tree | 4ee4b75067cabcbb0dca4b1c99be668dc48b563c /init | |
| parent | 679212836a881b53382ea6bd811f38e00705d50d (diff) | |
| download | busybox-w32-54d50a0b476ec2e6015dffd9598edc2d7968047b.tar.gz busybox-w32-54d50a0b476ec2e6015dffd9598edc2d7968047b.tar.bz2 busybox-w32-54d50a0b476ec2e6015dffd9598edc2d7968047b.zip | |
- fix "noreduce" flag of config_read (didn't work at all, at least for me).
- convert init's inittab parsing to the new config parser:
function old new delta
config_read 393 386 -7
static.actions 72 64 -8
.rodata 121772 121764 -8
parse_inittab 554 393 -161
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-184) Total: -184 bytes
Diffstat (limited to 'init')
| -rw-r--r-- | init/init.c | 74 |
1 files changed, 69 insertions, 5 deletions
diff --git a/init/init.c b/init/init.c index 4b2bd9c77..3f16551ea 100644 --- a/init/init.c +++ b/init/init.c | |||
| @@ -43,6 +43,7 @@ | |||
| 43 | #define SHUTDOWN 0x40 | 43 | #define SHUTDOWN 0x40 |
| 44 | #define RESTART 0x80 | 44 | #define RESTART 0x80 |
| 45 | 45 | ||
| 46 | /* | ||
| 46 | #define STR_SYSINIT "\x01" | 47 | #define STR_SYSINIT "\x01" |
| 47 | #define STR_RESPAWN "\x02" | 48 | #define STR_RESPAWN "\x02" |
| 48 | #define STR_ASKFIRST "\x04" | 49 | #define STR_ASKFIRST "\x04" |
| @@ -51,7 +52,7 @@ | |||
| 51 | #define STR_CTRLALTDEL "\x20" | 52 | #define STR_CTRLALTDEL "\x20" |
| 52 | #define STR_SHUTDOWN "\x40" | 53 | #define STR_SHUTDOWN "\x40" |
| 53 | #define STR_RESTART "\x80" | 54 | #define STR_RESTART "\x80" |
| 54 | 55 | */ | |
| 55 | /* Set up a linked list of init_actions, to be read from inittab */ | 56 | /* Set up a linked list of init_actions, to be read from inittab */ |
| 56 | struct init_action { | 57 | struct init_action { |
| 57 | struct init_action *next; | 58 | struct init_action *next; |
| @@ -558,12 +559,11 @@ static void kill_all_processes(void) | |||
| 558 | 559 | ||
| 559 | static void halt_reboot_pwoff(int sig) | 560 | static void halt_reboot_pwoff(int sig) |
| 560 | { | 561 | { |
| 561 | const char *m; | 562 | const char *m = "halt"; |
| 562 | int rb; | 563 | int rb; |
| 563 | 564 | ||
| 564 | kill_all_processes(); | 565 | kill_all_processes(); |
| 565 | 566 | ||
| 566 | m = "halt"; | ||
| 567 | rb = RB_HALT_SYSTEM; | 567 | rb = RB_HALT_SYSTEM; |
| 568 | if (sig == SIGTERM) { | 568 | if (sig == SIGTERM) { |
| 569 | m = "reboot"; | 569 | m = "reboot"; |
| @@ -687,6 +687,7 @@ static void delete_init_action(struct init_action *action) | |||
| 687 | */ | 687 | */ |
| 688 | static void parse_inittab(void) | 688 | static void parse_inittab(void) |
| 689 | { | 689 | { |
| 690 | #if 0 | ||
| 690 | FILE *file; | 691 | FILE *file; |
| 691 | char buf[COMMAND_SIZE]; | 692 | char buf[COMMAND_SIZE]; |
| 692 | 693 | ||
| @@ -774,6 +775,67 @@ static void parse_inittab(void) | |||
| 774 | next_line: ; | 775 | next_line: ; |
| 775 | } | 776 | } |
| 776 | fclose(file); | 777 | fclose(file); |
| 778 | #else | ||
| 779 | char *token[4]; | ||
| 780 | static const char actions[] ALIGN1 = { | ||
| 781 | "sysinit\0""respawn\0""askfirst\0""wait\0""once\0" | ||
| 782 | "ctrlaltdel\0""shutdown\0""restart\0" | ||
| 783 | }; | ||
| 784 | enum {STR_SYSINIT=0, STR_RESPAWN, STR_ASKFIRST, STR_WAIT, STR_ONCE, | ||
| 785 | STR_CTRLALTDEL, STR_SHUTDOWN, STR_RESTART}; | ||
| 786 | |||
| 787 | parser_t *parser = config_open(INITTAB); | ||
| 788 | /* No inittab file -- set up some default behavior */ | ||
| 789 | if (parser == NULL) { | ||
| 790 | /* Reboot on Ctrl-Alt-Del */ | ||
| 791 | new_init_action(CTRLALTDEL, "reboot", ""); | ||
| 792 | /* Umount all filesystems on halt/reboot */ | ||
| 793 | new_init_action(SHUTDOWN, "umount -a -r", ""); | ||
| 794 | /* Swapoff on halt/reboot */ | ||
| 795 | if (ENABLE_SWAPONOFF) | ||
| 796 | new_init_action(SHUTDOWN, "swapoff -a", ""); | ||
| 797 | /* Prepare to restart init when a QUIT is received */ | ||
| 798 | new_init_action(RESTART, "init", ""); | ||
| 799 | /* Askfirst shell on tty1-4 */ | ||
| 800 | new_init_action(ASKFIRST, bb_default_login_shell, ""); | ||
| 801 | new_init_action(ASKFIRST, bb_default_login_shell, VC_2); | ||
| 802 | new_init_action(ASKFIRST, bb_default_login_shell, VC_3); | ||
| 803 | new_init_action(ASKFIRST, bb_default_login_shell, VC_4); | ||
| 804 | /* sysinit */ | ||
| 805 | new_init_action(SYSINIT, INIT_SCRIPT, ""); | ||
| 806 | |||
| 807 | return; | ||
| 808 | } | ||
| 809 | /* optional_tty:ignored_runlevel:action:command | ||
| 810 | * i.e. 4 tokens, minimum number of tokens is 2 ("::sysinit:echo foo") | ||
| 811 | * We require tokens not to be collapsed -- need exactly 4 tokens. | ||
| 812 | */ | ||
| 813 | while (config_read(parser, token, -4, 2, ":", '#') >= 0) { | ||
| 814 | int action = -1; | ||
| 815 | char *tty = token[0]; | ||
| 816 | char *action_string = token[2]; | ||
| 817 | char *command = token[3]; | ||
| 818 | |||
| 819 | if (action_string) | ||
| 820 | action = index_in_strings(actions, action_string); | ||
| 821 | if (action < 0 || !command || !strlen(command)) | ||
| 822 | goto bad_entry; | ||
| 823 | if (tty) { | ||
| 824 | /* turn .*TTY -> /dev/TTY */ | ||
| 825 | if (!strncmp(tty, "/dev/", 5)) | ||
| 826 | tty += 5; | ||
| 827 | tty = concat_path_file("/dev/", tty); | ||
| 828 | } else | ||
| 829 | tty = ""; /* XXX: ugh. */ | ||
| 830 | new_init_action (1<<action, command, tty); | ||
| 831 | if (ENABLE_FEATURE_CLEAN_UP) | ||
| 832 | free(tty); | ||
| 833 | continue; | ||
| 834 | bad_entry: | ||
| 835 | message(L_LOG | L_CONSOLE, "Bad inittab entry: %s", parser->line); | ||
| 836 | } | ||
| 837 | config_close(parser); | ||
| 838 | #endif | ||
| 777 | } | 839 | } |
| 778 | 840 | ||
| 779 | #if ENABLE_FEATURE_USE_INITTAB | 841 | #if ENABLE_FEATURE_USE_INITTAB |
| @@ -866,7 +928,7 @@ int init_main(int argc UNUSED_PARAM, char **argv) | |||
| 866 | /* Figure out where the default console should be */ | 928 | /* Figure out where the default console should be */ |
| 867 | console_init(); | 929 | console_init(); |
| 868 | set_sane_term(); | 930 | set_sane_term(); |
| 869 | chdir("/"); | 931 | xchdir("/"); |
| 870 | setsid(); | 932 | setsid(); |
| 871 | { | 933 | { |
| 872 | const char *const *e; | 934 | const char *const *e; |
| @@ -875,7 +937,8 @@ int init_main(int argc UNUSED_PARAM, char **argv) | |||
| 875 | putenv((char *) *e); | 937 | putenv((char *) *e); |
| 876 | } | 938 | } |
| 877 | 939 | ||
| 878 | if (argv[1]) setenv("RUNLEVEL", argv[1], 1); | 940 | if (argv[1]) |
| 941 | setenv("RUNLEVEL", argv[1], 1); | ||
| 879 | 942 | ||
| 880 | /* Hello world */ | 943 | /* Hello world */ |
| 881 | message(MAYBE_CONSOLE | L_LOG, "init started: %s", bb_banner); | 944 | message(MAYBE_CONSOLE | L_LOG, "init started: %s", bb_banner); |
| @@ -900,6 +963,7 @@ int init_main(int argc UNUSED_PARAM, char **argv) | |||
| 900 | if (argv[1] | 963 | if (argv[1] |
| 901 | && (!strcmp(argv[1], "single") || !strcmp(argv[1], "-s") || LONE_CHAR(argv[1], '1')) | 964 | && (!strcmp(argv[1], "single") || !strcmp(argv[1], "-s") || LONE_CHAR(argv[1], '1')) |
| 902 | ) { | 965 | ) { |
| 966 | /* ??? shouldn't we set RUNLEVEL="b" here? */ | ||
| 903 | /* Start a shell on console */ | 967 | /* Start a shell on console */ |
| 904 | new_init_action(RESPAWN, bb_default_login_shell, ""); | 968 | new_init_action(RESPAWN, bb_default_login_shell, ""); |
| 905 | } else { | 969 | } else { |
