From 4df4394aaae2b718b347c4d0b1804e1d294e5f56 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 12 Feb 2009 02:42:25 -0500 Subject: 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 Reported-by: Ken Bloom --- src/sandbox.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src') 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; -- cgit v1.2.3-65-gdbad