aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2013-03-17 14:11:04 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2013-03-17 14:11:04 +0100
commit88b532d59af81f3b788864b2d6d42e1f86bc8de0 (patch)
tree0dadcf6799131c15de084c828265ac17ac051b52
parent4ef1439c593daadeffb3f00eaaf49e190a3039e1 (diff)
downloadbusybox-w32-88b532d59af81f3b788864b2d6d42e1f86bc8de0.tar.gz
busybox-w32-88b532d59af81f3b788864b2d6d42e1f86bc8de0.tar.bz2
busybox-w32-88b532d59af81f3b788864b2d6d42e1f86bc8de0.zip
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 <vda.linux@googlemail.com>
-rw-r--r--shell/hush.c9
-rw-r--r--shell/hush_test/hush-misc/source2.right4
-rwxr-xr-xshell/hush_test/hush-misc/source2.tests8
3 files changed, 19 insertions, 2 deletions
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)
8880 free(arg_path); 8880 free(arg_path);
8881 if (!input) { 8881 if (!input) {
8882 /* bb_perror_msg("%s", *argv); - done by fopen_or_warn */ 8882 /* bb_perror_msg("%s", *argv); - done by fopen_or_warn */
8883 /* POSIX: non-interactive shell should abort here,
8884 * not merely fail. So far no one complained :)
8885 */
8883 return EXIT_FAILURE; 8886 return EXIT_FAILURE;
8884 } 8887 }
8885 close_on_exec_on(fileno(input)); 8888 close_on_exec_on(fileno(input));
@@ -8889,12 +8892,14 @@ static int FAST_FUNC builtin_source(char **argv)
8889 /* "we are inside sourced file, ok to use return" */ 8892 /* "we are inside sourced file, ok to use return" */
8890 G.flag_return_in_progress = -1; 8893 G.flag_return_in_progress = -1;
8891#endif 8894#endif
8892 save_and_replace_G_args(&sv, argv); 8895 if (argv[1])
8896 save_and_replace_G_args(&sv, argv);
8893 8897
8894 parse_and_run_file(input); 8898 parse_and_run_file(input);
8895 fclose(input); 8899 fclose(input);
8896 8900
8897 restore_G_args(&sv, argv); 8901 if (argv[1])
8902 restore_G_args(&sv, argv);
8898#if ENABLE_HUSH_FUNCTIONS 8903#if ENABLE_HUSH_FUNCTIONS
8899 G.flag_return_in_progress = sv_flg; 8904 G.flag_return_in_progress = sv_flg;
8900#endif 8905#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 @@
10:arg0 1:arg1 2:arg2
2Ok1:0
30:arg0 1:q 2:w
4Ok2: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 @@
1echo 'echo "0:$0 1:$1 2:$2"' >sourced1
2set -- 1 2 3
3"$THIS_SH" -c '. ./sourced1' arg0 arg1 arg2
4echo Ok1:$?
5"$THIS_SH" -c '. ./sourced1 q w e' arg0 arg1 arg2
6echo Ok2:$?
7
8rm sourced1