aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2009-02-12 02:42:25 -0500
committerMike Frysinger <vapier@gentoo.org>2009-02-12 03:07:16 -0500
commit4df4394aaae2b718b347c4d0b1804e1d294e5f56 (patch)
treee7ec2b19ed55431455bc817da884cc36f64c8593 /src
parentadd testcase for old PATH bug (diff)
downloadsandbox-4df4394aaae2b718b347c4d0b1804e1d294e5f56.tar.gz
sandbox-4df4394aaae2b718b347c4d0b1804e1d294e5f56.tar.bz2
sandbox-4df4394aaae2b718b347c4d0b1804e1d294e5f56.zip
sandbox: check signal returns and allow SIGHUP to be ignored
If the SIGHUP signal is already set to SIG_IGN, then do not replace it with our own handler as most likely this means the user is using `nohup`. As for the other signals, check the return value and warn if something weird happens (like they aren't all set to SIG_DFL). URL: http://bugs.gentoo.org/217898 Signed-off-by: Mike Frysinger <vapier@gentoo.org> Reported-by: Ken Bloom <kbloom@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/sandbox.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/sandbox.c b/src/sandbox.c
index 3c782ca..87444cf 100644
--- a/src/sandbox.c
+++ b/src/sandbox.c
@@ -302,11 +302,22 @@ int main(int argc, char **argv)
}
}
- /* set up the required signal handlers */
- signal(SIGHUP, &stop);
- signal(SIGINT, &stop);
- signal(SIGQUIT, &stop);
- signal(SIGTERM, &stop);
+ /* set up the required signal handlers ... but allow SIGHUP to be
+ * ignored in case people are running `nohup ...` #217898
+ */
+ if (signal(SIGHUP, &stop) == SIG_IGN)
+ signal(SIGHUP, SIG_IGN);
+#define wsignal(sig, act) \
+ do { \
+ sighandler_t _old = signal(sig, act); \
+ if (_old == SIG_ERR) \
+ sb_pwarn("unable to bind signal %s\n", #sig); \
+ else if (_old != SIG_DFL) \
+ sb_warn("signal %s already had a handler ...\n", #sig); \
+ } while (0)
+ wsignal(SIGINT, &stop);
+ wsignal(SIGQUIT, &stop);
+ wsignal(SIGTERM, &stop);
act_new.sa_sigaction = usr1_handler;
sigemptyset (&act_new.sa_mask);
act_new.sa_flags = SA_SIGINFO | SA_RESTART;