Rename two config options:
authorDenis Vlasenko <vda.linux@googlemail.com>
Tue, 10 Apr 2007 23:03:30 +0000 (23:03 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Tue, 10 Apr 2007 23:03:30 +0000 (23:03 -0000)
FEATURE_SH_STANDALONE_SHELL => FEATURE_SH_STANDALONE
FEATURE_EXEC_PREFER_APPLETS => FEATURE_PREFER_APPLETS
Make SH_STANDALONE depend on PREFER_APPLETS.
getopt.c: more randomconfig-induced fixes

17 files changed:
Config.in
TODO_config_nommu
include/applets.h
include/busybox.h
include/libbb.h
libbb/default_error_retval.c
libbb/error_msg_and_die.c
libbb/execable.c
libbb/fflush_stdout_and_exit.c
libbb/vfork_daemon_rexec.c
scripts/defconfig
shell/Config.in
shell/ash.c
shell/hush.c
shell/lash.c
shell/msh.c
util-linux/getopt.c

index 59d7d67..94ed109 100644 (file)
--- a/Config.in
+++ b/Config.in
@@ -238,7 +238,7 @@ config SELINUX
 
          Most people will leave this set to 'N'.
 
-config FEATURE_EXEC_PREFER_APPLETS
+config FEATURE_PREFER_APPLETS
        bool "exec prefers applets"
        default n
        help
@@ -462,10 +462,10 @@ config INSTALL_APPLET_HARDLINKS
 
 config INSTALL_APPLET_DONT
        bool "not installed"
-       depends on FEATURE_INSTALLER || FEATURE_SH_STANDALONE_SHELL || FEATURE_EXEC_PREFER_APPLETS
+       depends on FEATURE_INSTALLER || FEATURE_SH_STANDALONE || FEATURE_PREFER_APPLETS
        help
          Do not install applet links. Useful when using the -install feature
-         or a standalone shell for rescue pruposes.
+         or a standalone shell for rescue purposes.
 
 endchoice
 
index 695ac11..e6f6d93 100644 (file)
@@ -35,7 +35,7 @@ CONFIG_FEATURE_SYSLOG=y
 # CONFIG_FEATURE_SUID_CONFIG_QUIET is not set
 # CONFIG_FEATURE_HAVE_RPC is not set
 # CONFIG_SELINUX is not set
-# CONFIG_FEATURE_EXEC_PREFER_APPLETS is not set
+# CONFIG_FEATURE_PREFER_APPLETS is not set
 CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
 
 #
@@ -657,7 +657,7 @@ CONFIG_MSH=y
 # Bourne Shell Options
 #
 CONFIG_FEATURE_SH_EXTRA_QUIET=y
-# CONFIG_FEATURE_SH_STANDALONE_SHELL is not set
+# CONFIG_FEATURE_SH_STANDALONE is not set
 
 #
 # System Logging Utilities
index d05299b..67f7db4 100644 (file)
@@ -56,8 +56,8 @@ s     - suid type:
 # define APPLET(name,l,s)                    { #name, name##_main USE_FEATURE_INSTALLER(,l) USE_FEATURE_SUID(,s) },
 # define APPLET_NOUSAGE(name,main,l,s)       { #name, main##_main USE_FEATURE_INSTALLER(,l) USE_FEATURE_SUID(,s) },
 # define APPLET_ODDNAME(name,main,l,s,name2) { #name, main##_main USE_FEATURE_INSTALLER(,l) USE_FEATURE_SUID(,s) },
-# define APPLET_NOEXEC(name,main,l,s,name2)  { #name, main##_main USE_FEATURE_INSTALLER(,l) USE_FEATURE_SUID(,s) USE_FEATURE_EXEC_PREFER_APPLETS(,1) },
-# define APPLET_NOFORK(name,main,l,s,name2)  { #name, main##_main USE_FEATURE_INSTALLER(,l) USE_FEATURE_SUID(,s) USE_FEATURE_EXEC_PREFER_APPLETS(,1 ,1) },
+# define APPLET_NOEXEC(name,main,l,s,name2)  { #name, main##_main USE_FEATURE_INSTALLER(,l) USE_FEATURE_SUID(,s) USE_FEATURE_PREFER_APPLETS(,1) },
+# define APPLET_NOFORK(name,main,l,s,name2)  { #name, main##_main USE_FEATURE_INSTALLER(,l) USE_FEATURE_SUID(,s) USE_FEATURE_PREFER_APPLETS(,1 ,1) },
 #endif
 
 #if ENABLE_INSTALL_NO_USR
index 380de9a..290ad17 100644 (file)
@@ -37,7 +37,7 @@ struct bb_applet {
 #if ENABLE_FEATURE_SUID
        __extension__ enum bb_suid_t need_suid:8;
 #endif
-#if ENABLE_FEATURE_EXEC_PREFER_APPLETS
+#if ENABLE_FEATURE_PREFER_APPLETS
        /* true if instead if fork(); exec("applet"); waitpid();
         * one can do fork(); exit(applet_main(argc,argv)); waitpid(); */
        unsigned char noexec;
index 2be1389..04bf6a5 100644 (file)
@@ -502,7 +502,7 @@ int execable_file(const char *name);
 char *find_execable(const char *filename);
 int exists_execable(const char *filename);
 
-#if ENABLE_FEATURE_EXEC_PREFER_APPLETS
+#if ENABLE_FEATURE_PREFER_APPLETS
 int bb_execvp(const char *file, char *const argv[]);
 #define BB_EXECVP(prog,cmd) bb_execvp(prog,cmd)
 #define BB_EXECLP(prog,cmd,...) \
@@ -609,7 +609,8 @@ llist_t *llist_rev(llist_t *list);
 int write_pidfile(const char *path);
 #define remove_pidfile(f) ((void)unlink(f))
 #else
-#define write_pidfile(f)  TRUE
+/* Why? #defining it to 1 gives "warning: statement with no effect"... */
+static ATTRIBUTE_ALWAYS_INLINE int write_pidfile(const char *path) { return 1; }
 #define remove_pidfile(f) ((void)0)
 #endif
 
index f4e46a4..0b19f21 100644 (file)
@@ -13,7 +13,6 @@
  * that too seems silly.
  */
 
-#include <stdlib.h>
 #include "libbb.h"
 
 int xfunc_error_retval = EXIT_FAILURE;
index 4a90493..4115046 100644 (file)
 #include "libbb.h"
 
 int die_sleep;
-#if ENABLE_FEATURE_EXEC_PREFER_APPLETS
+#if ENABLE_FEATURE_PREFER_APPLETS
 jmp_buf die_jmp;
 #endif
 
 void xfunc_die(void)
 {
        if (die_sleep) {
-               if (ENABLE_FEATURE_EXEC_PREFER_APPLETS && die_sleep < 0) {
+               if (ENABLE_FEATURE_PREFER_APPLETS && die_sleep < 0) {
                        /* Special case. We arrive here if NOFORK applet
                         * calls xfunc, which then decides to die.
                         * We don't die, but jump instead back to caller.
index ee10c61..d843647 100644 (file)
@@ -60,7 +60,7 @@ int exists_execable(const char *filename)
        return 0;
 }
 
-#if ENABLE_FEATURE_EXEC_PREFER_APPLETS
+#if ENABLE_FEATURE_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[])
index d79827f..48889da 100644 (file)
@@ -18,7 +18,7 @@ void fflush_stdout_and_exit(int retval)
        if (fflush(stdout))
                xfunc_die();
 
-       if (ENABLE_FEATURE_EXEC_PREFER_APPLETS && die_sleep < 0) {
+       if (ENABLE_FEATURE_PREFER_APPLETS && die_sleep < 0) {
                /* We are in NOFORK applet. Do not exit() directly,
                 * but use xfunc_die() */
                xfunc_error_retval = retval;
index cf88a2b..214b645 100644 (file)
@@ -102,7 +102,7 @@ int wait_pid(int *wstat, int pid)
 
 int spawn_and_wait(char **argv)
 {
-#if ENABLE_FEATURE_EXEC_PREFER_APPLETS
+#if ENABLE_FEATURE_PREFER_APPLETS
        int rc;
        const struct bb_applet *a = find_applet_by_name(argv[0]);
 
@@ -121,8 +121,13 @@ int spawn_and_wait(char **argv)
                {
                        int old_sleep = die_sleep;
                        int old_x = xfunc_error_retval;
-                       die_sleep = -1; /* special flag */
-                       /* xfunc_die() checks for it */
+                       uint32_t old_m = option_mask32;
+
+                       xfunc_error_retval = EXIT_FAILURE;
+                       /* special flag for xfunc_die(). If xfunc will "die"
+                        * in NOFORK applet, xfunc_die() sees negative
+                        * die_sleep and longjmp here instead. */
+                       die_sleep = -1;
 
                        rc = setjmp(die_jmp);
                        if (!rc) {
@@ -144,6 +149,7 @@ int spawn_and_wait(char **argv)
 
                        die_sleep = old_sleep;
                        xfunc_error_retval = old_x;
+                       option_mask32 = old_m;
                        return rc;
                }
 #ifndef BB_NOMMU       /* MMU only */
@@ -159,7 +165,7 @@ int spawn_and_wait(char **argv)
        rc = spawn(argv);
  w:
        return wait4pid(rc);
-#else /* !FEATURE_EXEC_PREFER_APPLETS */
+#else /* !FEATURE_PREFER_APPLETS */
        return wait4pid(spawn(argv));
 #endif
 }
index 6864b2f..009026e 100644 (file)
@@ -29,7 +29,7 @@ CONFIG_FEATURE_SUID_CONFIG=y
 CONFIG_FEATURE_SUID_CONFIG_QUIET=y
 # CONFIG_FEATURE_HAVE_RPC is not set
 # CONFIG_SELINUX is not set
-# CONFIG_FEATURE_EXEC_PREFER_APPLETS is not set
+# CONFIG_FEATURE_PREFER_APPLETS is not set
 CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
 
 #
@@ -658,7 +658,7 @@ CONFIG_ASH_RANDOM_SUPPORT=y
 # Bourne Shell Options
 #
 CONFIG_FEATURE_SH_EXTRA_QUIET=y
-# CONFIG_FEATURE_SH_STANDALONE_SHELL is not set
+# CONFIG_FEATURE_SH_STANDALONE is not set
 
 #
 # System Logging Utilities
index 4b7270e..9479e3f 100644 (file)
@@ -216,10 +216,10 @@ config FEATURE_SH_EXTRA_QUIET
        help
          Remove the busybox introduction when starting a shell.
 
-config FEATURE_SH_STANDALONE_SHELL
+config FEATURE_SH_STANDALONE
        bool "Standalone shell"
        default n
-       depends on MSH || LASH || HUSH || ASH
+       depends on (MSH || LASH || HUSH || ASH) && FEATURE_PREFER_APPLETS
        help
          This option causes the selected busybox shell to use busybox applets
          in preference to executables in the PATH whenever possible.  For
index b427842..bebfec8 100644 (file)
@@ -6531,7 +6531,7 @@ tryexec(char *cmd, char **argv, char **envp)
 {
        int repeated = 0;
 
-#if ENABLE_FEATURE_SH_STANDALONE_SHELL
+#if ENABLE_FEATURE_SH_STANDALONE
        if (strchr(cmd, '/') == NULL) {
                const struct bb_applet *a;
 
@@ -6596,7 +6596,7 @@ shellexec(char **argv, const char *path, int idx)
        clearredir(1);
        envp = environment();
        if (strchr(argv[0], '/')
-#if ENABLE_FEATURE_SH_STANDALONE_SHELL
+#if ENABLE_FEATURE_SH_STANDALONE
         || find_applet_by_name(argv[0])
 #endif
        ) {
@@ -11116,7 +11116,7 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path)
                return;
        }
 
-#if ENABLE_FEATURE_SH_STANDALONE_SHELL
+#if ENABLE_FEATURE_SH_STANDALONE
        if (find_applet_by_name(name)) {
                entry->cmdtype = CMDNORMAL;
                entry->u.index = -1;
@@ -11341,7 +11341,7 @@ helpcmd(int argc, char **argv)
                        col = 0;
                }
        }
-#if ENABLE_FEATURE_SH_STANDALONE_SHELL
+#if ENABLE_FEATURE_SH_STANDALONE
        for (i = 0; i < NUM_APPLETS; i++) {
                col += out1fmt("%c%s", ((col == 0) ? '\t' : ' '), applets[i].name);
                if (col > 60) {
index 666604d..f6c69a2 100644 (file)
@@ -1112,7 +1112,7 @@ static void pseudo_exec(struct child_prog *child)
                 * really dislike relying on /proc for things.  We could exec ourself
                 * from global_argv[0], but if we are in a chroot, we may not be able
                 * to find ourself... */
-#if ENABLE_FEATURE_SH_STANDALONE_SHELL
+#if ENABLE_FEATURE_SH_STANDALONE
                {
                        int argc_l;
                        char** argv_l = child->argv;
index f9d9deb..99e2b1f 100644 (file)
@@ -1164,7 +1164,7 @@ static int pseudo_exec(struct child_prog *child)
         * /bin/foo invocation will fork and exec /bin/foo, even if
         * /bin/foo is a symlink to busybox.
         */
-       if (ENABLE_FEATURE_SH_STANDALONE_SHELL) {
+       if (ENABLE_FEATURE_SH_STANDALONE) {
                char **argv_l = child->argv;
                int argc_l;
 
index 23a7c04..0337a4f 100644 (file)
@@ -37,7 +37,7 @@
 # define DEFAULT_SHELL "/proc/self/exe"
 # define CONFIG_BUSYBOX_EXEC_PATH "/proc/self/exe"
 # define BB_BANNER "busybox standalone"
-# define ENABLE_FEATURE_SH_STANDALONE_SHELL 0
+# define ENABLE_FEATURE_SH_STANDALONE 0
 # define bb_msg_memory_exhausted "memory exhausted"
 # define xmalloc(size) malloc(size)
 # define msh_main(argc,argv) main(argc,argv)
@@ -3064,7 +3064,7 @@ static const char *rexecve(char *c, char **v, char **envp)
        int eacces = 0, asis = 0;
        char *name = c;
 
-       if (ENABLE_FEATURE_SH_STANDALONE_SHELL) {
+       if (ENABLE_FEATURE_SH_STANDALONE) {
                optind = 1;
                if (find_applet_by_name(name)) {
                        /* We have to exec here since we vforked.  Running
@@ -3195,7 +3195,7 @@ static int dohelp(struct op *t)
                }
                x++;
        }
-#if ENABLE_FEATURE_SH_STANDALONE_SHELL
+#if ENABLE_FEATURE_SH_STANDALONE
        {
                const struct bb_applet *applet = applets;
 
index 85a1d44..68e69de 100644 (file)
    mode */
 enum {
        NON_OPT = 1,
+#if ENABLE_GETOPT_LONG
 /* LONG_OPT is the code that is returned when a long option is found. */
        LONG_OPT = 2
+#endif
 };
 
 /* For finding activated option flags. Must match getopt32 call! */
@@ -51,8 +53,10 @@ enum {
        OPT_s   = 0x10, // -s
        OPT_T   = 0x20, // -T
        OPT_u   = 0x40, // -u
+#if ENABLE_GETOPT_LONG
        OPT_a   = 0x80, // -a
        OPT_l   = 0x100, // -l
+#endif
        SHELL_IS_TCSH = 0x8000, /* hijack this bit for other purposes */
 };
 
@@ -137,31 +141,45 @@ static const char *normalize(const char *arg)
  * optstr must contain the short options, and longopts the long options.
  * Other settings are found in global variables.
  */
-static int generate_output(char * argv[],int argc,const char *optstr,
-               const struct option *longopts)
+#if !ENABLE_GETOPT_LONG
+#define generate_output(argv,argc,optstr,longopts) generate_output(argv,argc,optstr)
+#endif
+static int generate_output(char **argv, int argc, const char *optstr, const struct option *longopts)
 {
        int exit_code = 0; /* We assume everything will be OK */
        unsigned opt;
+#if ENABLE_GETOPT_LONG
        int longindex;
+#endif
        const char *charptr;
 
        if (quiet_errors) /* No error reporting from getopt(3) */
                opterr = 0;
        optind = 0; /* Reset getopt(3) */
 
-       while ((opt = (alternative ?
-                       getopt_long_only(argc,argv,optstr,longopts,&longindex) :
-                       getopt_long(argc,argv,optstr,longopts,&longindex)))
-              != EOF)
+       while (1) {
+               opt =
+#if ENABLE_GETOPT_LONG
+                       alternative ?
+                       getopt_long_only(argc, argv, optstr, longopts, &longindex) :
+                       getopt_long(argc, argv, optstr, longopts, &longindex);
+#else
+                       getopt(argc, argv, optstr);
+#endif
+               if (opt == EOF)
+                       break;
                if (opt == '?' || opt == ':' )
                        exit_code = 1;
                else if (!quiet_output) {
+#if ENABLE_GETOPT_LONG
                        if (opt == LONG_OPT) {
                                printf(" --%s", longopts[longindex].name);
                                if (longopts[longindex].has_arg)
                                        printf(" %s",
                                                normalize(optarg ? optarg : ""));
-                       } else if (opt == NON_OPT)
+                       } else
+#endif
+                       if (opt == NON_OPT)
                                printf(" %s", normalize(optarg));
                        else {
                                printf(" -%c", opt);
@@ -171,6 +189,7 @@ static int generate_output(char * argv[],int argc,const char *optstr,
                                                normalize(optarg ? optarg : ""));
                        }
                }
+       }
 
        if (!quiet_output) {
                printf(" --");
@@ -181,6 +200,7 @@ static int generate_output(char * argv[],int argc,const char *optstr,
        return exit_code;
 }
 
+#if ENABLE_GETOPT_LONG
 /*
  * Register several long options. options is a string of long options,
  * separated by commas or whitespace.
@@ -224,6 +244,7 @@ static struct option *add_long_options(struct option *long_options, char *option
        }
        return long_options;
 }
+#endif
 
 static void set_shell(const char *new_shell)
 {
@@ -262,13 +283,13 @@ static const struct option longopts[] = {
 int getopt_main(int argc, char *argv[]);
 int getopt_main(int argc, char *argv[])
 {
-       struct option *long_options = NULL;
        char *optstr = NULL;
        char *name = NULL;
        unsigned opt;
        const char *compatible;
        char *s_arg; 
 #if ENABLE_GETOPT_LONG
+       struct option *long_options = NULL;
        llist_t *l_arg = NULL;
 #endif