diff options
| author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-01-21 00:41:04 +0000 |
|---|---|---|
| committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-01-21 00:41:04 +0000 |
| commit | bb21944ea0d5e95f07691dfaeaba404ddfa70528 (patch) | |
| tree | 3e82c2dd94d674a723f3d7df350f32dc8892adc1 /init | |
| parent | ff978c7d73d84e06ee5dc927a180cdc794d35b21 (diff) | |
| download | busybox-w32-bb21944ea0d5e95f07691dfaeaba404ddfa70528.tar.gz busybox-w32-bb21944ea0d5e95f07691dfaeaba404ddfa70528.tar.bz2 busybox-w32-bb21944ea0d5e95f07691dfaeaba404ddfa70528.zip | |
Introduce FEATURE_EXEC_PREFER_APPLETS = "re-execute our own
executable if we asked to exec someting with argv[0] == known_applet"
Use it in init. Also respect PATH in init, remove explicit "/sbin" etc
from exec. Patch by Gabriel L. Somlo <somlo@cmu.edu>
git-svn-id: svn://busybox.net/trunk/busybox@17426 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'init')
| -rw-r--r-- | init/init.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/init/init.c b/init/init.c index 6fc68afb1..7694b4448 100644 --- a/init/init.c +++ b/init/init.c | |||
| @@ -389,6 +389,7 @@ static pid_t run(const struct init_action *a) | |||
| 389 | #include CUSTOMIZED_BANNER | 389 | #include CUSTOMIZED_BANNER |
| 390 | #endif | 390 | #endif |
| 391 | "\nPlease press Enter to activate this console. "; | 391 | "\nPlease press Enter to activate this console. "; |
| 392 | char *prog; | ||
| 392 | 393 | ||
| 393 | /* Block sigchild while forking. */ | 394 | /* Block sigchild while forking. */ |
| 394 | sigemptyset(&nmask); | 395 | sigemptyset(&nmask); |
| @@ -560,7 +561,10 @@ static pid_t run(const struct init_action *a) | |||
| 560 | 561 | ||
| 561 | /* Now run it. The new program will take over this PID, | 562 | /* Now run it. The new program will take over this PID, |
| 562 | * so nothing further in init.c should be run. */ | 563 | * so nothing further in init.c should be run. */ |
| 563 | execv(cmdpath, cmd); | 564 | prog = cmdpath; |
| 565 | if (ENABLE_FEATURE_EXEC_PREFER_APPLETS && find_applet_by_name(prog)) | ||
| 566 | prog = CONFIG_BUSYBOX_EXEC_PATH; | ||
| 567 | execvp(prog, cmd); | ||
| 564 | 568 | ||
| 565 | /* We're still here? Some error happened. */ | 569 | /* We're still here? Some error happened. */ |
| 566 | message(LOG | CONSOLE, "Bummer, cannot run '%s': %m", cmdpath); | 570 | message(LOG | CONSOLE, "Bummer, cannot run '%s': %m", cmdpath); |
| @@ -678,6 +682,7 @@ static void exec_signal(int sig ATTRIBUTE_UNUSED) | |||
| 678 | { | 682 | { |
| 679 | struct init_action *a, *tmp; | 683 | struct init_action *a, *tmp; |
| 680 | sigset_t unblock_signals; | 684 | sigset_t unblock_signals; |
| 685 | char *prog; | ||
| 681 | 686 | ||
| 682 | for (a = init_action_list; a; a = tmp) { | 687 | for (a = init_action_list; a; a = tmp) { |
| 683 | tmp = a->next; | 688 | tmp = a->next; |
| @@ -713,7 +718,10 @@ static void exec_signal(int sig ATTRIBUTE_UNUSED) | |||
| 713 | dup(0); | 718 | dup(0); |
| 714 | 719 | ||
| 715 | messageD(CONSOLE | LOG, "Trying to re-exec %s", a->command); | 720 | messageD(CONSOLE | LOG, "Trying to re-exec %s", a->command); |
| 716 | execl(a->command, a->command, NULL); | 721 | prog = a->command; |
| 722 | if (ENABLE_FEATURE_EXEC_PREFER_APPLETS && find_applet_by_name(prog)) | ||
| 723 | prog = CONFIG_BUSYBOX_EXEC_PATH; | ||
| 724 | execlp(prog, a->command, NULL); | ||
| 717 | 725 | ||
| 718 | message(CONSOLE | LOG, "exec of '%s' failed: %m", | 726 | message(CONSOLE | LOG, "exec of '%s' failed: %m", |
| 719 | a->command); | 727 | a->command); |
| @@ -852,13 +860,13 @@ static void parse_inittab(void) | |||
| 852 | /* No inittab file -- set up some default behavior */ | 860 | /* No inittab file -- set up some default behavior */ |
| 853 | #endif | 861 | #endif |
| 854 | /* Reboot on Ctrl-Alt-Del */ | 862 | /* Reboot on Ctrl-Alt-Del */ |
| 855 | new_init_action(CTRLALTDEL, "/sbin/reboot", ""); | 863 | new_init_action(CTRLALTDEL, "reboot", ""); |
| 856 | /* Umount all filesystems on halt/reboot */ | 864 | /* Umount all filesystems on halt/reboot */ |
| 857 | new_init_action(SHUTDOWN, "/bin/umount -a -r", ""); | 865 | new_init_action(SHUTDOWN, "umount -a -r", ""); |
| 858 | /* Swapoff on halt/reboot */ | 866 | /* Swapoff on halt/reboot */ |
| 859 | if(ENABLE_SWAPONOFF) new_init_action(SHUTDOWN, "/sbin/swapoff -a", ""); | 867 | if(ENABLE_SWAPONOFF) new_init_action(SHUTDOWN, "swapoff -a", ""); |
| 860 | /* Prepare to restart init when a HUP is received */ | 868 | /* Prepare to restart init when a HUP is received */ |
| 861 | new_init_action(RESTART, "/sbin/init", ""); | 869 | new_init_action(RESTART, "init", ""); |
| 862 | /* Askfirst shell on tty1-4 */ | 870 | /* Askfirst shell on tty1-4 */ |
| 863 | new_init_action(ASKFIRST, bb_default_login_shell, ""); | 871 | new_init_action(ASKFIRST, bb_default_login_shell, ""); |
| 864 | new_init_action(ASKFIRST, bb_default_login_shell, VC_2); | 872 | new_init_action(ASKFIRST, bb_default_login_shell, VC_2); |
| @@ -1039,9 +1047,9 @@ int init_main(int argc, char **argv) | |||
| 1039 | { | 1047 | { |
| 1040 | message(CONSOLE,"Low memory: forcing swapon."); | 1048 | message(CONSOLE,"Low memory: forcing swapon."); |
| 1041 | /* swapon -a requires /proc typically */ | 1049 | /* swapon -a requires /proc typically */ |
| 1042 | new_init_action(SYSINIT, "/bin/mount -t proc proc /proc", ""); | 1050 | new_init_action(SYSINIT, "mount -t proc proc /proc", ""); |
| 1043 | /* Try to turn on swap */ | 1051 | /* Try to turn on swap */ |
| 1044 | new_init_action(SYSINIT, "/sbin/swapon -a", ""); | 1052 | new_init_action(SYSINIT, "swapon -a", ""); |
| 1045 | run_actions(SYSINIT); /* wait and removing */ | 1053 | run_actions(SYSINIT); /* wait and removing */ |
| 1046 | } | 1054 | } |
| 1047 | } | 1055 | } |
| @@ -1068,7 +1076,10 @@ int init_main(int argc, char **argv) | |||
| 1068 | 1076 | ||
| 1069 | putenv("SELINUX_INIT=YES"); | 1077 | putenv("SELINUX_INIT=YES"); |
| 1070 | if (selinux_init_load_policy(&enforce) == 0) { | 1078 | if (selinux_init_load_policy(&enforce) == 0) { |
| 1071 | execv(argv[0], argv); | 1079 | char *prog = argv[0]; |
| 1080 | if (ENABLE_FEATURE_EXEC_PREFER_APPLETS && find_applet_by_name(prog)) | ||
| 1081 | prog = CONFIG_BUSYBOX_EXEC_PATH; | ||
| 1082 | execvp(prog, argv); | ||
| 1072 | } else if (enforce > 0) { | 1083 | } else if (enforce > 0) { |
| 1073 | /* SELinux in enforcing mode but load_policy failed */ | 1084 | /* SELinux in enforcing mode but load_policy failed */ |
| 1074 | /* At this point, we probably can't open /dev/console, so log() won't work */ | 1085 | /* At this point, we probably can't open /dev/console, so log() won't work */ |
