Sat Aug 25 02:42:49 2018 UTC ()
PR bin/53548

Deal with the new shell internal exit reason EXEXIT in the case of
a shell which has vfork()'d.   It takes a peculiar set of circumstances
to get into a situation where this is ever relevant, but it can be
done.   See the PR for details.


(kre)
diff -r1.160 -r1.161 src/bin/sh/eval.c

cvs diff -r1.160 -r1.161 src/bin/sh/eval.c (expand / switch to unified diff)

--- src/bin/sh/eval.c 2018/08/22 20:08:54 1.160
+++ src/bin/sh/eval.c 2018/08/25 02:42:49 1.161
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: eval.c,v 1.160 2018/08/22 20:08:54 kre Exp $ */ 1/* $NetBSD: eval.c,v 1.161 2018/08/25 02:42:49 kre Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1993 4 * Copyright (c) 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Kenneth Almquist. 8 * Kenneth Almquist.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -27,27 +27,27 @@ @@ -27,27 +27,27 @@
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 */ 33 */
34 34
35#include <sys/cdefs.h> 35#include <sys/cdefs.h>
36#ifndef lint 36#ifndef lint
37#if 0 37#if 0
38static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95"; 38static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95";
39#else 39#else
40__RCSID("$NetBSD: eval.c,v 1.160 2018/08/22 20:08:54 kre Exp $"); 40__RCSID("$NetBSD: eval.c,v 1.161 2018/08/25 02:42:49 kre Exp $");
41#endif 41#endif
42#endif /* not lint */ 42#endif /* not lint */
43 43
44#include <stdbool.h> 44#include <stdbool.h>
45#include <stdlib.h> 45#include <stdlib.h>
46#include <signal.h> 46#include <signal.h>
47#include <stdio.h> 47#include <stdio.h>
48#include <string.h> 48#include <string.h>
49#include <errno.h> 49#include <errno.h>
50#include <limits.h> 50#include <limits.h>
51#include <unistd.h> 51#include <unistd.h>
52#include <sys/fcntl.h> 52#include <sys/fcntl.h>
53#include <sys/stat.h> 53#include <sys/stat.h>
@@ -1075,27 +1075,28 @@ evalcommand(union node *cmd, int flgs, s @@ -1075,27 +1075,28 @@ evalcommand(union node *cmd, int flgs, s
1075 */ 1075 */
1076 SHELL_FORKED(); 1076 SHELL_FORKED();
1077 if (setjmp(jmploc.loc)) { 1077 if (setjmp(jmploc.loc)) {
1078 if (exception == EXSHELLPROC) { 1078 if (exception == EXSHELLPROC) {
1079 /* 1079 /*
1080 * We can't progress with the 1080 * We can't progress with the
1081 * vfork, so, set vforked = 2 1081 * vfork, so, set vforked = 2
1082 * so the parent knows, 1082 * so the parent knows,
1083 * and _exit(); 1083 * and _exit();
1084 */ 1084 */
1085 vforked = 2; 1085 vforked = 2;
1086 _exit(0); 1086 _exit(0);
1087 } else { 1087 } else {
1088 _exit(exerrno); 1088 _exit(exception == EXEXIT ?
 1089 exitstatus : exerrno);
1089 } 1090 }
1090 } 1091 }
1091 savehandler = handler; 1092 savehandler = handler;
1092 handler = &jmploc; 1093 handler = &jmploc;
1093 listmklocal(varlist.list, VEXPORT | VNOFUNC); 1094 listmklocal(varlist.list, VEXPORT | VNOFUNC);
1094 forkchild(jp, cmd, mode, vforked); 1095 forkchild(jp, cmd, mode, vforked);
1095 break; 1096 break;
1096 default: 1097 default:
1097 VFORK_UNDO(); 1098 VFORK_UNDO();
1098 /* restore from vfork(2) */ 1099 /* restore from vfork(2) */
1099 handler = savehandler; 1100 handler = savehandler;
1100 poplocalvars(); 1101 poplocalvars();
1101 localvars = savelocalvars; 1102 localvars = savelocalvars;