PATCH: removing hardcoded paths from init
Gabriel L. Somlo
somlo at cmu.edu
Mon Jan 22 19:07:32 UTC 2007
Denis,
Here's another patch, that introduces BB_EXECVP and BB_EXECLP macros
in busybox.h. I've changed libbb/xfuncs.c:spawn() and init/init.c to
use it.
I think this makes the whole thing simpler and tighter.
Let me know what you think, and apply if you agree...
Thanks,
Gabriel
diff -NarU5 busybox-svn-17463.orig/include/libbb.h busybox-svn-17463/include/libbb.h
--- busybox-svn-17463.orig/include/libbb.h 2007-01-22 11:18:06.000000000 -0500
+++ busybox-svn-17463/include/libbb.h 2007-01-22 13:44:07.000000000 -0500
@@ -537,10 +537,20 @@
int execable_file(const char *name);
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)
+#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);
int inflate(int in, int out);
int bb_make_directory(char *path, long mode, int flags);
diff -NarU5 busybox-svn-17463.orig/init/init.c busybox-svn-17463/init/init.c
--- busybox-svn-17463.orig/init/init.c 2007-01-22 11:18:07.000000000 -0500
+++ busybox-svn-17463/init/init.c 2007-01-22 13:49:49.000000000 -0500
@@ -387,11 +387,10 @@
static const char press_enter[] =
#ifdef CUSTOMIZED_BANNER
#include CUSTOMIZED_BANNER
#endif
"\nPlease press Enter to activate this console. ";
- char *prog;
/* Block sigchild while forking. */
sigemptyset(&nmask);
sigaddset(&nmask, SIGCHLD);
sigprocmask(SIG_BLOCK, &nmask, &omask);
@@ -559,14 +558,11 @@
}
#endif
/* Now run it. The new program will take over this PID,
* so nothing further in init.c should be run. */
- prog = cmdpath;
- if (ENABLE_FEATURE_EXEC_PREFER_APPLETS && find_applet_by_name(prog))
- prog = CONFIG_BUSYBOX_EXEC_PATH;
- execvp(prog, cmd);
+ BB_EXECVP(cmdpath, cmd);
/* We're still here? Some error happened. */
message(LOG | CONSOLE, "Bummer, cannot run '%s': %m", cmdpath);
_exit(-1);
}
@@ -680,11 +676,10 @@
static void exec_signal(int sig ATTRIBUTE_UNUSED)
{
struct init_action *a, *tmp;
sigset_t unblock_signals;
- char *prog;
for (a = init_action_list; a; a = tmp) {
tmp = a->next;
if (a->action & RESTART) {
shutdown_system();
@@ -716,14 +711,11 @@
/* Setup stdout, stderr on the supplied terminal */
dup(0);
dup(0);
messageD(CONSOLE | LOG, "Trying to re-exec %s", a->command);
- prog = a->command;
- if (ENABLE_FEATURE_EXEC_PREFER_APPLETS && find_applet_by_name(prog))
- prog = CONFIG_BUSYBOX_EXEC_PATH;
- execlp(prog, a->command, NULL);
+ BB_EXECLP(a->command, a->command, NULL);
message(CONSOLE | LOG, "exec of '%s' failed: %m",
a->command);
sync();
sleep(2);
@@ -1074,14 +1066,11 @@
if (getenv("SELINUX_INIT") == NULL) {
int enforce = 0;
putenv("SELINUX_INIT=YES");
if (selinux_init_load_policy(&enforce) == 0) {
- char *prog = argv[0];
- if (ENABLE_FEATURE_EXEC_PREFER_APPLETS && find_applet_by_name(prog))
- prog = CONFIG_BUSYBOX_EXEC_PATH;
- execvp(prog, argv);
+ BB_EXECVP(argv[0], argv);
} else if (enforce > 0) {
/* SELinux in enforcing mode but load_policy failed */
/* At this point, we probably can't open /dev/console, so log() won't work */
message(CONSOLE,"Unable to load SELinux Policy. Machine is in enforcing mode. Halting now.");
exit(1);
diff -NarU5 busybox-svn-17463.orig/libbb/xfuncs.c busybox-svn-17463/libbb/xfuncs.c
--- busybox-svn-17463.orig/libbb/xfuncs.c 2007-01-22 11:18:04.000000000 -0500
+++ busybox-svn-17463/libbb/xfuncs.c 2007-01-22 13:50:12.000000000 -0500
@@ -181,21 +181,17 @@
pid_t spawn(char **argv)
{
/* Why static? */
static int failed;
pid_t pid;
- char *prog;
// Be nice to nommu machines.
failed = 0;
pid = vfork();
if (pid < 0) return pid;
if (!pid) {
- prog = argv[0];
- if (ENABLE_FEATURE_EXEC_PREFER_APPLETS && find_applet_by_name(prog))
- prog = CONFIG_BUSYBOX_EXEC_PATH;
- execvp(prog, argv);
+ BB_EXECVP(argv[0], argv);
// 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
// would screw up parent.)
More information about the busybox
mailing list