[busybox]/bin/sh exit status
Nils Carlson
nils.carlson at ludd.ltu.se
Sun Jan 24 22:05:16 UTC 2010
Hi there,
While doing some work with the C system() command we ran into some
trouble
where busybox wasn't returning the exit status of the spawned process,
ie,
/bin/sh -c
wasn't returning the exit code as from the last command (which it
should,
according to posix).
So here is a simple patch that fixes this, tell me what you think,
is the change valid, is it desired? It's quite usefull anyway... :-)
Cheers,
Nils Carlson
diff --git a/shell/bbsh.c b/shell/bbsh.c
index 897c022..64317f9 100644
--- a/shell/bbsh.c
+++ b/shell/bbsh.c
@@ -169,7 +169,10 @@ static int run_pipeline(struct pipeline *line)
execvp(cmd->argv[0],cmd->argv);
printf("No %s", cmd->argv[0]);
exit(EXIT_FAILURE);
- } else waitpid(pid, &status, 0);
+ } else {
+ waitpid(pid, &status, 0);
+ return status;
+ }
}
return 0;
@@ -183,19 +186,22 @@ static void free_cmd(void *data)
}
-static void handle(char *command)
+static int handle(char *command)
{
struct pipeline line;
char *start = command;
+ int ret;
for (;;) {
memset(&line,0,sizeof(struct pipeline));
start = parse_pipeline(start, &line);
if (!line.cmd) break;
- run_pipeline(&line);
+ ret = run_pipeline(&line);
free_list(line.cmd, free_cmd);
}
+
+ return ret;
}
int bbsh_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@@ -203,6 +209,7 @@ int bbsh_main(int argc, char **argv)
{
char *command=NULL;
FILE *f;
+ int ret
getopt32(argv, "c:", &command);
@@ -214,10 +221,10 @@ int bbsh_main(int argc, char **argv)
if (!f) putchar('$');
if (1 > getline(&command, &cmdlen,f ? : stdin))
break
- handle(command);
+ ret = handle(command);
}
if (ENABLE_FEATURE_CLEAN_UP) free(command);
}
- return 1;
+ return ret;
}
More information about the busybox
mailing list