summaryrefslogtreecommitdiffstats
path: root/bin/sh/trap.c
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2009-06-13 21:10:41 +0000
committerjilles <jilles@FreeBSD.org>2009-06-13 21:10:41 +0000
commit7decb9c312312e3869ccb7439115644dc95ed665 (patch)
tree4f076f4b21a2e29a81466aef9594ef539a2c56ed /bin/sh/trap.c
parent595149bf9031d68f18bb15236b09e76d0d4abf10 (diff)
downloadFreeBSD-src-7decb9c312312e3869ccb7439115644dc95ed665.zip
FreeBSD-src-7decb9c312312e3869ccb7439115644dc95ed665.tar.gz
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)
Diffstat (limited to 'bin/sh/trap.c')
-rw-r--r--bin/sh/trap.c15
1 files changed, 15 insertions, 0 deletions
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.
*/
OpenPOWER on IntegriCloud