hush: fix a bug in argv restoration after sourcing a file
if sourced file "shift"ed argvs so that $1 is NULL, restore wasn't done. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
4e4f88e569
commit
2b1559056c
4
shell/ash_test/ash-misc/source_argv_and_shift.right
Normal file
4
shell/ash_test/ash-misc/source_argv_and_shift.right
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
sourced_arg1:1
|
||||||
|
arg1:
|
||||||
|
sourced_arg1:a
|
||||||
|
arg1:1
|
12
shell/ash_test/ash-misc/source_argv_and_shift.tests
Executable file
12
shell/ash_test/ash-misc/source_argv_and_shift.tests
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
echo 'echo sourced_arg1:$1' >sourced1
|
||||||
|
echo 'shift' >>sourced1
|
||||||
|
|
||||||
|
set -- 1
|
||||||
|
. ./sourced1
|
||||||
|
echo arg1:$1
|
||||||
|
|
||||||
|
set -- 1
|
||||||
|
. ./sourced1 a
|
||||||
|
echo arg1:$1
|
||||||
|
|
||||||
|
rm sourced1
|
@ -9606,6 +9606,7 @@ static int FAST_FUNC builtin_source(char **argv)
|
|||||||
char *arg_path, *filename;
|
char *arg_path, *filename;
|
||||||
FILE *input;
|
FILE *input;
|
||||||
save_arg_t sv;
|
save_arg_t sv;
|
||||||
|
char *args_need_save;
|
||||||
#if ENABLE_HUSH_FUNCTIONS
|
#if ENABLE_HUSH_FUNCTIONS
|
||||||
smallint sv_flg;
|
smallint sv_flg;
|
||||||
#endif
|
#endif
|
||||||
@ -9637,7 +9638,8 @@ static int FAST_FUNC builtin_source(char **argv)
|
|||||||
/* "we are inside sourced file, ok to use return" */
|
/* "we are inside sourced file, ok to use return" */
|
||||||
G_flag_return_in_progress = -1;
|
G_flag_return_in_progress = -1;
|
||||||
#endif
|
#endif
|
||||||
if (argv[1])
|
args_need_save = argv[1]; /* used as a boolean variable */
|
||||||
|
if (args_need_save)
|
||||||
save_and_replace_G_args(&sv, argv);
|
save_and_replace_G_args(&sv, argv);
|
||||||
|
|
||||||
/* "false; . ./empty_line; echo Zero:$?" should print 0 */
|
/* "false; . ./empty_line; echo Zero:$?" should print 0 */
|
||||||
@ -9645,7 +9647,7 @@ static int FAST_FUNC builtin_source(char **argv)
|
|||||||
parse_and_run_file(input);
|
parse_and_run_file(input);
|
||||||
fclose_and_forget(input);
|
fclose_and_forget(input);
|
||||||
|
|
||||||
if (argv[1])
|
if (args_need_save) /* can't use argv[1] instead: "shift" can mangle it */
|
||||||
restore_G_args(&sv, argv);
|
restore_G_args(&sv, argv);
|
||||||
#if ENABLE_HUSH_FUNCTIONS
|
#if ENABLE_HUSH_FUNCTIONS
|
||||||
G_flag_return_in_progress = sv_flg;
|
G_flag_return_in_progress = sv_flg;
|
||||||
|
4
shell/hush_test/hush-misc/source_argv_and_shift.right
Normal file
4
shell/hush_test/hush-misc/source_argv_and_shift.right
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
sourced_arg1:1
|
||||||
|
arg1:
|
||||||
|
sourced_arg1:a
|
||||||
|
arg1:1
|
12
shell/hush_test/hush-misc/source_argv_and_shift.tests
Executable file
12
shell/hush_test/hush-misc/source_argv_and_shift.tests
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
echo 'echo sourced_arg1:$1' >sourced1
|
||||||
|
echo 'shift' >>sourced1
|
||||||
|
|
||||||
|
set -- 1
|
||||||
|
. ./sourced1
|
||||||
|
echo arg1:$1
|
||||||
|
|
||||||
|
set -- 1
|
||||||
|
. ./sourced1 a
|
||||||
|
echo arg1:$1
|
||||||
|
|
||||||
|
rm sourced1
|
Loading…
Reference in New Issue
Block a user