mirror of
https://github.com/sheumann/hush.git
synced 2024-08-20 04:28:57 +00:00
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>
This commit is contained in:
parent
a8df4c09fb
commit
3ef4f77620
41
shell/hush.c
41
shell/hush.c
@ -3322,6 +3322,16 @@ static void exec_builtin(char ***to_free,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void execvp_or_die(char **argv) NORETURN;
|
||||||
|
static void execvp_or_die(char **argv)
|
||||||
|
{
|
||||||
|
debug_printf_exec("execing '%s'\n", argv[0]);
|
||||||
|
sigprocmask(SIG_SETMASK, &G.inherited_set, NULL);
|
||||||
|
execvp(argv[0], argv);
|
||||||
|
bb_perror_msg("can't execute '%s'", argv[0]);
|
||||||
|
_exit(127); /* bash compat */
|
||||||
|
}
|
||||||
|
|
||||||
#if BB_MMU
|
#if BB_MMU
|
||||||
#define pseudo_exec_argv(nommu_save, argv, assignment_cnt, argv_expanded) \
|
#define pseudo_exec_argv(nommu_save, argv, assignment_cnt, argv_expanded) \
|
||||||
pseudo_exec_argv(argv, assignment_cnt, argv_expanded)
|
pseudo_exec_argv(argv, assignment_cnt, argv_expanded)
|
||||||
@ -3337,7 +3347,7 @@ static void exec_builtin(char ***to_free,
|
|||||||
static void pseudo_exec_argv(nommu_save_t *nommu_save,
|
static void pseudo_exec_argv(nommu_save_t *nommu_save,
|
||||||
char **argv, int assignment_cnt,
|
char **argv, int assignment_cnt,
|
||||||
char **argv_expanded) NORETURN;
|
char **argv_expanded) NORETURN;
|
||||||
static void pseudo_exec_argv(nommu_save_t *nommu_save,
|
static NOINLINE void pseudo_exec_argv(nommu_save_t *nommu_save,
|
||||||
char **argv, int assignment_cnt,
|
char **argv, int assignment_cnt,
|
||||||
char **argv_expanded)
|
char **argv_expanded)
|
||||||
{
|
{
|
||||||
@ -3421,11 +3431,7 @@ static void pseudo_exec_argv(nommu_save_t *nommu_save,
|
|||||||
#if ENABLE_FEATURE_SH_STANDALONE || BB_MMU
|
#if ENABLE_FEATURE_SH_STANDALONE || BB_MMU
|
||||||
skip:
|
skip:
|
||||||
#endif
|
#endif
|
||||||
debug_printf_exec("execing '%s'\n", argv[0]);
|
execvp_or_die(argv);
|
||||||
sigprocmask(SIG_SETMASK, &G.inherited_set, NULL);
|
|
||||||
execvp(argv[0], argv);
|
|
||||||
bb_perror_msg("can't execute '%s'", argv[0]);
|
|
||||||
_exit(127); /* bash compat */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Called after [v]fork() in run_pipe
|
/* Called after [v]fork() in run_pipe
|
||||||
@ -6985,32 +6991,19 @@ static int FAST_FUNC builtin_cd(char **argv)
|
|||||||
|
|
||||||
static int FAST_FUNC builtin_exec(char **argv)
|
static int FAST_FUNC builtin_exec(char **argv)
|
||||||
{
|
{
|
||||||
static const char pseudo_null_str[] = { SPECIAL_VAR_SYMBOL, SPECIAL_VAR_SYMBOL, '\0' };
|
|
||||||
char **pp;
|
|
||||||
#if !BB_MMU
|
|
||||||
nommu_save_t dummy;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (*++argv == NULL)
|
if (*++argv == NULL)
|
||||||
return EXIT_SUCCESS; /* bash does this */
|
return EXIT_SUCCESS; /* bash does this */
|
||||||
|
|
||||||
/* Make sure empty arguments aren't ignored */
|
|
||||||
/* Example: exec ls '' */
|
|
||||||
pp = argv;
|
|
||||||
while (*pp) {
|
|
||||||
if ((*pp)[0] == '\0')
|
|
||||||
*pp = (char*)pseudo_null_str;
|
|
||||||
pp++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Careful: we can end up here after [v]fork. Do not restore
|
/* Careful: we can end up here after [v]fork. Do not restore
|
||||||
* tty pgrp then, only top-level shell process does that */
|
* tty pgrp then, only top-level shell process does that */
|
||||||
if (G_saved_tty_pgrp && getpid() == G.root_pid)
|
if (G_saved_tty_pgrp && getpid() == G.root_pid)
|
||||||
tcsetpgrp(G_interactive_fd, G_saved_tty_pgrp);
|
tcsetpgrp(G_interactive_fd, G_saved_tty_pgrp);
|
||||||
|
|
||||||
/* TODO: if exec fails, bash does NOT exit! We do... */
|
/* TODO: if exec fails, bash does NOT exit! We do.
|
||||||
pseudo_exec_argv(&dummy, argv, 0, NULL);
|
* We'll need to undo sigprocmask (it's inside execvp_or_die)
|
||||||
/* never returns */
|
* and tcsetpgrp, and this is inherently racy.
|
||||||
|
*/
|
||||||
|
execvp_or_die(argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int FAST_FUNC builtin_exit(char **argv)
|
static int FAST_FUNC builtin_exit(char **argv)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
if test $# = 0; then
|
if test $# = 0; then
|
||||||
# UNFIXED BUG in builtin_exec! will glob param!
|
exec "$THIS_SH" "$0" 'param_glob.t*'
|
||||||
#exec "$THIS_SH" "$0" 'param_glob.t*'
|
echo NOT SHOWN
|
||||||
"$THIS_SH" "$0" 'param_glob.t*'
|
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
echo $*
|
echo $*
|
||||||
|
Loading…
Reference in New Issue
Block a user