From 64578c0589a3a741f81fb55c16eeb882128da00b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 29 Jul 1998 03:08:05 +0000 Subject: merge from the autoconf2 branch to the main branch (This used to be commit 3bda7ac417107a7b01d91805ca71c4330657ed21) --- source3/lib/signal.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 source3/lib/signal.c (limited to 'source3/lib/signal.c') diff --git a/source3/lib/signal.c b/source3/lib/signal.c new file mode 100644 index 0000000000..8f6f5a9cd4 --- /dev/null +++ b/source3/lib/signal.c @@ -0,0 +1,102 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + signal handling functions + + Copyright (C) Andrew Tridgell 1998 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + + +/**************************************************************************** +catch child exits +****************************************************************************/ +static void sig_cld(int signum) +{ + while (sys_waitpid((pid_t)-1,(int *)NULL, WNOHANG) > 0) ; + + CatchSignal(SIGCLD, SIG_IGN); +} + + + +/******************************************************************* +block sigs +********************************************************************/ +void BlockSignals(BOOL block,int signum) +{ +#ifdef HAVE_SIGPROCMASK + sigset_t set; + sigemptyset(&set); + sigaddset(&set,signum); + sigprocmask(block?SIG_BLOCK:SIG_UNBLOCK,&set,NULL); +#elif defined(HAVE_SIGBLOCK) + int block_mask = sigmask(signum); + static int oldmask = 0; + if (block) { + oldmask = sigblock(block_mask); + } else { + sigsetmask(oldmask); + } +#else + /* yikes! This platform can't block signals? */ + static int done; + if (!done) { + DEBUG(0,("WARNING: No signal blocking available\n")); + done=1; + } +#endif +} + + + +/******************************************************************* +catch a signal. This should implement the following semantics: + +1) the handler remains installed after being called +2) the signal should be blocked during handler execution +********************************************************************/ +void CatchSignal(int signum,void (*handler)(int )) +{ +#ifdef HAVE_SIGACTION + struct sigaction act; + + memset(&act, 0, sizeof(act)); + + act.sa_handler = handler; +#ifdef SA_RESTART + act.sa_flags = SA_RESTART; +#endif + sigemptyset(&act.sa_mask); + sigaddset(&act.sa_mask,signum); + sigaction(signum,&act,NULL); +#else + /* FIXME: need to handle sigvec and systems with broken signal() */ + signal(signum, handler); +#endif +} + + + +/******************************************************************* +ignore SIGCLD via whatever means is necessary for this OS +********************************************************************/ +void CatchChild(void) +{ + CatchSignal(SIGCLD, sig_cld); +} -- cgit From b29514427364105ba6286ad688d61444eafb22ea Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 30 Aug 1998 12:32:45 +0000 Subject: This should fix the zombie problem that luke noticed. (This used to be commit 425ccf9271ea44879d0940b9d95ae9b8f95aa092) --- source3/lib/signal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/signal.c') diff --git a/source3/lib/signal.c b/source3/lib/signal.c index 8f6f5a9cd4..db72b458a7 100644 --- a/source3/lib/signal.c +++ b/source3/lib/signal.c @@ -30,7 +30,7 @@ static void sig_cld(int signum) { while (sys_waitpid((pid_t)-1,(int *)NULL, WNOHANG) > 0) ; - CatchSignal(SIGCLD, SIG_IGN); + CatchSignal(SIGCLD, sig_cld); } -- cgit From f6044c87c021342d68d614d59bc8dacd32d223b9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 5 Sep 1998 13:24:20 +0000 Subject: some cleanups to use ZERO_STRUCT() and friends (This used to be commit 7b154dc4313324dfad6cf0117b8ce246bf12bf16) --- source3/lib/signal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/signal.c') diff --git a/source3/lib/signal.c b/source3/lib/signal.c index db72b458a7..bb1c6fe189 100644 --- a/source3/lib/signal.c +++ b/source3/lib/signal.c @@ -76,7 +76,7 @@ void CatchSignal(int signum,void (*handler)(int )) #ifdef HAVE_SIGACTION struct sigaction act; - memset(&act, 0, sizeof(act)); + ZERO_STRUCT(act); act.sa_handler = handler; #ifdef SA_RESTART -- cgit From 3db52feb1f3b2c07ce0b06ad4a7099fa6efe3fc7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 13 Dec 1999 13:27:58 +0000 Subject: first pass at updating head branch to be to be the same as the SAMBA_2_0 branch (This used to be commit 453a822a76780063dff23526c35408866d0c0154) --- source3/lib/signal.c | 68 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 14 deletions(-) (limited to 'source3/lib/signal.c') diff --git a/source3/lib/signal.c b/source3/lib/signal.c index bb1c6fe189..5651e942d7 100644 --- a/source3/lib/signal.c +++ b/source3/lib/signal.c @@ -22,22 +22,51 @@ #include "includes.h" - /**************************************************************************** -catch child exits + Catch child exits and reap the child zombie status. ****************************************************************************/ + static void sig_cld(int signum) { - while (sys_waitpid((pid_t)-1,(int *)NULL, WNOHANG) > 0) ; + while (sys_waitpid((pid_t)-1,(int *)NULL, WNOHANG) > 0) + ; + + /* + * Turns out it's *really* important not to + * restore the signal handler here if we have real POSIX + * signal handling. If we do, then we get the signal re-delivered + * immediately - hey presto - instant loop ! JRA. + */ +#if !defined(HAVE_SIGACTION) CatchSignal(SIGCLD, sig_cld); +#endif } +/**************************************************************************** +catch child exits - leave status; +****************************************************************************/ +static void sig_cld_leave_status(int signum) +{ + /* + * Turns out it's *really* important not to + * restore the signal handler here if we have real POSIX + * signal handling. If we do, then we get the signal re-delivered + * immediately - hey presto - instant loop ! JRA. + */ + +#if !defined(HAVE_SIGACTION) + CatchSignal(SIGCLD, sig_cld_leave_status); +#else + ; +#endif +} /******************************************************************* -block sigs + Block sigs. ********************************************************************/ + void BlockSignals(BOOL block,int signum) { #ifdef HAVE_SIGPROCMASK @@ -63,14 +92,13 @@ void BlockSignals(BOOL block,int signum) #endif } - - /******************************************************************* -catch a signal. This should implement the following semantics: + Catch a signal. This should implement the following semantics: -1) the handler remains installed after being called -2) the signal should be blocked during handler execution + 1) The handler remains installed after being called. + 2) The signal should be blocked during handler execution. ********************************************************************/ + void CatchSignal(int signum,void (*handler)(int )) { #ifdef HAVE_SIGACTION @@ -80,23 +108,35 @@ void CatchSignal(int signum,void (*handler)(int )) act.sa_handler = handler; #ifdef SA_RESTART - act.sa_flags = SA_RESTART; + /* + * We *want* SIGALRM to interrupt a system call. + */ + if(signum != SIGALRM) + act.sa_flags = SA_RESTART; #endif sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask,signum); sigaction(signum,&act,NULL); -#else +#else /* !HAVE_SIGACTION */ /* FIXME: need to handle sigvec and systems with broken signal() */ signal(signum, handler); #endif } - - /******************************************************************* -ignore SIGCLD via whatever means is necessary for this OS + Ignore SIGCLD via whatever means is necessary for this OS. ********************************************************************/ + void CatchChild(void) { CatchSignal(SIGCLD, sig_cld); } + +/******************************************************************* + Catch SIGCLD but leave the child around so it's status can be reaped. +********************************************************************/ + +void CatchChildLeaveStatus(void) +{ + CatchSignal(SIGCLD, sig_cld_leave_status); +} -- cgit From 6de513cef43ad83ecd1823bde5a4e05c22224b0f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 12 Jun 2000 06:09:39 +0000 Subject: fixed a bug in BlockSignals() for systems that don't have sigprocmask() (This used to be commit abf06fa90ba49f6a1ec5458d056f8b8cf20b6512) --- source3/lib/signal.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source3/lib/signal.c') diff --git a/source3/lib/signal.c b/source3/lib/signal.c index 5651e942d7..9c78fad886 100644 --- a/source3/lib/signal.c +++ b/source3/lib/signal.c @@ -75,12 +75,10 @@ void BlockSignals(BOOL block,int signum) sigaddset(&set,signum); sigprocmask(block?SIG_BLOCK:SIG_UNBLOCK,&set,NULL); #elif defined(HAVE_SIGBLOCK) - int block_mask = sigmask(signum); - static int oldmask = 0; if (block) { - oldmask = sigblock(block_mask); + sigblock(sigmask(signum)); } else { - sigsetmask(oldmask); + sigsetmask(siggetmask() & ~sigmask(signum)); } #else /* yikes! This platform can't block signals? */ -- cgit From cd68afe31256ad60748b34f7318a180cfc2127cc Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 30 Jan 2002 06:08:46 +0000 Subject: Removed version number from file header. Changed "SMB/Netbios" to "SMB/CIFS" in file header. (This used to be commit 6a58c9bd06d0d7502a24bf5ce5a2faf0a146edfa) --- source3/lib/signal.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/signal.c') diff --git a/source3/lib/signal.c b/source3/lib/signal.c index 9c78fad886..99f908235c 100644 --- a/source3/lib/signal.c +++ b/source3/lib/signal.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. signal handling functions Copyright (C) Andrew Tridgell 1998 -- cgit From e90b65284812aaa5ff9e9935ce9bbad7791cbbcd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 15 Jul 2002 10:35:28 +0000 Subject: updated the 3.0 branch from the head branch - ready for alpha18 (This used to be commit 03ac082dcb375b6f3ca3d810a6a6367542bc23ce) --- source3/lib/signal.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source3/lib/signal.c') diff --git a/source3/lib/signal.c b/source3/lib/signal.c index 99f908235c..dceb3b53bc 100644 --- a/source3/lib/signal.c +++ b/source3/lib/signal.c @@ -96,10 +96,11 @@ void BlockSignals(BOOL block,int signum) 2) The signal should be blocked during handler execution. ********************************************************************/ -void CatchSignal(int signum,void (*handler)(int )) +void (*CatchSignal(int signum,void (*handler)(int )))(int) { #ifdef HAVE_SIGACTION struct sigaction act; + struct sigaction oldact; ZERO_STRUCT(act); @@ -113,10 +114,11 @@ void CatchSignal(int signum,void (*handler)(int )) #endif sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask,signum); - sigaction(signum,&act,NULL); + sigaction(signum,&act,&oldact); + return oldact.sa_handler; #else /* !HAVE_SIGACTION */ /* FIXME: need to handle sigvec and systems with broken signal() */ - signal(signum, handler); + return signal(signum, handler); #endif } -- cgit From d645041d6345ff2802dd2f06ebed1d8f456fee23 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 14 Jan 2003 08:26:54 +0000 Subject: Merge from HEAD: - remove useless #else - signed/unsigned fixes - use an fstring for LM hash buffer. Andrew Bartlett (This used to be commit c0fb53c31fd7341745d14640e761affc5dae5230) --- source3/lib/signal.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/lib/signal.c') diff --git a/source3/lib/signal.c b/source3/lib/signal.c index dceb3b53bc..bff4b91c1a 100644 --- a/source3/lib/signal.c +++ b/source3/lib/signal.c @@ -57,8 +57,6 @@ static void sig_cld_leave_status(int signum) #if !defined(HAVE_SIGACTION) CatchSignal(SIGCLD, sig_cld_leave_status); -#else - ; #endif } -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/lib/signal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/signal.c') diff --git a/source3/lib/signal.c b/source3/lib/signal.c index bff4b91c1a..825cc973a0 100644 --- a/source3/lib/signal.c +++ b/source3/lib/signal.c @@ -6,7 +6,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/lib/signal.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/signal.c') diff --git a/source3/lib/signal.c b/source3/lib/signal.c index 825cc973a0..4d4e9555db 100644 --- a/source3/lib/signal.c +++ b/source3/lib/signal.c @@ -15,8 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/lib/signal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/signal.c') diff --git a/source3/lib/signal.c b/source3/lib/signal.c index 4d4e9555db..4b1c95eb77 100644 --- a/source3/lib/signal.c +++ b/source3/lib/signal.c @@ -63,7 +63,7 @@ static void sig_cld_leave_status(int signum) Block sigs. ********************************************************************/ -void BlockSignals(BOOL block,int signum) +void BlockSignals(bool block,int signum) { #ifdef HAVE_SIGPROCMASK sigset_t set; -- cgit