From 88b532d59af81f3b788864b2d6d42e1f86bc8de0 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 17 Mar 2013 14:11:04 +0100 Subject: [PATCH] hush: source builtin should override $N only if it has args function old new delta builtin_source 174 184 +10 Signed-off-by: Denys Vlasenko --- shell/hush.c | 9 +++++++-- shell/hush_test/hush-misc/source2.right | 4 ++++ shell/hush_test/hush-misc/source2.tests | 8 ++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 shell/hush_test/hush-misc/source2.right create mode 100755 shell/hush_test/hush-misc/source2.tests diff --git a/shell/hush.c b/shell/hush.c index e2dc1e2d0..b23325725 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -8880,6 +8880,9 @@ static int FAST_FUNC builtin_source(char **argv) free(arg_path); if (!input) { /* bb_perror_msg("%s", *argv); - done by fopen_or_warn */ + /* POSIX: non-interactive shell should abort here, + * not merely fail. So far no one complained :) + */ return EXIT_FAILURE; } close_on_exec_on(fileno(input)); @@ -8889,12 +8892,14 @@ static int FAST_FUNC builtin_source(char **argv) /* "we are inside sourced file, ok to use return" */ G.flag_return_in_progress = -1; #endif - save_and_replace_G_args(&sv, argv); + if (argv[1]) + save_and_replace_G_args(&sv, argv); parse_and_run_file(input); fclose(input); - restore_G_args(&sv, argv); + if (argv[1]) + restore_G_args(&sv, argv); #if ENABLE_HUSH_FUNCTIONS G.flag_return_in_progress = sv_flg; #endif diff --git a/shell/hush_test/hush-misc/source2.right b/shell/hush_test/hush-misc/source2.right new file mode 100644 index 000000000..0587bad67 --- /dev/null +++ b/shell/hush_test/hush-misc/source2.right @@ -0,0 +1,4 @@ +0:arg0 1:arg1 2:arg2 +Ok1:0 +0:arg0 1:q 2:w +Ok2:0 diff --git a/shell/hush_test/hush-misc/source2.tests b/shell/hush_test/hush-misc/source2.tests new file mode 100755 index 000000000..40b6b83cd --- /dev/null +++ b/shell/hush_test/hush-misc/source2.tests @@ -0,0 +1,8 @@ +echo 'echo "0:$0 1:$1 2:$2"' >sourced1 +set -- 1 2 3 +"$THIS_SH" -c '. ./sourced1' arg0 arg1 arg2 +echo Ok1:$? +"$THIS_SH" -c '. ./sourced1 q w e' arg0 arg1 arg2 +echo Ok2:$? + +rm sourced1 -- 2.25.1