diff options
| author | Erik Andersen <andersen@codepoet.org> | 2000-05-13 06:33:19 +0000 |
|---|---|---|
| committer | Erik Andersen <andersen@codepoet.org> | 2000-05-13 06:33:19 +0000 |
| commit | bcd6177853a39d47b7c0ea75cc27653d63649afa (patch) | |
| tree | 45ed7567a55a548fff8cf6e50dcda63420a8bd0f /shell | |
| parent | 73c8c9cf9a61286a109a8785b8e4782828d6fe99 (diff) | |
| download | busybox-w32-bcd6177853a39d47b7c0ea75cc27653d63649afa.tar.gz busybox-w32-bcd6177853a39d47b7c0ea75cc27653d63649afa.tar.bz2 busybox-w32-bcd6177853a39d47b7c0ea75cc27653d63649afa.zip | |
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 'shell')
| -rw-r--r-- | shell/lash.c | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/shell/lash.c b/shell/lash.c index e446ad113..05dab9254 100644 --- a/shell/lash.c +++ b/shell/lash.c | |||
| @@ -721,6 +721,7 @@ static int parseCommand(char **commandPtr, struct job *job, int *isBg) | |||
| 721 | return 0; | 721 | return 0; |
| 722 | } | 722 | } |
| 723 | 723 | ||
| 724 | |||
| 724 | static int runCommand(struct job newJob, struct jobSet *jobList, int inBg) | 725 | static int runCommand(struct job newJob, struct jobSet *jobList, int inBg) |
| 725 | { | 726 | { |
| 726 | struct job *job; | 727 | struct job *job; |
| @@ -728,14 +729,10 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg) | |||
| 728 | int nextin, nextout; | 729 | int nextin, nextout; |
| 729 | int pipefds[2]; /* pipefd[0] is for reading */ | 730 | int pipefds[2]; /* pipefd[0] is for reading */ |
| 730 | struct builtInCommand *x; | 731 | struct builtInCommand *x; |
| 732 | #ifdef BB_FEATURE_STANDALONE_SHELL | ||
| 733 | const struct BB_applet *a = applets; | ||
| 734 | #endif | ||
| 731 | 735 | ||
| 732 | /* handle built-ins here -- we don't fork() so we can't background | ||
| 733 | these very easily */ | ||
| 734 | for (x = bltins; x->cmd; x++) { | ||
| 735 | if (!strcmp(newJob.progs[0].argv[0], x->cmd)) { | ||
| 736 | return (x->function(&newJob, jobList)); | ||
| 737 | } | ||
| 738 | } | ||
| 739 | 736 | ||
| 740 | nextin = 0, nextout = 1; | 737 | nextin = 0, nextout = 1; |
| 741 | for (i = 0; i < newJob.numProgs; i++) { | 738 | for (i = 0; i < newJob.numProgs; i++) { |
| @@ -762,6 +759,25 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg) | |||
| 762 | /* explicit redirections override pipes */ | 759 | /* explicit redirections override pipes */ |
| 763 | setupRedirections(newJob.progs + i); | 760 | setupRedirections(newJob.progs + i); |
| 764 | 761 | ||
| 762 | /* Match any built-ins here */ | ||
| 763 | for (x = bltins; x->cmd; x++) { | ||
| 764 | if (!strcmp(newJob.progs[i].argv[0], x->cmd)) { | ||
| 765 | exit (x->function(&newJob, jobList)); | ||
| 766 | } | ||
| 767 | } | ||
| 768 | #ifdef BB_FEATURE_STANDALONE_SHELL | ||
| 769 | /* Handle busybox internals here */ | ||
| 770 | while (a->name != 0) { | ||
| 771 | if (strcmp(newJob.progs[i].argv[0], a->name) == 0) { | ||
| 772 | int argc; | ||
| 773 | char** argv=newJob.progs[i].argv; | ||
| 774 | for(argc=0;*argv!=NULL, argv++, argc++); | ||
| 775 | exit((*(a->main)) (argc, newJob.progs[i].argv)); | ||
| 776 | } | ||
| 777 | a++; | ||
| 778 | } | ||
| 779 | #endif | ||
| 780 | |||
| 765 | execvp(newJob.progs[i].argv[0], newJob.progs[i].argv); | 781 | execvp(newJob.progs[i].argv[0], newJob.progs[i].argv); |
| 766 | fatalError("sh: %s: %s\n", newJob.progs[i].argv[0], | 782 | fatalError("sh: %s: %s\n", newJob.progs[i].argv[0], |
| 767 | strerror(errno)); | 783 | strerror(errno)); |
