EXEC_PREFER_APPLETS support by Gabriel L. Somlo <somlo@cmu.edu>
authorDenis Vlasenko <vda.linux@googlemail.com>
Tue, 6 Feb 2007 01:20:12 +0000 (01:20 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Tue, 6 Feb 2007 01:20:12 +0000 (01:20 -0000)
22 files changed:
archival/tar.c
console-tools/openvt.c
coreutils/chroot.c
coreutils/env.c
coreutils/install.c
coreutils/nice.c
coreutils/nohup.c
e2fsprogs/fsck.c
findutils/xargs.c
include/libbb.h
libbb/execable.c
loginutils/adduser.c
loginutils/login.c
miscutils/devfsd.c
miscutils/setsid.c
miscutils/taskset.c
miscutils/time.c
networking/ifupdown.c
networking/nc.c
runit/chpst.c
runit/runsvdir.c
util-linux/setarch.c

index 48c4f3f8cacc17e6d6aeadb3319d164a5e15f036..d8e36749e5a4c375eeb0ca899624a3868dd3bda5 100644 (file)
@@ -529,7 +529,7 @@ static int writeTarFile(const int tar_fd, const int verboseFlag,
                        close(gzipStatusPipe[0]);
                        fcntl(gzipStatusPipe[1], F_SETFD, FD_CLOEXEC);  /* close on exec shows success */
 
-                       execlp(zip_exec, zip_exec, "-f", NULL);
+                       BB_EXECLP(zip_exec, zip_exec, "-f", NULL);
                        vfork_exec_errno = errno;
 
                        close(gzipStatusPipe[1]);
index 9296219bd22d7d68dc6ac11931f4d42a35e18487..eb9f49fe25931091dccbe42faf81d62030186022 100644 (file)
@@ -36,7 +36,7 @@ int openvt_main(int argc, char **argv)
                dup2(fd, STDERR_FILENO);
                while (fd > 2) close(fd--);
 
-               execvp(argv[2], &argv[2]);
+               BB_EXECVP(argv[2], &argv[2]);
                _exit(1);
        }
        return EXIT_SUCCESS;
index 16c743fef37e0172e0a28e9c93e80c44a70b0411..fcd70f21a8bcfe9e07f3f449c592cde17ba96527 100644 (file)
@@ -33,6 +33,6 @@ int chroot_main(int argc, char **argv)
                argv[1] = (char *) "-i";
        }
 
-       execvp(*argv, argv);
+       BB_EXECVP(*argv, argv);
        bb_perror_msg_and_die("cannot execute %s", *argv);
 }
index 04279f3e00fbf25424c1a34fec533f5cb4e9fc97..7be0c63a531be4155736aeb3e31f8d86e30060b5 100644 (file)
@@ -81,7 +81,7 @@ int env_main(int argc, char** argv)
        }
 
        if (*argv) {
-               execvp(*argv, argv);
+               BB_EXECVP(*argv, argv);
                /* SUSv3-mandated exit codes. */
                xfunc_error_retval = (errno == ENOENT) ? 127 : 126;
                bb_perror_msg_and_die("%s", *argv);
index dd73fb693cc57b750e8337fe2f96c9e6a8cd508f..c105addc54bf0b1e66ceb79c8325351f1cda6553 100644 (file)
@@ -126,7 +126,7 @@ int install_main(int argc, char **argv)
                        ret = EXIT_FAILURE;
                }
                if (flags & OPT_STRIP) {
-                       if (execlp("strip", "strip", dest, NULL) == -1) {
+                       if (BB_EXECLP("strip", "strip", dest, NULL) == -1) {
                                bb_perror_msg("strip");
                                ret = EXIT_FAILURE;
                        }
index b7bff6a520c9abe2533878706255878be0d49321..3285315288ffba71db6eb985fc50d2cbc19f0599 100644 (file)
@@ -47,7 +47,7 @@ int nice_main(int argc, char **argv)
                }
        }
 
-       execvp(*argv, argv);            /* Now exec the desired program. */
+       BB_EXECVP(*argv, argv);         /* Now exec the desired program. */
 
        /* The exec failed... */
        xfunc_error_retval = (errno == ENOENT) ? 127 : 126; /* SUSv3 */
index a9944b7f49311f40199c9c83ff567ce9508adcbf..6a6c70e13dc291ae02b569dbec907a6557007017 100644 (file)
@@ -53,7 +53,7 @@ int nohup_main(int argc, char **argv)
                close(nullfd);
        signal(SIGHUP, SIG_IGN);
 
-       execvp(argv[1], argv+1);
+       BB_EXECVP(argv[1], argv+1);
        if (ENABLE_FEATURE_CLEAN_UP && home)
                free((char*)nohupout);
        bb_perror_msg_and_die("%s", argv[1]);
index 9ec31d2a3b43f4c7fe41819c3e68eed95c2a4685..ad22fcd7a8b522e0b1411e0620ad378483273f34 100644 (file)
@@ -677,7 +677,7 @@ static void execute(const char *type, const char *device, const char *mntpt,
                                 * Use "fsck -s" to avoid... */
                                close(0);
                        }
-                       execvp(argv[0], argv);
+                       BB_EXECVP(argv[0], argv);
                        bb_perror_msg_and_die("%s", argv[0]);
                }
        }
index c2060f804ef0549f7e955094f2199308d9f42e7e..44dbcdad0ea7419fb6d65099f70e8ff75593b2c1 100644 (file)
@@ -60,7 +60,7 @@ static int xargs_exec(char *const *args)
 
        if (p == 0) {
                /* vfork -- child */
-               execvp(args[0], args);
+               BB_EXECVP(args[0], args);
                exec_errno = errno;     /* set error to shared stack */
                _exit(1);
        }
index 7342f89f6de64172300f666a0127238ee9f3cede..babb39ba94f511cb64e36f887649c50b12ca21c7 100644 (file)
@@ -562,12 +562,13 @@ char *find_execable(const char *filename);
 int exists_execable(const char *filename);
 
 #ifdef ENABLE_FEATURE_EXEC_PREFER_APPLETS
-#define BB_EXECVP(prog,cmd) \
-       execvp((find_applet_by_name(prog)) ? CONFIG_BUSYBOX_EXEC_PATH : prog, cmd)
+int bb_execvp(const char *file, char *const argv[]);
+#define BB_EXECVP(prog,cmd) bb_execvp(prog,cmd)
 #define BB_EXECLP(prog,cmd,...) \
-       execlp((find_applet_by_name(prog)) ? CONFIG_BUSYBOX_EXEC_PATH : prog, cmd, __VA_ARGS__)
+       execlp((find_applet_by_name(prog)) ? CONFIG_BUSYBOX_EXEC_PATH : prog, \
+               cmd, __VA_ARGS__)
 #else
-#define BB_EXECVP(prog,cmd) execvp(prog,cmd)
+#define BB_EXECVP(prog,cmd)     execvp(prog,cmd)
 #define BB_EXECLP(prog,cmd,...) execlp(prog,cmd, __VA_ARGS__) 
 #endif
 
index 817c067369adfcfdd1f7b6ff413f765c9f629819..601c7539e6df7e1151461779bbca2ca24ecbf719 100644 (file)
@@ -59,3 +59,13 @@ int exists_execable(const char *filename)
        }
        return 0;
 }
+
+#ifdef ENABLE_FEATURE_EXEC_PREFER_APPLETS
+/* just like the real execvp, but try to launch an applet named 'file' first
+ */
+int bb_execvp(const char *file, char *const argv[])
+{
+       return execvp(find_applet_by_name(file) ? CONFIG_BUSYBOX_EXEC_PATH : file,
+                                       argv);
+}
+#endif
index 8193aea82ed39eddffb9f5eb7ba026d5a5047541..b6d0c62ea864f44018b46fe89aa9f895461ea539 100644 (file)
@@ -80,7 +80,7 @@ static void passwd_wrapper(const char *login) ATTRIBUTE_NORETURN;
 static void passwd_wrapper(const char *login)
 {
        static const char prog[] = "passwd";
-       execlp(prog, prog, login, NULL);
+       BB_EXECLP(prog, prog, login, NULL);
        bb_error_msg_and_die("failed to execute '%s', you must set the password for '%s' manually", prog, login);
 }
 
index a19191b8c3a86016b5375be1c912d3facd09a69b..830df0a7feb539612ac1120eb2b01b3962257899 100644 (file)
@@ -357,7 +357,7 @@ auth_failed:
                                setenv("LOGIN_UID", utoa(pw->pw_uid), 1);
                                setenv("LOGIN_GID", utoa(pw->pw_gid), 1);
                                setenv("LOGIN_SHELL", pw->pw_shell, 1);
-                               execvp(script, t_argv);
+                               BB_EXECVP(script, t_argv);
                                exit(1);
                        default: /* parent */
                                wait(NULL);
index 69c698781c5f1d69ab93883e1638670a31206f40..96c172cb8d37ce1b3a7f599afca9b8727edaed79 100644 (file)
@@ -378,7 +378,7 @@ static void fork_and_execute(int die, char *arg0, char **arg )
         /* Child : if arg0 != NULL do execvp */
        if(arg0 != NULL )
        {
-               execvp (arg0, arg);
+               BB_EXECVP(arg0, arg);
                msg_logger_and_die(LOG_ERR, "execvp");
        }
 }
index b4d5ced468b299e5ef13a4c29a83e96db2d51869..6db07be5f51a12425f0811ce97c4ae5be83122f9 100644 (file)
@@ -36,7 +36,7 @@ int setsid_main(int argc, char *argv[])
 
        setsid();  /* no error possible */
 
-       execvp(argv[1], argv + 1);
+       BB_EXECVP(argv[1], argv + 1);
 
        bb_perror_msg_and_die("%s", argv[1]);
 }
index cf6a8be99a1413ec7a7ae41b9c1a0f751dfd4c7e..b3bf4902ece3071adc7700190e89adea01beedb2 100644 (file)
@@ -91,7 +91,7 @@ int taskset_main(int argc, char** argv)
                goto print_aff;
        }
        ++argv;
-       execvp(*argv, argv);
+       BB_EXECVP(*argv, argv);
        bb_perror_msg_and_die("%s", *argv);
 }
 #undef OPT_p
index 56f1d4ab89cdeed2789b4d393f5f4f1d91154975..a4591950250ffc3a81633aaadcf44e48ecf7e8a3 100644 (file)
@@ -410,7 +410,7 @@ static void run_command(char *const *cmd, resource_t * resp)
        else if (pid == 0) {    /* If child.  */
                /* Don't cast execvp arguments; that causes errors on some systems,
                   versus merely warnings if the cast is left off.  */
-               execvp(cmd[0], cmd);
+               BB_EXECVP(cmd[0], cmd);
                bb_error_msg("cannot run %s", cmd[0]);
                _exit(errno == ENOENT ? 127 : 126);
        }
index ce3b9bab7ee21566f38f402a78b2070d7c9595a6..ccebecd951f5af817eb77084fcd173ac08eb078a 100644 (file)
@@ -1004,7 +1004,7 @@ static int popen2(FILE **in, FILE **out, char *command, ...)
                close(infd[1]);
                close(outfd[0]);
                close(outfd[1]);
-               execvp(command, argv);
+               BB_EXECVP(command, argv);
                exit(127);
        default:                        /* parent */
                *in = fdopen(infd[1], "w");
index c1e881162528201461e3db001fe9a4e3908bee92..1bdecaf5eb8018092deeddf1a773aabe8abce445 100644 (file)
@@ -149,7 +149,7 @@ int nc_main(int argc, char **argv)
                }
                dup2(0, 1);
                dup2(0, 2);
-               USE_NC_EXTRA(execvp(execparam[0], execparam);)
+               USE_NC_EXTRA(BB_EXECVP(execparam[0], execparam);)
                /* Don't print stuff or it will go over the wire.... */
                _exit(127);
        }
index 053051d1de3541842a1162ef9d033be1b1c9cde7..7b907845f138eda15270fa98feade8d6359447f2 100644 (file)
@@ -310,7 +310,7 @@ int chpst_main(int argc, char **argv)
        if (OPT_nostdin) close(0);
        if (OPT_nostdout) close(1);
        if (OPT_nostderr) close(2);
-       execvp(argv[0], argv);
+       BB_EXECVP(argv[0], argv);
        bb_perror_msg_and_die("exec %s", argv[0]);
 }
 
@@ -322,7 +322,7 @@ static void setuidgid(int argc, char **argv)
        if (!account) bb_show_usage();
        if (!*++argv) bb_show_usage();
        suidgid((char*)account);
-       execvp(argv[0], argv);
+       BB_EXECVP(argv[0], argv);
        bb_perror_msg_and_die("exec %s", argv[0]);
 }
 
@@ -334,7 +334,7 @@ static void envuidgid(int argc, char **argv)
        if (!account) bb_show_usage();
        if (!*++argv) bb_show_usage();
        euidgid((char*)account);
-       execvp(argv[0], argv);
+       BB_EXECVP(argv[0], argv);
        bb_perror_msg_and_die("exec %s", argv[0]);
 }
 
@@ -346,7 +346,7 @@ static void envdir(int argc, char **argv)
        if (!dir) bb_show_usage();
        if (!*++argv) bb_show_usage();
        edir(dir);
-       execvp(argv[0], argv);
+       BB_EXECVP(argv[0], argv);
        bb_perror_msg_and_die("exec %s", argv[0]);
 }
 
@@ -369,6 +369,6 @@ static void softlimit(int argc, char **argv)
        argv += optind;
        if (!argv[0]) bb_show_usage();
        slimit();
-       execvp(argv[0], argv);
+       BB_EXECVP(argv[0], argv);
        bb_perror_msg_and_die("exec %s", argv[0]);
 }
index d9053ad6a4fc5bb20e5dba41b26d5c870c8c7f13..2d2b5db3147b5c7ef9ae2df9c88019da10966e36 100644 (file)
@@ -73,7 +73,7 @@ static void runsv(int no, const char *name)
                sig_uncatch(SIGHUP);
                sig_uncatch(SIGTERM);
                if (pgrp) setsid();
-               execvp(prog[0], prog);
+               BB_EXECVP(prog[0], prog);
                //pathexec_run(*prog, prog, (char* const*)environ);
                fatal2_cannot("start runsv ", name);
        }
index 8f4e308d406bd664741130bf686702157e9efe46..a7a45ec4d5d0d8f6ccd38964d65a02e29183d8d0 100644 (file)
@@ -46,7 +46,7 @@ retry:
        if (personality(pers) >= 0) {
 
                /* Try to execute the program */
-               execvp(argv[0], argv);
+               BB_EXECVP(argv[0], argv);
        }
 
        bb_perror_msg_and_die("%s", argv[0]);