From d179b191794c06626375692ea81c1931db57f550 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 13 Jun 2002 22:49:13 +0000 Subject: Ensure we save any older SIGALRM signal handler. Jeremy. (This used to be commit aa0a6f5532a2689409426eef9a4b66a28fb97635) --- source3/lib/messages.c | 5 +++-- source3/lib/signal.c | 8 +++++--- source3/lib/util_file.c | 5 +++-- 3 files changed, 11 insertions(+), 7 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/messages.c b/source3/lib/messages.c index 3929f526dc1..5d861b485cf 100644 --- a/source3/lib/messages.c +++ b/source3/lib/messages.c @@ -475,6 +475,7 @@ BOOL message_named_mutex(char *name, unsigned int timeout) { TDB_DATA key; int ret; + void (*oldsig_handler)(int); if (!message_init()) return False; @@ -484,7 +485,7 @@ BOOL message_named_mutex(char *name, unsigned int timeout) if (timeout) { gotalarm = 0; - CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig); + oldsig_handler = CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig); alarm(timeout); } @@ -492,7 +493,7 @@ BOOL message_named_mutex(char *name, unsigned int timeout) if (timeout) { alarm(0); - CatchSignal(SIGALRM, SIGNAL_CAST SIG_IGN); + CatchSignal(SIGALRM, SIGNAL_CAST oldsig_handler); if (gotalarm) return False; } diff --git a/source3/lib/signal.c b/source3/lib/signal.c index 99f908235c4..dceb3b53bce 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 } diff --git a/source3/lib/util_file.c b/source3/lib/util_file.c index fd3aeb99d9e..883827a4f5f 100644 --- a/source3/lib/util_file.c +++ b/source3/lib/util_file.c @@ -40,9 +40,10 @@ BOOL do_file_lock(int fd, int waitsecs, int type) { SMB_STRUCT_FLOCK lock; int ret; + void (*oldsig_handler)(int); gotalarm = 0; - CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig); + oldsig_handler = CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig); lock.l_type = type; lock.l_whence = SEEK_SET; @@ -54,7 +55,7 @@ BOOL do_file_lock(int fd, int waitsecs, int type) /* Note we must *NOT* use sys_fcntl here ! JRA */ ret = fcntl(fd, SMB_F_SETLKW, &lock); alarm(0); - CatchSignal(SIGALRM, SIGNAL_CAST SIG_IGN); + CatchSignal(SIGALRM, SIGNAL_CAST oldsig_handler); if (gotalarm) { DEBUG(0, ("do_file_lock: failed to %s file.\n", -- cgit