Add BB_EXEC[LV]P() which encapsulate FEATURE_EXEC_PREFER_APPLETS
(patch from Gabriel L. Somlo <somlo@cmu.edu>)
This commit is contained in:
parent
0aa8490693
commit
4921b54f37
@ -551,6 +551,16 @@ int execable_file(const char *name);
|
|||||||
char *find_execable(const char *filename);
|
char *find_execable(const char *filename);
|
||||||
int exists_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)
|
||||||
|
#define BB_EXECLP(prog,cmd,...) \
|
||||||
|
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_EXECLP(prog,cmd,...) execvp(prog,cmd, __VA_ARGS__)
|
||||||
|
#endif
|
||||||
|
|
||||||
USE_DESKTOP(long long) int uncompress(int fd_in, int fd_out);
|
USE_DESKTOP(long long) int uncompress(int fd_in, int fd_out);
|
||||||
int inflate(int in, int out);
|
int inflate(int in, int out);
|
||||||
|
|
||||||
|
17
init/init.c
17
init/init.c
@ -389,7 +389,6 @@ static pid_t run(const struct init_action *a)
|
|||||||
#include CUSTOMIZED_BANNER
|
#include CUSTOMIZED_BANNER
|
||||||
#endif
|
#endif
|
||||||
"\nPlease press Enter to activate this console. ";
|
"\nPlease press Enter to activate this console. ";
|
||||||
const char *prog;
|
|
||||||
|
|
||||||
/* Block sigchild while forking. */
|
/* Block sigchild while forking. */
|
||||||
sigemptyset(&nmask);
|
sigemptyset(&nmask);
|
||||||
@ -561,10 +560,7 @@ static pid_t run(const struct init_action *a)
|
|||||||
|
|
||||||
/* Now run it. The new program will take over this PID,
|
/* Now run it. The new program will take over this PID,
|
||||||
* so nothing further in init.c should be run. */
|
* so nothing further in init.c should be run. */
|
||||||
prog = cmdpath;
|
BB_EXECVP(cmdpath, cmd);
|
||||||
if (ENABLE_FEATURE_EXEC_PREFER_APPLETS && find_applet_by_name(prog))
|
|
||||||
prog = CONFIG_BUSYBOX_EXEC_PATH;
|
|
||||||
execvp(prog, cmd);
|
|
||||||
|
|
||||||
/* We're still here? Some error happened. */
|
/* We're still here? Some error happened. */
|
||||||
message(LOG | CONSOLE, "Bummer, cannot run '%s': %m", cmdpath);
|
message(LOG | CONSOLE, "Bummer, cannot run '%s': %m", cmdpath);
|
||||||
@ -682,7 +678,6 @@ static void exec_signal(int sig ATTRIBUTE_UNUSED)
|
|||||||
{
|
{
|
||||||
struct init_action *a, *tmp;
|
struct init_action *a, *tmp;
|
||||||
sigset_t unblock_signals;
|
sigset_t unblock_signals;
|
||||||
char *prog;
|
|
||||||
|
|
||||||
for (a = init_action_list; a; a = tmp) {
|
for (a = init_action_list; a; a = tmp) {
|
||||||
tmp = a->next;
|
tmp = a->next;
|
||||||
@ -718,10 +713,7 @@ static void exec_signal(int sig ATTRIBUTE_UNUSED)
|
|||||||
dup(0);
|
dup(0);
|
||||||
|
|
||||||
messageD(CONSOLE | LOG, "Trying to re-exec %s", a->command);
|
messageD(CONSOLE | LOG, "Trying to re-exec %s", a->command);
|
||||||
prog = a->command;
|
BB_EXECLP(a->command, a->command, NULL);
|
||||||
if (ENABLE_FEATURE_EXEC_PREFER_APPLETS && find_applet_by_name(prog))
|
|
||||||
prog = CONFIG_BUSYBOX_EXEC_PATH;
|
|
||||||
execlp(prog, a->command, NULL);
|
|
||||||
|
|
||||||
message(CONSOLE | LOG, "exec of '%s' failed: %m",
|
message(CONSOLE | LOG, "exec of '%s' failed: %m",
|
||||||
a->command);
|
a->command);
|
||||||
@ -1076,10 +1068,7 @@ int init_main(int argc, char **argv)
|
|||||||
|
|
||||||
putenv("SELINUX_INIT=YES");
|
putenv("SELINUX_INIT=YES");
|
||||||
if (selinux_init_load_policy(&enforce) == 0) {
|
if (selinux_init_load_policy(&enforce) == 0) {
|
||||||
char *prog = argv[0];
|
BB_EXECVP(argv[0], argv);
|
||||||
if (ENABLE_FEATURE_EXEC_PREFER_APPLETS && find_applet_by_name(prog))
|
|
||||||
prog = CONFIG_BUSYBOX_EXEC_PATH;
|
|
||||||
execvp(prog, argv);
|
|
||||||
} else if (enforce > 0) {
|
} else if (enforce > 0) {
|
||||||
/* SELinux in enforcing mode but load_policy failed */
|
/* SELinux in enforcing mode but load_policy failed */
|
||||||
/* At this point, we probably can't open /dev/console, so log() won't work */
|
/* At this point, we probably can't open /dev/console, so log() won't work */
|
||||||
|
@ -184,17 +184,13 @@ pid_t spawn(char **argv)
|
|||||||
/* Why static? */
|
/* Why static? */
|
||||||
static int failed;
|
static int failed;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
const char *prog;
|
|
||||||
|
|
||||||
// Be nice to nommu machines.
|
// Be nice to nommu machines.
|
||||||
failed = 0;
|
failed = 0;
|
||||||
pid = vfork();
|
pid = vfork();
|
||||||
if (pid < 0) return pid;
|
if (pid < 0) return pid;
|
||||||
if (!pid) {
|
if (!pid) {
|
||||||
prog = argv[0];
|
BB_EXECVP(argv[0], argv);
|
||||||
if (ENABLE_FEATURE_EXEC_PREFER_APPLETS && find_applet_by_name(prog))
|
|
||||||
prog = CONFIG_BUSYBOX_EXEC_PATH;
|
|
||||||
execvp(prog, argv);
|
|
||||||
|
|
||||||
// We're sharing a stack with blocked parent, let parent know we failed
|
// We're sharing a stack with blocked parent, let parent know we failed
|
||||||
// and then exit to unblock parent (but don't run atexit() stuff, which
|
// and then exit to unblock parent (but don't run atexit() stuff, which
|
||||||
|
Loading…
x
Reference in New Issue
Block a user