hush: fix a case where return in sourced file has no effect
authorDenys Vlasenko <vda.linux@googlemail.com>
Thu, 24 Mar 2011 01:50:03 +0000 (02:50 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 24 Mar 2011 01:50:03 +0000 (02:50 +0100)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/hush.c
shell/hush_test/hush-misc/return1.right [new file with mode: 0644]
shell/hush_test/hush-misc/return1.tests [new file with mode: 0755]

index 339f3349a5f69b1ca098580dbbbc44a3c3e35e88..8154ac47bb377dc3b6dc7908c32d9c395da8058b 100644 (file)
@@ -5554,6 +5554,10 @@ static void parse_and_run_stream(struct in_str *inp, int end_trigger)
                debug_printf_exec("parse_and_run_stream: run_and_free_list\n");
                run_and_free_list(pipe_list);
                empty = 0;
+#if ENABLE_HUSH_FUNCTIONS
+               if (G.flag_return_in_progress == 1)
+                       break;
+#endif
        }
 }
 
diff --git a/shell/hush_test/hush-misc/return1.right b/shell/hush_test/hush-misc/return1.right
new file mode 100644 (file)
index 0000000..7b24a35
--- /dev/null
@@ -0,0 +1 @@
+Ok:0
diff --git a/shell/hush_test/hush-misc/return1.tests b/shell/hush_test/hush-misc/return1.tests
new file mode 100755 (executable)
index 0000000..eeb92ef
--- /dev/null
@@ -0,0 +1,4 @@
+echo "true && return; echo Should not be printed" >return_sourced
+. ./return_sourced
+rm return_sourced
+echo Ok:$?