stop using __u32 etc. uint32_t is there for a reason
[oweals/busybox.git] / shell / ash.c
index ae5182ad133810b676addd8339f13a0de3a77943..6d96bce5aefb48288d9449017d6a36f83a07ffde 100644 (file)
@@ -85,7 +85,7 @@
 #ifdef CONFIG_ASH_JOB_CONTROL
 #define JOBS 1
 #else
-#undef JOBS
+#define JOBS 0
 #endif
 
 #if JOBS || defined(CONFIG_ASH_READ_NCHARS)
@@ -1381,15 +1381,7 @@ static const struct builtincmd builtincmd[] = {
        { BUILTIN_REGULAR       "wait", waitcmd },
 };
 
-#define NUMBUILTINS  (sizeof (builtincmd) / sizeof (struct builtincmd) )
-
-static const char *safe_applets[] = { 
-       "[", "test", "echo", "cat",
-       "ln", "cp", "touch", "mkdir", "rm",
-       "cut", "hexdump", "awk", "sort",
-       "find", "xargs", "ls", "dd",
-       "chown", "chmod"
-};
+#define NUMBUILTINS (sizeof(builtincmd) / sizeof(builtincmd[0]))
 
 
 struct cmdentry {
@@ -2042,7 +2034,30 @@ static void exitshell(void) ATTRIBUTE_NORETURN;
 
 static int is_safe_applet(char *name)
 {
-       int n = sizeof(safe_applets) / sizeof(char *);
+       /* It isn't a bug to have non-existent applet here... */
+       /* ...just a waste of space... */
+       static const char safe_applets[][8] = { 
+               "["
+               USE_AWK    (, "awk"    )
+               USE_CAT    (, "cat"    )
+               USE_CHMOD  (, "chmod"  )
+               USE_CHOWN  (, "chown"  )
+               USE_CP     (, "cp"     )
+               USE_CUT    (, "cut"    )
+               USE_DD     (, "dd"     )
+               USE_ECHO   (, "echo"   )
+               USE_FIND   (, "find"   )
+               USE_HEXDUMP(, "hexdump")
+               USE_LN     (, "ln"     )
+               USE_LS     (, "ls"     )
+               USE_MKDIR  (, "mkdir"  )
+               USE_RM     (, "rm"     )
+               USE_SORT   (, "sort"   )
+               USE_TEST   (, "test"   )
+               USE_TOUCH  (, "touch"  )
+               USE_XARGS  (, "xargs"  )
+       };
+       int n = sizeof(safe_applets) / sizeof(safe_applets[0]);
        int i;
        for (i = 0; i < n; i++)
                if (strcmp(safe_applets[i], name) == 0)
@@ -2402,7 +2417,7 @@ static const char * updatepwd(const char *dir)
        }
        p = strtok(cdcomppath, "/");
        while (p) {
-               switch(*p) {
+               switch (*p) {
                case '.':
                        if (p[1] == '.' && p[2] == '\0') {
                                while (new > lim) {
@@ -3702,12 +3717,11 @@ shellexec(char **argv, const char *path, int idx)
 
        clearredir(1);
        envp = environment();
-       if (strchr(argv[0], '/') != NULL
-               || is_safe_applet(argv[0])
+       if (strchr(argv[0], '/')
 #ifdef CONFIG_FEATURE_SH_STANDALONE_SHELL
-               || find_applet_by_name(argv[0])
+        || find_applet_by_name(argv[0])
 #endif
-                                               ) {
+       ) {
                tryexec(argv[0], argv, envp);
                e = errno;
        } else {
@@ -3750,7 +3764,10 @@ tryexec(char *cmd, char **argv, char **envp)
        int argc = 0;
        char **c;
        
-       if(strchr(cmd, '/') == NULL && is_safe_applet(cmd) && (a = find_applet_by_name(cmd)) != NULL) {
+       if (strchr(cmd, '/') == NULL
+        && (a = find_applet_by_name(cmd)) != NULL
+        && is_safe_applet(cmd)
+       ) {
                c = argv;
                while (*c != NULL) {
                        c++; argc++;
@@ -3759,7 +3776,7 @@ tryexec(char *cmd, char **argv, char **envp)
                exit(a->main(argc, argv));
        }
 #ifdef CONFIG_FEATURE_SH_STANDALONE_SHELL
-       if(find_applet_by_name(cmd) != NULL) {
+       if (find_applet_by_name(cmd) != NULL) {
                /* re-exec ourselves with the new arguments */
                execve(CONFIG_BUSYBOX_EXEC_PATH,argv,envp);
                /* If they called chroot or otherwise made the binary no longer
@@ -4802,7 +4819,7 @@ exptilde(char *startp, char *p, int flag)
        name = p + 1;
 
        while ((c = *++p) != '\0') {
-               switch(c) {
+               switch (c) {
                case CTLESC:
                        return startp;
                case CTLQUOTEMARK:
@@ -6647,7 +6664,7 @@ usage:
 }
 #endif /* JOBS */
 
-#if defined(JOBS) || DEBUG
+#if JOBS || DEBUG
 static int
 jobno(const struct job *jp)
 {
@@ -8172,7 +8189,7 @@ exitcmd(int argc, char **argv)
 static int
 echocmd(int argc, char **argv)
 {
-       return bb_echo(argc, argv);
+       return bb_echo(argv);
 }
 #endif
 
@@ -10211,7 +10228,7 @@ readtoken1(int firstc, int syntax, char *eofmark, int striptabs)
                CHECKEND();     /* set c to PEOF if at end of here document */
                for (;;) {      /* until end of line or end of word */
                        CHECKSTRSPACE(4, out);  /* permit 4 calls to USTPUTC */
-                       switch(SIT(c, syntax)) {
+                       switch (SIT(c, syntax)) {
                        case CNL:       /* '\n' */
                                if (syntax == BASESYNTAX)
                                        goto endword;   /* exit outer loop */
@@ -11282,7 +11299,7 @@ shtree(union node *n, int ind, char *pfx, FILE *fp)
                return;
 
        indent(ind, pfx, fp);
-       switch(n->type) {
+       switch (n->type) {
        case NSEMI:
                s = "; ";
                goto binop;
@@ -11893,17 +11910,11 @@ static int helpcmd(int argc, char **argv)
                }
        }
 #ifdef CONFIG_FEATURE_SH_STANDALONE_SHELL
-       {
-               extern const struct BB_applet applets[];
-               extern const size_t NUM_APPLETS;
-
-               for (i = 0; i < NUM_APPLETS; i++) {
-
-                       col += out1fmt("%c%s", ((col == 0) ? '\t' : ' '), applets[i].name);
-                       if (col > 60) {
-                               out1fmt("\n");
-                               col = 0;
-                       }
+       for (i = 0; i < NUM_APPLETS; i++) {
+               col += out1fmt("%c%s", ((col == 0) ? '\t' : ' '), applets[i].name);
+               if (col > 60) {
+                       out1fmt("\n");
+                       col = 0;
                }
        }
 #endif
@@ -12014,7 +12025,7 @@ setvar(const char *name, const char *val, int flags)
                vallen = strlen(val);
        }
        INTOFF;
-       nameeq = ckmalloc(namelen + vallen + 2)
+       nameeq = ckmalloc(namelen + vallen + 2);
        p = memcpy(nameeq, name, namelen) + namelen;
        if (val) {
                *p++ = '=';
@@ -12619,7 +12630,7 @@ readcmd(int argc, char **argv)
        while ((i = nextopt("p:r")) != '\0')
 #endif
        {
-               switch(i) {
+               switch (i) {
                case 'p':
                        prompt = optionarg;
                        break;
@@ -12693,7 +12704,7 @@ readcmd(int argc, char **argv)
                FD_ZERO (&set);
                FD_SET (0, &set);
 
-               i = select (FD_SETSIZE, &set, NULL, NULL, &ts);
+               i = select(FD_SETSIZE, &set, NULL, NULL, &ts);
                if (!i) {
 #if defined(CONFIG_ASH_READ_NCHARS)
                        if (nch_flag)
@@ -13585,7 +13596,7 @@ static arith_t arith (const char *expr, int *perrcode)
                 * a number, since it evaluates to one). Think about it.
                 * It makes sense. */
                if (lasttok != TOK_NUM) {
-                       switch(op) {
+                       switch (op) {
                                case TOK_ADD:
                                    op = TOK_UPLUS;
                                    break;