From 7decb9c312312e3869ccb7439115644dc95ed665 Mon Sep 17 00:00:00 2001 From: jilles Date: Sat, 13 Jun 2009 21:10:41 +0000 Subject: 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. This is a useful bugfix by itself and also important because I plan to skip forking more often. PR: bin/113860 (part of) PR: bin/74404 (part of) Reviewed by: stefanf Approved by: ed (mentor) --- bin/sh/trap.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'bin/sh/trap.c') diff --git a/bin/sh/trap.c b/bin/sh/trap.c index 099dc11..a0cd0ba 100644 --- a/bin/sh/trap.c +++ b/bin/sh/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. */ -- cgit v1.1