NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: bin/36079
The following reply was made to PR bin/36079; it has been noted by GNATS.
From: Jilles Tjoelker <jilles%stack.nl@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc:
Subject: Re: bin/36079
Date: Fri, 12 Jun 2009 00:00:51 +0200
--pWyiEgJYm5f9v55/
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
A patch similar to
http://www.stack.nl/~jilles/unix/sh-forkiftrapped.patch
should fix this properly, keeping the shell running if there are any
traps set. I have run with this on FreeBSD for quite a while and have
not noticed problems, although it hasn't been committed yet.
It will need to be changed slightly because NetBSD doesn't have the -T
option (immediate traps).
--
Jilles Tjoelker
--pWyiEgJYm5f9v55/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="sh-forkiftrapped.patch"
Don't skip forking for an external command if any traps are active.
Example:
sh -c '(trap "echo trapped" EXIT; sleep 3)'
now correctly prints "trapped".
With this check, it is no longer necessary to check for -T
explicitly in that case.
diff --git a/eval.c b/eval.c
--- a/eval.c
+++ b/eval.c
@@ -730,7 +730,7 @@ evalcommand(union node *cmd, int flags,
/* Fork off a child process if necessary. */
if (cmd->ncmd.backgnd
|| (cmdentry.cmdtype == CMDNORMAL
- && ((flags & EV_EXIT) == 0 || Tflag))
+ && ((flags & EV_EXIT) == 0 || have_traps()))
|| ((flags & EV_BACKCMD) != 0
&& (cmdentry.cmdtype != CMDBUILTIN
|| cmdentry.u.index == CDCMD
diff --git a/trap.c b/trap.c
--- a/trap.c
+++ b/trap.c
@@ -222,6 +222,21 @@ clear_traps(void)
/*
+ * Check if we have any traps enabled.
+ */
+int
+have_traps(void)
+{
+ char *volatile *tp;
+
+ for (tp = trap ; tp <= &trap[NSIG - 1] ; tp++) {
+ if (*tp && **tp) /* trap not NULL or SIG_IGN */
+ return 1;
+ }
+ return 0;
+}
+
+/*
* Set the signal handler for the specified signal. The routine figures
* out what it should be set to.
*/
diff --git a/trap.h b/trap.h
--- a/trap.h
+++ b/trap.h
@@ -39,6 +39,7 @@ extern volatile sig_atomic_t gotwinch;
int trapcmd(int, char **);
void clear_traps(void);
+int have_traps(void);
void setsignal(int);
void ignoresig(int);
void onsig(int);
--pWyiEgJYm5f9v55/--
Home |
Main Index |
Thread Index |
Old Index