aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-10-19 23:09:06 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-10-19 23:09:06 +0200
commit3ef4f77620a9f5f9a7c1247e29ea9c14e07b8a30 (patch)
treed0d3d5c73b535ff2db54267fc941e79391770ef3 /shell
parenta8df4c09fbc1daae502a887c47a7bb35d28e8991 (diff)
downloadbusybox-w32-3ef4f77620a9f5f9a7c1247e29ea9c14e07b8a30.tar.gz
busybox-w32-3ef4f77620a9f5f9a7c1247e29ea9c14e07b8a30.tar.bz2
busybox-w32-3ef4f77620a9f5f9a7c1247e29ea9c14e07b8a30.zip
hush: fix exec builtin in a better way (+ "glob in exec" bug fixed)
function old new delta execvp_or_die - 50 +50 static.pseudo_null_str 3 - -3 builtin_exec 83 57 -26 pseudo_exec_argv 200 163 -37 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 0/2 up/down: 50/-66) Total: -16 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/hush.c41
-rwxr-xr-xshell/hush_test/hush-vars/param_glob.tests5
2 files changed, 19 insertions, 27 deletions
diff --git a/shell/hush.c b/shell/hush.c
index ae08c7326..5edcdb844 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -3322,6 +3322,16 @@ static void exec_builtin(char ***to_free,
3322} 3322}
3323 3323
3324 3324
3325static void execvp_or_die(char **argv) NORETURN;
3326static void execvp_or_die(char **argv)
3327{
3328 debug_printf_exec("execing '%s'\n", argv[0]);
3329 sigprocmask(SIG_SETMASK, &G.inherited_set, NULL);
3330 execvp(argv[0], argv);
3331 bb_perror_msg("can't execute '%s'", argv[0]);
3332 _exit(127); /* bash compat */
3333}
3334
3325#if BB_MMU 3335#if BB_MMU
3326#define pseudo_exec_argv(nommu_save, argv, assignment_cnt, argv_expanded) \ 3336#define pseudo_exec_argv(nommu_save, argv, assignment_cnt, argv_expanded) \
3327 pseudo_exec_argv(argv, assignment_cnt, argv_expanded) 3337 pseudo_exec_argv(argv, assignment_cnt, argv_expanded)
@@ -3337,7 +3347,7 @@ static void exec_builtin(char ***to_free,
3337static void pseudo_exec_argv(nommu_save_t *nommu_save, 3347static void pseudo_exec_argv(nommu_save_t *nommu_save,
3338 char **argv, int assignment_cnt, 3348 char **argv, int assignment_cnt,
3339 char **argv_expanded) NORETURN; 3349 char **argv_expanded) NORETURN;
3340static void pseudo_exec_argv(nommu_save_t *nommu_save, 3350static NOINLINE void pseudo_exec_argv(nommu_save_t *nommu_save,
3341 char **argv, int assignment_cnt, 3351 char **argv, int assignment_cnt,
3342 char **argv_expanded) 3352 char **argv_expanded)
3343{ 3353{
@@ -3421,11 +3431,7 @@ static void pseudo_exec_argv(nommu_save_t *nommu_save,
3421#if ENABLE_FEATURE_SH_STANDALONE || BB_MMU 3431#if ENABLE_FEATURE_SH_STANDALONE || BB_MMU
3422 skip: 3432 skip:
3423#endif 3433#endif
3424 debug_printf_exec("execing '%s'\n", argv[0]); 3434 execvp_or_die(argv);
3425 sigprocmask(SIG_SETMASK, &G.inherited_set, NULL);
3426 execvp(argv[0], argv);
3427 bb_perror_msg("can't execute '%s'", argv[0]);
3428 _exit(127); /* bash compat */
3429} 3435}
3430 3436
3431/* Called after [v]fork() in run_pipe 3437/* Called after [v]fork() in run_pipe
@@ -6985,32 +6991,19 @@ static int FAST_FUNC builtin_cd(char **argv)
6985 6991
6986static int FAST_FUNC builtin_exec(char **argv) 6992static int FAST_FUNC builtin_exec(char **argv)
6987{ 6993{
6988 static const char pseudo_null_str[] = { SPECIAL_VAR_SYMBOL, SPECIAL_VAR_SYMBOL, '\0' };
6989 char **pp;
6990#if !BB_MMU
6991 nommu_save_t dummy;
6992#endif
6993
6994 if (*++argv == NULL) 6994 if (*++argv == NULL)
6995 return EXIT_SUCCESS; /* bash does this */ 6995 return EXIT_SUCCESS; /* bash does this */
6996 6996
6997 /* Make sure empty arguments aren't ignored */
6998 /* Example: exec ls '' */
6999 pp = argv;
7000 while (*pp) {
7001 if ((*pp)[0] == '\0')
7002 *pp = (char*)pseudo_null_str;
7003 pp++;
7004 }
7005
7006 /* Careful: we can end up here after [v]fork. Do not restore 6997 /* Careful: we can end up here after [v]fork. Do not restore
7007 * tty pgrp then, only top-level shell process does that */ 6998 * tty pgrp then, only top-level shell process does that */
7008 if (G_saved_tty_pgrp && getpid() == G.root_pid) 6999 if (G_saved_tty_pgrp && getpid() == G.root_pid)
7009 tcsetpgrp(G_interactive_fd, G_saved_tty_pgrp); 7000 tcsetpgrp(G_interactive_fd, G_saved_tty_pgrp);
7010 7001
7011 /* TODO: if exec fails, bash does NOT exit! We do... */ 7002 /* TODO: if exec fails, bash does NOT exit! We do.
7012 pseudo_exec_argv(&dummy, argv, 0, NULL); 7003 * We'll need to undo sigprocmask (it's inside execvp_or_die)
7013 /* never returns */ 7004 * and tcsetpgrp, and this is inherently racy.
7005 */
7006 execvp_or_die(argv);
7014} 7007}
7015 7008
7016static int FAST_FUNC builtin_exit(char **argv) 7009static int FAST_FUNC builtin_exit(char **argv)
diff --git a/shell/hush_test/hush-vars/param_glob.tests b/shell/hush_test/hush-vars/param_glob.tests
index 0173fd771..4d74fee02 100755
--- a/shell/hush_test/hush-vars/param_glob.tests
+++ b/shell/hush_test/hush-vars/param_glob.tests
@@ -1,7 +1,6 @@
1if test $# = 0; then 1if test $# = 0; then
2 # UNFIXED BUG in builtin_exec! will glob param! 2 exec "$THIS_SH" "$0" 'param_glob.t*'
3 #exec "$THIS_SH" "$0" 'param_glob.t*' 3 echo NOT SHOWN
4 "$THIS_SH" "$0" 'param_glob.t*'
5 exit 4 exit
6fi 5fi
7echo $* 6echo $*