hush: "wait $!; echo $?" should return 127 if $! already exited
authorDenys Vlasenko <vda.linux@googlemail.com>
Mon, 7 Nov 2016 22:07:21 +0000 (23:07 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Mon, 7 Nov 2016 22:07:21 +0000 (23:07 +0100)
It would be nice to provide bash-like "remember las exitcode"
thingy, but it's a bit complex. For now, match ash and dash.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/hush.c

index b842d6eec6d0fc35a04e5d74353a406e51dfbd8f..7683a3749eb61cf6a505d6bb47f85e48fc19a4ca 100644 (file)
@@ -9636,12 +9636,13 @@ static int FAST_FUNC builtin_wait(char **argv)
                                        /* "wait $!" but last bg task has already exited. Try:
                                         * (sleep 1; exit 3) & sleep 2; echo $?; wait $!; echo $?
                                         * In bash it prints exitcode 0, then 3.
+                                        * In dash, it is 127.
                                         */
-                                       ret = 0; /* FIXME */
-                                       continue;
+                                       /* ret = G.last_bg_pid_exitstatus - FIXME */
+                               } else {
+                                       /* Example: "wait 1". mimic bash message */
+                                       bb_error_msg("wait: pid %d is not a child of this shell", (int)pid);
                                }
-                               /* Example: "wait 1". mimic bash message */
-                               bb_error_msg("wait: pid %d is not a child of this shell", (int)pid);
                        } else {
                                /* ??? */
                                bb_perror_msg("wait %s", *argv);