# HG changeset patch # User bears # Date 980420403 0 # Node ID 94f2e5607772752090562d87c8f2e7e040141172 # Parent 3d243292468dba35199185282ca321014c743c01 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up repeated signal handler setting code into Utl_installSignalHandler. * src/client.c: Ensure Client_retrieveArt always exits with the global lock held. Previously it would be held on error, not held if OK. diff -r 3d243292468d -r 94f2e5607772 src/client.c --- a/src/client.c Sun Jan 07 11:15:58 2001 +0000 +++ b/src/client.c Thu Jan 25 11:00:03 2001 +0000 @@ -1,7 +1,7 @@ /* client.c - $Id: client.c 240 2000-12-10 11:34:50Z enz $ + $Id: client.c 248 2001-01-25 11:00:03Z bears $ */ #if HAVE_CONFIG_H @@ -236,21 +236,6 @@ return; } -static sig_t -installSignalHandler( int sig, sig_t handler ) -{ - struct sigaction act, oldAct; - - act.sa_handler = handler; - sigemptyset( &act.sa_mask ); - act.sa_flags = 0; - if ( sig != SIGALRM ) - act.sa_flags |= SA_RESTART; - if ( sigaction( sig, &act, &oldAct ) < 0 ) - return SIG_ERR; - return oldAct.sa_handler; -} - static Bool connectWithTimeout( int sock, const struct sockaddr *servAddr, socklen_t addrLen ) @@ -258,7 +243,7 @@ sig_t oldHandler; int r, to; - oldHandler = installSignalHandler( SIGALRM, connectAlarm ); + oldHandler = Utl_installSignalHandler( SIGALRM, connectAlarm ); if ( oldHandler == SIG_ERR ) { Log_err( "client.c:connectWithTimeout: signal failed." ); @@ -269,7 +254,7 @@ Log_err( "client.c:connectWithTimeout: Alarm was already set." ); r = connect( sock, servAddr, addrLen ); alarm( 0 ); - installSignalHandler( SIGALRM, oldHandler ); + Utl_installSignalHandler( SIGALRM, oldHandler ); return ( r >= 0 ); } @@ -1100,6 +1085,7 @@ retrievingFailed( msgId, client.lastStat ); else retrieveAndStoreArt( msgId, 0, 0 ); + Lock_openDatabases(); } void diff -r 3d243292468d -r 94f2e5607772 src/protocol.c --- a/src/protocol.c Sun Jan 07 11:15:58 2001 +0000 +++ b/src/protocol.c Thu Jan 25 11:00:03 2001 +0000 @@ -1,7 +1,7 @@ /* protocol.c - $Id: protocol.c 228 2000-10-26 21:29:55Z bears $ + $Id: protocol.c 248 2001-01-25 11:00:03Z bears $ */ #if HAVE_CONFIG_H @@ -33,23 +33,6 @@ return; } -static sig_t -installSignalHandler( int sig, sig_t handler ) -{ - struct sigaction act, oldAct; - - act.sa_handler = handler; - sigemptyset( &act.sa_mask ); - act.sa_flags = 0; - if ( sig == SIGALRM ) - act.sa_flags |= SA_INTERRUPT; - else - act.sa_flags |= SA_RESTART; - if ( sigaction( sig, &act, &oldAct ) < 0 ) - return SIG_ERR; - return oldAct.sa_handler; -} - Bool Prt_getLn( Str line, FILE *f, int timeoutSeconds ) { @@ -59,7 +42,7 @@ if ( timeoutSeconds >= 0 ) { - oldHandler = installSignalHandler( SIGALRM, readAlarm ); + oldHandler = Utl_installSignalHandler( SIGALRM, readAlarm ); if ( oldHandler == SIG_ERR ) { Log_err( "Prt_getLn: signal failed." ); @@ -76,7 +59,7 @@ if ( timeoutSeconds >= 0 ) { alarm( 0 ); - installSignalHandler( SIGALRM, oldHandler ); + Utl_installSignalHandler( SIGALRM, oldHandler ); } if ( ret == NULL ) return FALSE; diff -r 3d243292468d -r 94f2e5607772 src/util.c --- a/src/util.c Sun Jan 07 11:15:58 2001 +0000 +++ b/src/util.c Thu Jan 25 11:00:03 2001 +0000 @@ -1,7 +1,7 @@ /* util.c - $Id: util.c 183 2000-07-25 12:14:54Z bears $ + $Id: util.c 248 2001-01-25 11:00:03Z bears $ */ #if HAVE_CONFIG_H @@ -462,6 +462,21 @@ memcpy( *dst, src, (size_t)len + 1 ); } +sig_t +Utl_installSignalHandler( int sig, sig_t handler ) +{ + struct sigaction act, oldAct; + + act.sa_handler = handler; + sigemptyset( &act.sa_mask ); + act.sa_flags = 0; + if ( sig != SIGALRM ) + act.sa_flags |= SA_RESTART; + if ( sigaction( sig, &act, &oldAct ) < 0 ) + return SIG_ERR; + return oldAct.sa_handler; +} + #if defined(UTIL_TEST) /* Test code borrowed from wildmat.c. Yep, still uses gets(). */ diff -r 3d243292468d -r 94f2e5607772 src/util.h --- a/src/util.h Sun Jan 07 11:15:58 2001 +0000 +++ b/src/util.h Thu Jan 25 11:00:03 2001 +0000 @@ -3,7 +3,7 @@ Miscellaneous helper functions. - $Id: util.h 110 2000-05-19 15:12:45Z bears $ + $Id: util.h 248 2001-01-25 11:00:03Z bears $ */ #ifndef UTL_H @@ -13,6 +13,8 @@ #include #endif +#include + #if TIME_WITH_SYS_TIME #include #include @@ -100,4 +102,8 @@ void Utl_allocAndCpy( char **dst, const char *src ); +/* Install signal handler. */ +sig_t +Utl_installSignalHandler( int sig, sig_t handler ); + #endif