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 | |
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
-rw-r--r-- | Changelog | 4 | ||||
-rw-r--r-- | applets/busybox.c | 6 | ||||
-rw-r--r-- | busybox.c | 6 | ||||
-rw-r--r-- | busybox.def.h | 5 | ||||
-rw-r--r-- | internal.h | 4 | ||||
-rw-r--r-- | lash.c | 30 | ||||
-rw-r--r-- | sh.c | 30 | ||||
-rw-r--r-- | shell/lash.c | 30 |
8 files changed, 87 insertions, 28 deletions
@@ -30,6 +30,10 @@ | |||
30 | * zcat now works (wasn't working since option parsing was broken) | 30 | * zcat now works (wasn't working since option parsing was broken) |
31 | * Renamed "mnc" to the more correct "nc". | 31 | * Renamed "mnc" to the more correct "nc". |
32 | * Makefile intelligence updates | 32 | * Makefile intelligence updates |
33 | * BusyBox sh (lash) internals now behave wrt pipes and redirects. | ||
34 | * BusyBox sh (lash) now supports being used as a standalone shell. When | ||
35 | BB_FEATURE_STANDALONE_SHELL is defined, all the busybox commands may | ||
36 | be invoked as shell internals. | ||
33 | * More doc updates | 37 | * More doc updates |
34 | 38 | ||
35 | 39 | ||
diff --git a/applets/busybox.c b/applets/busybox.c index 85b42df23..07caa3446 100644 --- a/applets/busybox.c +++ b/applets/busybox.c | |||
@@ -30,7 +30,7 @@ int atexit(void (*__func) (void)) | |||
30 | void *__libc_stack_end; | 30 | void *__libc_stack_end; |
31 | #endif | 31 | #endif |
32 | 32 | ||
33 | static const struct Applet applets[] = { | 33 | const struct BB_applet applets[] = { |
34 | 34 | ||
35 | #ifdef BB_BASENAME | 35 | #ifdef BB_BASENAME |
36 | {"basename", basename_main, _BB_DIR_USR_BIN}, | 36 | {"basename", basename_main, _BB_DIR_USR_BIN}, |
@@ -350,7 +350,7 @@ int main(int argc, char **argv) | |||
350 | { | 350 | { |
351 | char *s; | 351 | char *s; |
352 | char *name; | 352 | char *name; |
353 | const struct Applet *a = applets; | 353 | const struct BB_applet *a = applets; |
354 | 354 | ||
355 | for (s = name = argv[0]; *s != '\0';) { | 355 | for (s = name = argv[0]; *s != '\0';) { |
356 | if (*s++ == '/') | 356 | if (*s++ == '/') |
@@ -384,7 +384,7 @@ int busybox_main(int argc, char **argv) | |||
384 | argv++; | 384 | argv++; |
385 | 385 | ||
386 | if (been_there_done_that == 1 || argc < 1) { | 386 | if (been_there_done_that == 1 || argc < 1) { |
387 | const struct Applet *a = applets; | 387 | const struct BB_applet *a = applets; |
388 | 388 | ||
389 | fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", | 389 | fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", |
390 | BB_VER, BB_BT); | 390 | BB_VER, BB_BT); |
@@ -30,7 +30,7 @@ int atexit(void (*__func) (void)) | |||
30 | void *__libc_stack_end; | 30 | void *__libc_stack_end; |
31 | #endif | 31 | #endif |
32 | 32 | ||
33 | static const struct Applet applets[] = { | 33 | const struct BB_applet applets[] = { |
34 | 34 | ||
35 | #ifdef BB_BASENAME | 35 | #ifdef BB_BASENAME |
36 | {"basename", basename_main, _BB_DIR_USR_BIN}, | 36 | {"basename", basename_main, _BB_DIR_USR_BIN}, |
@@ -350,7 +350,7 @@ int main(int argc, char **argv) | |||
350 | { | 350 | { |
351 | char *s; | 351 | char *s; |
352 | char *name; | 352 | char *name; |
353 | const struct Applet *a = applets; | 353 | const struct BB_applet *a = applets; |
354 | 354 | ||
355 | for (s = name = argv[0]; *s != '\0';) { | 355 | for (s = name = argv[0]; *s != '\0';) { |
356 | if (*s++ == '/') | 356 | if (*s++ == '/') |
@@ -384,7 +384,7 @@ int busybox_main(int argc, char **argv) | |||
384 | argv++; | 384 | argv++; |
385 | 385 | ||
386 | if (been_there_done_that == 1 || argc < 1) { | 386 | if (been_there_done_that == 1 || argc < 1) { |
387 | const struct Applet *a = applets; | 387 | const struct BB_applet *a = applets; |
388 | 388 | ||
389 | fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", | 389 | fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", |
390 | BB_VER, BB_BT); | 390 | BB_VER, BB_BT); |
diff --git a/busybox.def.h b/busybox.def.h index 5652b4518..296c7f94a 100644 --- a/busybox.def.h +++ b/busybox.def.h | |||
@@ -201,6 +201,11 @@ | |||
201 | // Enable command line editing in the shell | 201 | // Enable command line editing in the shell |
202 | //#define BB_FEATURE_SH_COMMAND_EDITING | 202 | //#define BB_FEATURE_SH_COMMAND_EDITING |
203 | // | 203 | // |
204 | //Allow the shell to invoke all the compiled in BusyBox commands as if they | ||
205 | //were shell builtins. Nice for staticly linking an emergency rescue shell | ||
206 | //amoung other thing. | ||
207 | #ifdef BB_FEATURE_STANDALONE_SHELL | ||
208 | // | ||
204 | // Enable tab completion in the shell (not yet | 209 | // Enable tab completion in the shell (not yet |
205 | // working very well -- so don't turn this on) | 210 | // working very well -- so don't turn this on) |
206 | //#define BB_FEATURE_SH_TAB_COMPLETION | 211 | //#define BB_FEATURE_SH_TAB_COMPLETION |
diff --git a/internal.h b/internal.h index a953ce2e5..92b0255b0 100644 --- a/internal.h +++ b/internal.h | |||
@@ -90,11 +90,13 @@ enum Location { | |||
90 | _BB_DIR_USR_SBIN | 90 | _BB_DIR_USR_SBIN |
91 | }; | 91 | }; |
92 | 92 | ||
93 | struct Applet { | 93 | struct BB_applet { |
94 | const char* name; | 94 | const char* name; |
95 | int (*main)(int argc, char** argv); | 95 | int (*main)(int argc, char** argv); |
96 | enum Location location; | 96 | enum Location location; |
97 | }; | 97 | }; |
98 | /* From busybox.c */ | ||
99 | extern const struct BB_applet applets[]; | ||
98 | 100 | ||
99 | extern int basename_main(int argc, char **argv); | 101 | extern int basename_main(int argc, char **argv); |
100 | extern int busybox_main(int argc, char** argv); | 102 | extern int busybox_main(int argc, char** argv); |
@@ -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)); |
@@ -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)); |
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)); |