Subject: another vfork shell regression
To: None <current-users@netbsd.org>
From: David Laight <david@l8s.co.uk>
List: current-users
Date: 10/23/2002 20:20:59
The wrong process is aborting when variable assignment fails
in the vfork path.  So the following command fails to execute
the second echo (shown here with the correct output).

$ (readonly r; r= /bin/echo a; echo b)
r: is read only
b

fix: defer the mklocal() to the child shell.

Also 'jobs' fails in a non-interactive shell.
In showjobs(), the code that puts the process back into its
own process group should only be run if the shell is actually
doing job control - eg if 'mflag' is set.

	David

Index: eval.c
===================================================================
RCS file: /cvsroot/basesrc/bin/sh/eval.c,v
retrieving revision 1.65
diff -u -r1.65 eval.c
--- eval.c	2002/09/28 01:25:01	1.65
+++ eval.c	2002/10/23 19:09:33
@@ -756,8 +770,6 @@
 
 			savelocalvars = localvars;
 			localvars = NULL;
-			for (sp = varlist.list ; sp ; sp = sp->next)
-				mklocal(sp->text, VEXPORT);
 			vforked = 1;
 			switch (pid = vfork()) {
 			case -1:
@@ -783,6 +795,8 @@
 				}
 				savehandler = handler;
 				handler = &jmploc;
+				for (sp = varlist.list; sp; sp = sp->next)
+					mklocal(sp->text, VEXPORT);
 				forkchild(jp, cmd, mode, vforked);
 				break;
 			default:

Index: jobs.c
===================================================================
RCS file: /cvsroot/basesrc/bin/sh/jobs.c,v
retrieving revision 1.53
diff -u -r1.53 jobs.c
--- jobs.c	2002/09/28 03:15:43	1.53
+++ jobs.c	2002/10/23 19:18:17
@@ -354,7 +541,7 @@
 	 * Check if we are not in our foreground group, and if not
 	 * put us in it.
 	 */
-	if (gotpid != -1 && tcgetpgrp(ttyfd) != getpid()) {
+	if (mflag && gotpid != -1 && tcgetpgrp(ttyfd) != getpid()) {
 		if (tcsetpgrp(ttyfd, getpid()) == -1)
 			error("Cannot set tty process group (%s) at %d",
 			    strerror(errno), __LINE__);

-- 
David Laight: david@l8s.co.uk