sh: Set $? to 0 for background commands.
authorPeter Avalos <pavalos@dragonflybsd.org>
Sat, 2 Jul 2011 23:59:09 +0000 (13:59 -1000)
committerPeter Avalos <pavalos@dragonflybsd.org>
Sun, 21 Aug 2011 19:10:24 +0000 (12:10 -0700)
For backgrounded pipelines and subshells, the previous value of $? was
being preserved, which is incorrect.

For backgrounded simple commands containing a command substitution, the
status of the last command substitution was returned instead of 0.

If fork() fails, this is an error.

Obtained-from:   FreeBSD SVN rev 221027

bin/sh/eval.c
tools/regression/bin/sh/execution/bg1.0 [new file with mode: 0644]
tools/regression/bin/sh/execution/bg2.0 [new file with mode: 0644]
tools/regression/bin/sh/execution/bg3.0 [new file with mode: 0644]

index 0d4964d..8169d12 100644 (file)
@@ -34,7 +34,7 @@
  * SUCH DAMAGE.
  *
  * @(#)eval.c  8.9 (Berkeley) 6/8/95
- * $FreeBSD: src/bin/sh/eval.c,v 1.102 2011/04/23 22:28:56 jilles Exp $
+ * $FreeBSD: src/bin/sh/eval.c,v 1.103 2011/04/25 20:54:12 jilles Exp $
  */
 
 #include <sys/time.h>
@@ -421,7 +421,8 @@ evalsubshell(union node *n, int flags)
                INTOFF;
                exitstatus = waitforjob(jp, NULL);
                INTON;
-       }
+       } else
+               exitstatus = 0;
 }
 
 
@@ -561,7 +562,8 @@ evalpipe(union node *n)
                exitstatus = waitforjob(jp, NULL);
                TRACE(("evalpipe:  job done exit status %d\n", exitstatus));
                INTON;
-       }
+       } else
+               exitstatus = 0;
 }
 
 
@@ -1059,7 +1061,8 @@ parent:   /* parent process gets here (if we forked) */
                backcmd->fd = pip[0];
                close(pip[1]);
                backcmd->jp = jp;
-       }
+       } else
+               exitstatus = 0;
 
 out:
        if (lastarg)
diff --git a/tools/regression/bin/sh/execution/bg1.0 b/tools/regression/bin/sh/execution/bg1.0
new file mode 100644 (file)
index 0000000..c801013
--- /dev/null
@@ -0,0 +1,3 @@
+# $FreeBSD: src/tools/regression/bin/sh/execution/bg1.0,v 1.1 2011/04/25 20:54:12 jilles Exp $
+
+: `false` &
diff --git a/tools/regression/bin/sh/execution/bg2.0 b/tools/regression/bin/sh/execution/bg2.0
new file mode 100644 (file)
index 0000000..d201070
--- /dev/null
@@ -0,0 +1,5 @@
+# $FreeBSD: src/tools/regression/bin/sh/execution/bg2.0,v 1.1 2011/04/25 20:54:12 jilles Exp $
+
+f() { return 42; }
+f
+: | : &
diff --git a/tools/regression/bin/sh/execution/bg3.0 b/tools/regression/bin/sh/execution/bg3.0
new file mode 100644 (file)
index 0000000..9e26b66
--- /dev/null
@@ -0,0 +1,5 @@
+# $FreeBSD: src/tools/regression/bin/sh/execution/bg3.0,v 1.1 2011/04/25 20:54:12 jilles Exp $
+
+f() { return 42; }
+f
+(:) &