aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-02-03 02:17:41 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-02-03 02:17:41 +0000
commit4921b54f37125a58d5ea1a8aac886ae781517bc1 (patch)
treed8a989b6b3c29db835d3ec3084b908b6199d91dc
parent0aa84906936bd99ea8627a24b8ad2fdeedc7e928 (diff)
downloadbusybox-w32-4921b54f37125a58d5ea1a8aac886ae781517bc1.tar.gz
busybox-w32-4921b54f37125a58d5ea1a8aac886ae781517bc1.tar.bz2
busybox-w32-4921b54f37125a58d5ea1a8aac886ae781517bc1.zip
Add BB_EXEC[LV]P() which encapsulate FEATURE_EXEC_PREFER_APPLETS
(patch from Gabriel L. Somlo <somlo@cmu.edu>)
-rw-r--r--include/libbb.h10
-rw-r--r--init/init.c17
-rw-r--r--libbb/xfuncs.c6
3 files changed, 14 insertions, 19 deletions
diff --git a/include/libbb.h b/include/libbb.h
index ed1c41a02..85afdf20a 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -551,6 +551,16 @@ int execable_file(const char *name);
551char *find_execable(const char *filename); 551char *find_execable(const char *filename);
552int exists_execable(const char *filename); 552int exists_execable(const char *filename);
553 553
554#ifdef ENABLE_FEATURE_EXEC_PREFER_APPLETS
555#define BB_EXECVP(prog,cmd) \
556 execvp((find_applet_by_name(prog)) ? CONFIG_BUSYBOX_EXEC_PATH : prog, cmd)
557#define BB_EXECLP(prog,cmd,...) \
558 execlp((find_applet_by_name(prog)) ? CONFIG_BUSYBOX_EXEC_PATH : prog, cmd, __VA_ARGS__)
559#else
560#define BB_EXECVP(prog,cmd) execvp(prog,cmd)
561#define BB_EXECLP(prog,cmd,...) execvp(prog,cmd, __VA_ARGS__)
562#endif
563
554USE_DESKTOP(long long) int uncompress(int fd_in, int fd_out); 564USE_DESKTOP(long long) int uncompress(int fd_in, int fd_out);
555int inflate(int in, int out); 565int inflate(int in, int out);
556 566
diff --git a/init/init.c b/init/init.c
index cb314003e..110af8566 100644
--- a/init/init.c
+++ b/init/init.c
@@ -389,7 +389,6 @@ 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 const char *prog;
393 392
394 /* Block sigchild while forking. */ 393 /* Block sigchild while forking. */
395 sigemptyset(&nmask); 394 sigemptyset(&nmask);
@@ -561,10 +560,7 @@ static pid_t run(const struct init_action *a)
561 560
562 /* Now run it. The new program will take over this PID, 561 /* Now run it. The new program will take over this PID,
563 * so nothing further in init.c should be run. */ 562 * so nothing further in init.c should be run. */
564 prog = cmdpath; 563 BB_EXECVP(cmdpath, cmd);
565 if (ENABLE_FEATURE_EXEC_PREFER_APPLETS && find_applet_by_name(prog))
566 prog = CONFIG_BUSYBOX_EXEC_PATH;
567 execvp(prog, cmd);
568 564
569 /* We're still here? Some error happened. */ 565 /* We're still here? Some error happened. */
570 message(LOG | CONSOLE, "Bummer, cannot run '%s': %m", cmdpath); 566 message(LOG | CONSOLE, "Bummer, cannot run '%s': %m", cmdpath);
@@ -682,7 +678,6 @@ static void exec_signal(int sig ATTRIBUTE_UNUSED)
682{ 678{
683 struct init_action *a, *tmp; 679 struct init_action *a, *tmp;
684 sigset_t unblock_signals; 680 sigset_t unblock_signals;
685 char *prog;
686 681
687 for (a = init_action_list; a; a = tmp) { 682 for (a = init_action_list; a; a = tmp) {
688 tmp = a->next; 683 tmp = a->next;
@@ -718,10 +713,7 @@ static void exec_signal(int sig ATTRIBUTE_UNUSED)
718 dup(0); 713 dup(0);
719 714
720 messageD(CONSOLE | LOG, "Trying to re-exec %s", a->command); 715 messageD(CONSOLE | LOG, "Trying to re-exec %s", a->command);
721 prog = a->command; 716 BB_EXECLP(a->command, a->command, NULL);
722 if (ENABLE_FEATURE_EXEC_PREFER_APPLETS && find_applet_by_name(prog))
723 prog = CONFIG_BUSYBOX_EXEC_PATH;
724 execlp(prog, a->command, NULL);
725 717
726 message(CONSOLE | LOG, "exec of '%s' failed: %m", 718 message(CONSOLE | LOG, "exec of '%s' failed: %m",
727 a->command); 719 a->command);
@@ -1076,10 +1068,7 @@ int init_main(int argc, char **argv)
1076 1068
1077 putenv("SELINUX_INIT=YES"); 1069 putenv("SELINUX_INIT=YES");
1078 if (selinux_init_load_policy(&enforce) == 0) { 1070 if (selinux_init_load_policy(&enforce) == 0) {
1079 char *prog = argv[0]; 1071 BB_EXECVP(argv[0], argv);
1080 if (ENABLE_FEATURE_EXEC_PREFER_APPLETS && find_applet_by_name(prog))
1081 prog = CONFIG_BUSYBOX_EXEC_PATH;
1082 execvp(prog, argv);
1083 } else if (enforce > 0) { 1072 } else if (enforce > 0) {
1084 /* SELinux in enforcing mode but load_policy failed */ 1073 /* SELinux in enforcing mode but load_policy failed */
1085 /* At this point, we probably can't open /dev/console, so log() won't work */ 1074 /* At this point, we probably can't open /dev/console, so log() won't work */
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index 601ff3f7e..3cbb0d3eb 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -184,17 +184,13 @@ pid_t spawn(char **argv)
184 /* Why static? */ 184 /* Why static? */
185 static int failed; 185 static int failed;
186 pid_t pid; 186 pid_t pid;
187 const char *prog;
188 187
189 // Be nice to nommu machines. 188 // Be nice to nommu machines.
190 failed = 0; 189 failed = 0;
191 pid = vfork(); 190 pid = vfork();
192 if (pid < 0) return pid; 191 if (pid < 0) return pid;
193 if (!pid) { 192 if (!pid) {
194 prog = argv[0]; 193 BB_EXECVP(argv[0], argv);
195 if (ENABLE_FEATURE_EXEC_PREFER_APPLETS && find_applet_by_name(prog))
196 prog = CONFIG_BUSYBOX_EXEC_PATH;
197 execvp(prog, argv);
198 194
199 // We're sharing a stack with blocked parent, let parent know we failed 195 // We're sharing a stack with blocked parent, let parent know we failed
200 // and then exit to unblock parent (but don't run atexit() stuff, which 196 // and then exit to unblock parent (but don't run atexit() stuff, which