#ifdef CONFIG_ASH_JOB_CONTROL
#define JOBS 1
#else
-#undef JOBS
+#define JOBS 0
#endif
#if JOBS || defined(CONFIG_ASH_READ_NCHARS)
{ 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 {
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)
}
p = strtok(cdcomppath, "/");
while (p) {
- switch(*p) {
+ switch (*p) {
case '.':
if (p[1] == '.' && p[2] == '\0') {
while (new > lim) {
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 {
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++;
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
name = p + 1;
while ((c = *++p) != '\0') {
- switch(c) {
+ switch (c) {
case CTLESC:
return startp;
case CTLQUOTEMARK:
}
#endif /* JOBS */
-#if defined(JOBS) || DEBUG
+#if JOBS || DEBUG
static int
jobno(const struct job *jp)
{
static int
echocmd(int argc, char **argv)
{
- return bb_echo(argc, argv);
+ return bb_echo(argv);
}
#endif
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 */
return;
indent(ind, pfx, fp);
- switch(n->type) {
+ switch (n->type) {
case NSEMI:
s = "; ";
goto binop;
}
}
#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
vallen = strlen(val);
}
INTOFF;
- nameeq = ckmalloc(namelen + vallen + 2)
+ nameeq = ckmalloc(namelen + vallen + 2);
p = memcpy(nameeq, name, namelen) + namelen;
if (val) {
*p++ = '=';
while ((i = nextopt("p:r")) != '\0')
#endif
{
- switch(i) {
+ switch (i) {
case 'p':
prompt = optionarg;
break;
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)
* 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;