summaryrefslogtreecommitdiff
path: root/shell/hush.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-05-02 23:39:04 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-05-02 23:39:04 +0000
commitf2fffd0014edff7f791fc2a5b27147bb0628d7e6 (patch)
tree297db97c34a8e3c579129e2f6f07e6eacaafff67 /shell/hush.c
parent3bc18253b081cc0b73f902036416fea47f2b61e5 (diff)
downloadbusybox-w32-f2fffd0014edff7f791fc2a5b27147bb0628d7e6.tar.gz
busybox-w32-f2fffd0014edff7f791fc2a5b27147bb0628d7e6.tar.bz2
busybox-w32-f2fffd0014edff7f791fc2a5b27147bb0628d7e6.zip
hush: remove env builtin (it is buggy). Add comments
Diffstat (limited to '')
-rw-r--r--shell/hush.c33
1 files changed, 16 insertions, 17 deletions
diff --git a/shell/hush.c b/shell/hush.c
index cdb0b74da..f3be78547 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -332,7 +332,6 @@ static void __syntax(int line)
332/* Index of subroutines: */ 332/* Index of subroutines: */
333/* function prototypes for builtins */ 333/* function prototypes for builtins */
334static int builtin_cd(char **argv); 334static int builtin_cd(char **argv);
335static int builtin_env(char **argv);
336static int builtin_eval(char **argv); 335static int builtin_eval(char **argv);
337static int builtin_exec(char **argv); 336static int builtin_exec(char **argv);
338static int builtin_exit(char **argv); 337static int builtin_exit(char **argv);
@@ -432,7 +431,6 @@ static const struct built_in_command bltins[] = {
432 { "break", "Exit for, while or until loop", builtin_not_written }, 431 { "break", "Exit for, while or until loop", builtin_not_written },
433 { "cd", "Change working directory", builtin_cd }, 432 { "cd", "Change working directory", builtin_cd },
434 { "continue", "Continue for, while or until loop", builtin_not_written }, 433 { "continue", "Continue for, while or until loop", builtin_not_written },
435 { "env", "Print all environment variables", builtin_env },
436 { "eval", "Construct and run shell command", builtin_eval }, 434 { "eval", "Construct and run shell command", builtin_eval },
437 { "exec", "Exec command, replacing this shell with the exec'd process", 435 { "exec", "Exec command, replacing this shell with the exec'd process",
438 builtin_exec }, 436 builtin_exec },
@@ -643,19 +641,6 @@ static int builtin_cd(char **argv)
643 return EXIT_SUCCESS; 641 return EXIT_SUCCESS;
644} 642}
645 643
646/* built-in 'env' handler */
647static int builtin_env(char **argv ATTRIBUTE_UNUSED)
648{
649/* TODO: call env applet's code instead */
650 char **e = environ;
651 if (e == NULL)
652 return EXIT_FAILURE;
653 while (*e) {
654 puts(*e++);
655 }
656 return EXIT_SUCCESS;
657}
658
659/* built-in 'exec' handler */ 644/* built-in 'exec' handler */
660static int builtin_exec(char **argv) 645static int builtin_exec(char **argv)
661{ 646{
@@ -670,13 +655,15 @@ static int builtin_exit(char **argv)
670{ 655{
671// TODO: bash does it ONLY on top-level sh exit (+interacive only?) 656// TODO: bash does it ONLY on top-level sh exit (+interacive only?)
672 //puts("exit"); /* bash does it */ 657 //puts("exit"); /* bash does it */
658// TODO: warn if we have background jobs: "There are stopped jobs"
659// On second consecutive 'exit', exit anyway.
673 660
674 if (argv[1] == NULL) 661 if (argv[1] == NULL)
675 hush_exit(last_return_code); 662 hush_exit(last_return_code);
676 /* mimic bash: exit 123abc == exit 255 + error msg */ 663 /* mimic bash: exit 123abc == exit 255 + error msg */
677 xfunc_error_retval = 255; 664 xfunc_error_retval = 255;
678 /* bash: exit -2 == exit 254, no error msg */ 665 /* bash: exit -2 == exit 254, no error msg */
679 hush_exit(xatoi(argv[1])); 666 hush_exit(xatoi(argv[1]) & 0xff);
680} 667}
681 668
682/* built-in 'export VAR=value' handler */ 669/* built-in 'export VAR=value' handler */
@@ -686,7 +673,15 @@ static int builtin_export(char **argv)
686 char *name = argv[1]; 673 char *name = argv[1];
687 674
688 if (name == NULL) { 675 if (name == NULL) {
689 return builtin_env(argv); 676 // TODO:
677 // ash emits: export VAR='VAL'
678 // bash: declare -x VAR="VAL"
679 // (both also escape as needed (quotes, $, etc))
680 char **e = environ;
681 if (e)
682 while (*e)
683 puts(*e++);
684 return EXIT_SUCCESS;
690 } 685 }
691 686
692 name = strdup(name); 687 name = strdup(name);
@@ -1321,6 +1316,8 @@ static void pseudo_exec_argv(char **argv)
1321 1316
1322static void pseudo_exec(struct child_prog *child) 1317static void pseudo_exec(struct child_prog *child)
1323{ 1318{
1319// FIXME: buggy wrt NOMMU! Must not modify any global data
1320// until it does exec/_exit, but currently it does.
1324 int rcode; 1321 int rcode;
1325 1322
1326 if (child->argv) { 1323 if (child->argv) {
@@ -1852,6 +1849,8 @@ static int run_pipe_real(struct pipe *pi)
1852 return -1; 1849 return -1;
1853} 1850}
1854 1851
1852// NB: called by pseudo_exec, and therefore must not modify any
1853// global data until exec/_exit (we can be a child after vfork!)
1855static int run_list_real(struct pipe *pi) 1854static int run_list_real(struct pipe *pi)
1856{ 1855{
1857 char *save_name = NULL; 1856 char *save_name = NULL;