From 3ae239d78642fd14d1b256a9c8f54bca5038623f Mon Sep 17 00:00:00 2001 From: lukem Date: Wed, 18 Jul 2007 01:32:33 +0000 Subject: [PATCH] Attempt to raise the default signal handler (SIG_DFL) when exiting because of a signal, rather than just relying upon _exit(2). --- usr.bin/csplit/csplit.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/usr.bin/csplit/csplit.c b/usr.bin/csplit/csplit.c index 6f9e7e08a6d5..15b0dc52136c 100644 --- a/usr.bin/csplit/csplit.c +++ b/usr.bin/csplit/csplit.c @@ -1,4 +1,4 @@ -/* $NetBSD: csplit.c,v 1.1 2006/09/25 19:21:42 christos Exp $ */ +/* $NetBSD: csplit.c,v 1.2 2007/07/18 01:32:33 lukem Exp $ */ /* $FreeBSD: src/usr.bin/csplit/csplit.c,v 1.9 2004/03/22 11:15:03 tjr Exp$ */ /*- @@ -47,7 +47,7 @@ #include #ifndef lint -__RCSID("$NetBSD: csplit.c,v 1.1 2006/09/25 19:21:42 christos Exp $"); +__RCSID("$NetBSD: csplit.c,v 1.2 2007/07/18 01:32:33 lukem Exp $"); #endif #include @@ -228,12 +228,24 @@ handlesig(int sig) { char msg[BUFSIZ]; size_t len; + struct sigaction n_hand; + sigset_t n_mask; len = snprintf(msg, sizeof(msg), "%s: Caught %s, cleaning up\n", getprogname(), strsignal(sig)); if (len < sizeof(msg)) (void)write(STDERR_FILENO, msg, len); cleanup(); + /* Reset to default signal handler, clear mask, raise signal */ + memset(&n_hand, 0, sizeof n_hand); + sigemptyset(&n_hand.sa_mask); + n_hand.sa_handler = SIG_DFL; + if ((sigaction(sig, &n_hand, NULL) == 0) && + (sigemptyset(&n_mask) == 0) && + (sigaddset(&n_mask, sig) == 0) && + (sigprocmask(SIG_UNBLOCK, &n_mask, 0) == 0)) { + raise(sig); + } _exit(2); }