From 8f0af3b0013156b8aa3bae802af5e33c3a440915 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 29 Nov 2010 02:55:35 +0100 Subject: if only one applet is enabled, make "busybox applet [params]" work as expected Signed-off-by: Denys Vlasenko --- libbb/appletlib.c | 62 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 29 deletions(-) (limited to 'libbb/appletlib.c') diff --git a/libbb/appletlib.c b/libbb/appletlib.c index c417a270d..c65180c5e 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -227,7 +227,7 @@ bool re_execed; IF_FEATURE_SUID(static uid_t ruid;) /* real uid */ -#if ENABLE_FEATURE_SUID_CONFIG +# if ENABLE_FEATURE_SUID_CONFIG /* applets[] is const, so we have to define this "override" structure */ static struct BB_suid_config { @@ -498,15 +498,15 @@ static void parse_config_file(void) sct_head = sct; } } -#else +# else static inline void parse_config_file(void) { IF_FEATURE_SUID(ruid = getuid();) } -#endif /* FEATURE_SUID_CONFIG */ +# endif /* FEATURE_SUID_CONFIG */ -#if ENABLE_FEATURE_SUID +# if ENABLE_FEATURE_SUID static void check_suid(int applet_no) { gid_t rgid; /* real gid */ @@ -515,7 +515,7 @@ static void check_suid(int applet_no) return; /* run by root - no need to check more */ rgid = getgid(); -#if ENABLE_FEATURE_SUID_CONFIG +# if ENABLE_FEATURE_SUID_CONFIG if (suid_cfg_readable) { uid_t uid; struct BB_suid_config *sct; @@ -558,7 +558,7 @@ static void check_suid(int applet_no) bb_perror_msg_and_die("setresuid"); return; } -#if !ENABLE_FEATURE_SUID_CONFIG_QUIET +# if !ENABLE_FEATURE_SUID_CONFIG_QUIET { static bool onetime = 0; @@ -567,9 +567,9 @@ static void check_suid(int applet_no) fprintf(stderr, "Using fallback suid method\n"); } } -#endif +# endif check_need_suid: -#endif +# endif if (APPLET_SUID(applet_no) == _BB_SUID_REQUIRE) { /* Real uid is not 0. If euid isn't 0 too, suid bit * is most probably not set on our executable */ @@ -580,25 +580,24 @@ static void check_suid(int applet_no) xsetuid(ruid); } } -#else -#define check_suid(x) ((void)0) -#endif /* FEATURE_SUID */ +# else +# define check_suid(x) ((void)0) +# endif /* FEATURE_SUID */ -#if ENABLE_FEATURE_INSTALLER +# if ENABLE_FEATURE_INSTALLER static const char usr_bin [] ALIGN1 = "/usr/bin/"; static const char usr_sbin[] ALIGN1 = "/usr/sbin/"; static const char *const install_dir[] = { &usr_bin [8], /* "/" */ &usr_bin [4], /* "/bin/" */ &usr_sbin[4] /* "/sbin/" */ -# if !ENABLE_INSTALL_NO_USR +# if !ENABLE_INSTALL_NO_USR ,usr_bin ,usr_sbin -# endif +# endif }; - /* create (sym)links for each applet */ static void install_links(const char *busybox, int use_symbolic_links, char *custom_install_dir) @@ -628,9 +627,9 @@ static void install_links(const char *busybox, int use_symbolic_links, free(fpc); } } -#else -# define install_links(x,y,z) ((void)0) -#endif +# else +# define install_links(x,y,z) ((void)0) +# endif /* If we were called as "busybox..." */ static int busybox_main(char **argv) @@ -695,10 +694,10 @@ static int busybox_main(char **argv) const char *a = applet_names; dup2(1, 2); while (*a) { -#if ENABLE_FEATURE_INSTALLER +# if ENABLE_FEATURE_INSTALLER if (argv[1][6]) /* --list-path? */ full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1); -#endif +# endif full_write2_str(a); full_write2_str("\n"); i++; @@ -771,7 +770,7 @@ void FAST_FUNC run_applet_and_exit(const char *name, char **argv) int applet = find_applet_by_name(name); if (applet >= 0) run_applet_no_and_exit(applet, argv); - if (!strncmp(name, "busybox", 7)) + if (strncmp(name, "busybox", 7) == 0) exit(busybox_main(argv)); } @@ -803,14 +802,6 @@ int main(int argc UNUSED_PARAM, char **argv) mallopt(M_MMAP_THRESHOLD, 8 * PAGE_SIZE - 256); #endif -#if defined(SINGLE_APPLET_MAIN) - /* Only one applet is selected by the user! */ - /* applet_names in this case is just "applet\0\0" */ - lbb_prepare(applet_names IF_FEATURE_INDIVIDUAL(, argv)); - return SINGLE_APPLET_MAIN(argc, argv); -#else - lbb_prepare("busybox" IF_FEATURE_INDIVIDUAL(, argv)); - #if !BB_MMU /* NOMMU re-exec trick sets high-order bit in first byte of name */ if (argv[0][0] & 0x80) { @@ -818,6 +809,19 @@ int main(int argc UNUSED_PARAM, char **argv) argv[0][0] &= 0x7f; } #endif + +#if defined(SINGLE_APPLET_MAIN) + /* Only one applet is selected in .config */ + if (strncmp(argv[0], "busybox", 7) == 0) { + /* "busybox " should still work as expected */ + argv++; + } + /* applet_names in this case is just "applet\0\0" */ + lbb_prepare(applet_names IF_FEATURE_INDIVIDUAL(, argv)); + return SINGLE_APPLET_MAIN(argc, argv); +#else + lbb_prepare("busybox" IF_FEATURE_INDIVIDUAL(, argv)); + applet_name = argv[0]; if (applet_name[0] == '-') applet_name++; -- cgit v1.2.3