Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/sh When forking a child shell, arrange for errors/exit t...
details: https://anonhg.NetBSD.org/src/rev/baca49929d9c
branches: trunk
changeset: 837407:baca49929d9c
user: kre <kre%NetBSD.org@localhost>
date: Mon Dec 03 02:38:30 2018 +0000
description:
When forking a child shell, arrange for errors/exit to always unwind
to the main handler, rather than wherever the parent shell would go.
nb: not needed for vfork(), after vfork() we never go that path - which
is good or we'd be corrupting the parent's handler.
This allows the child to always exit (when it should) rather than being
caught up doing something else (and while it would eventually exit, the
status would be incorrect in some cases).
One test is:
sh -c 'trap "(! :) && echo BUG || echo nobug" EXIT'
from Martijn Dekker
Fix from FreeBSD (missed earlier).
XXX - 2b part of the 48875 pullup to -8
diffstat:
bin/sh/jobs.c | 9 ++++++---
bin/sh/main.c | 10 +++++-----
bin/sh/main.h | 3 ++-
3 files changed, 13 insertions(+), 9 deletions(-)
diffs (100 lines):
diff -r d01d2269e614 -r baca49929d9c bin/sh/jobs.c
--- a/bin/sh/jobs.c Mon Dec 03 00:12:22 2018 +0000
+++ b/bin/sh/jobs.c Mon Dec 03 02:38:30 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: jobs.c,v 1.102 2018/10/28 18:16:01 kre Exp $ */
+/* $NetBSD: jobs.c,v 1.103 2018/12/03 02:38:30 kre Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)jobs.c 8.5 (Berkeley) 5/4/95";
#else
-__RCSID("$NetBSD: jobs.c,v 1.102 2018/10/28 18:16:01 kre Exp $");
+__RCSID("$NetBSD: jobs.c,v 1.103 2018/12/03 02:38:30 kre Exp $");
#endif
#endif /* not lint */
@@ -1161,8 +1161,11 @@
wasroot = rootshell;
CTRACE(DBG_JOBS, ("Child shell %d %sforked from %d (mode %d)\n",
getpid(), vforked?"v":"", getppid(), mode));
- if (!vforked)
+
+ if (!vforked) {
rootshell = 0;
+ handler = &main_handler;
+ }
closescript(vforked);
clear_traps(vforked);
diff -r d01d2269e614 -r baca49929d9c bin/sh/main.c
--- a/bin/sh/main.c Mon Dec 03 00:12:22 2018 +0000
+++ b/bin/sh/main.c Mon Dec 03 02:38:30 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.76 2018/08/22 20:08:54 kre Exp $ */
+/* $NetBSD: main.c,v 1.77 2018/12/03 02:38:30 kre Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)main.c 8.7 (Berkeley) 7/19/95";
#else
-__RCSID("$NetBSD: main.c,v 1.76 2018/08/22 20:08:54 kre Exp $");
+__RCSID("$NetBSD: main.c,v 1.77 2018/12/03 02:38:30 kre Exp $");
#endif
#endif /* not lint */
@@ -83,6 +83,7 @@
int rootpid;
int rootshell;
+struct jmploc main_handler;
int max_user_fd;
#if PROFILE
short profile_buf[16384];
@@ -102,7 +103,6 @@
int
main(int argc, char **argv)
{
- struct jmploc jmploc;
struct stackmark smark;
volatile int state;
char *shinit;
@@ -123,7 +123,7 @@
monitor(4, etext, profile_buf, sizeof profile_buf, 50);
#endif
state = 0;
- if (setjmp(jmploc.loc)) {
+ if (setjmp(main_handler.loc)) {
/*
* When a shell procedure is executed, we raise the
* exception EXSHELLPROC to clean up before executing
@@ -170,7 +170,7 @@
else
goto state4;
}
- handler = &jmploc;
+ handler = &main_handler;
#ifdef DEBUG
#if DEBUG >= 2
debug = 1; /* this may be reset by procargs() later */
diff -r d01d2269e614 -r baca49929d9c bin/sh/main.h
--- a/bin/sh/main.h Mon Dec 03 00:12:22 2018 +0000
+++ b/bin/sh/main.h Mon Dec 03 02:38:30 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.h,v 1.11 2011/06/18 21:18:46 christos Exp $ */
+/* $NetBSD: main.h,v 1.12 2018/12/03 02:38:30 kre Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -36,6 +36,7 @@
extern int rootpid; /* pid of main shell */
extern int rootshell; /* true if we aren't a child of the main shell */
+extern struct jmploc main_handler; /* top level exception handler */
void readcmdfile(char *);
void cmdloop(int);
Home |
Main Index |
Thread Index |
Old Index