hush: fix another case where empty "for" wasn't setting exitcode to 0
authorDenys Vlasenko <vda.linux@googlemail.com>
Sat, 28 Jul 2018 10:42:08 +0000 (12:42 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sat, 28 Jul 2018 10:42:08 +0000 (12:42 +0200)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/ash_test/ash-misc/empty_for1.right [new file with mode: 0644]
shell/ash_test/ash-misc/empty_for1.tests [new file with mode: 0755]
shell/hush.c
shell/hush_test/hush-misc/empty_for1.right [new file with mode: 0644]
shell/hush_test/hush-misc/empty_for1.tests [new file with mode: 0755]

diff --git a/shell/ash_test/ash-misc/empty_for1.right b/shell/ash_test/ash-misc/empty_for1.right
new file mode 100644 (file)
index 0000000..46ffcec
--- /dev/null
@@ -0,0 +1 @@
+Zero:0
diff --git a/shell/ash_test/ash-misc/empty_for1.tests b/shell/ash_test/ash-misc/empty_for1.tests
new file mode 100755 (executable)
index 0000000..5a2554d
--- /dev/null
@@ -0,0 +1,5 @@
+false
+for v; do
+       exit 2
+done
+echo Zero:$?
index 14681aa48dd1cf2b07791036e83c9351f16d9721..d17f7f29e966f25e5360bba5d5ba097ccc4f86e5 100644 (file)
@@ -9391,11 +9391,11 @@ static int run_list(struct pipe *pi)
                                }; /* argv list with one element: "$@" */
                                char **vals;
 
+                               G.last_exitcode = rcode = EXIT_SUCCESS;
                                vals = (char**)encoded_dollar_at_argv;
                                if (pi->next->res_word == RES_IN) {
                                        /* if no variable values after "in" we skip "for" */
                                        if (!pi->next->cmds[0].argv) {
-                                               G.last_exitcode = rcode = EXIT_SUCCESS;
                                                debug_printf_exec(": null FOR: exitcode EXIT_SUCCESS\n");
                                                break;
                                        }
diff --git a/shell/hush_test/hush-misc/empty_for1.right b/shell/hush_test/hush-misc/empty_for1.right
new file mode 100644 (file)
index 0000000..46ffcec
--- /dev/null
@@ -0,0 +1 @@
+Zero:0
diff --git a/shell/hush_test/hush-misc/empty_for1.tests b/shell/hush_test/hush-misc/empty_for1.tests
new file mode 100755 (executable)
index 0000000..5a2554d
--- /dev/null
@@ -0,0 +1,5 @@
+false
+for v; do
+       exit 2
+done
+echo Zero:$?