diff options
author | Erik Andersen | 2000-05-13 06:33:19 +0000 |
---|---|---|
committer | Erik Andersen | 2000-05-13 06:33:19 +0000 |
commit | bcd6177853a39d47b7c0ea75cc27653d63649afa (patch) | |
tree | 45ed7567a55a548fff8cf6e50dcda63420a8bd0f /sh.c | |
parent | 73c8c9cf9a61286a109a8785b8e4782828d6fe99 (diff) | |
download | busybox-bcd6177853a39d47b7c0ea75cc27653d63649afa.zip busybox-bcd6177853a39d47b7c0ea75cc27653d63649afa.tar.gz |
BusyBox shell (lash) can now be used as a standalone shell when
BB_FEATURE_STANDALONE_SHELL is defined (i.e. BusyBox can now completely replace
sash). Also fixed it so shell builtins now respect pipes and redirects.
-Erik
Diffstat (limited to 'sh.c')
-rw-r--r-- | sh.c | 30 |
1 files changed, 23 insertions, 7 deletions
@@ -721,6 +721,7 @@ static int parseCommand(char **commandPtr, struct job *job, int *isBg) return 0; } + static int runCommand(struct job newJob, struct jobSet *jobList, int inBg) { struct job *job; @@ -728,14 +729,10 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg) int nextin, nextout; int pipefds[2]; /* pipefd[0] is for reading */ struct builtInCommand *x; +#ifdef BB_FEATURE_STANDALONE_SHELL + const struct BB_applet *a = applets; +#endif - /* handle built-ins here -- we don't fork() so we can't background - these very easily */ - for (x = bltins; x->cmd; x++) { - if (!strcmp(newJob.progs[0].argv[0], x->cmd)) { - return (x->function(&newJob, jobList)); - } - } nextin = 0, nextout = 1; for (i = 0; i < newJob.numProgs; i++) { @@ -762,6 +759,25 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg) /* explicit redirections override pipes */ setupRedirections(newJob.progs + i); + /* Match any built-ins here */ + for (x = bltins; x->cmd; x++) { + if (!strcmp(newJob.progs[i].argv[0], x->cmd)) { + exit (x->function(&newJob, jobList)); + } + } +#ifdef BB_FEATURE_STANDALONE_SHELL + /* Handle busybox internals here */ + while (a->name != 0) { + if (strcmp(newJob.progs[i].argv[0], a->name) == 0) { + int argc; + char** argv=newJob.progs[i].argv; + for(argc=0;*argv!=NULL, argv++, argc++); + exit((*(a->main)) (argc, newJob.progs[i].argv)); + } + a++; + } +#endif + execvp(newJob.progs[i].argv[0], newJob.progs[i].argv); fatalError("sh: %s: %s\n", newJob.progs[i].argv[0], strerror(errno)); |