comparison src/client.c @ 164:94f2e5607772 noffle

[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.
author bears
date Thu, 25 Jan 2001 11:00:03 +0000
parents 976ff791c7ec
children 0ce333d046b9
comparison
equal deleted inserted replaced
163:3d243292468d 164:94f2e5607772
1 /* 1 /*
2 client.c 2 client.c
3 3
4 $Id: client.c 240 2000-12-10 11:34:50Z enz $ 4 $Id: client.c 248 2001-01-25 11:00:03Z bears $
5 */ 5 */
6 6
7 #if HAVE_CONFIG_H 7 #if HAVE_CONFIG_H
8 #include <config.h> 8 #include <config.h>
9 #endif 9 #endif
234 UNUSED( sig ); 234 UNUSED( sig );
235 235
236 return; 236 return;
237 } 237 }
238 238
239 static sig_t
240 installSignalHandler( int sig, sig_t handler )
241 {
242 struct sigaction act, oldAct;
243
244 act.sa_handler = handler;
245 sigemptyset( &act.sa_mask );
246 act.sa_flags = 0;
247 if ( sig != SIGALRM )
248 act.sa_flags |= SA_RESTART;
249 if ( sigaction( sig, &act, &oldAct ) < 0 )
250 return SIG_ERR;
251 return oldAct.sa_handler;
252 }
253
254 static Bool 239 static Bool
255 connectWithTimeout( int sock, const struct sockaddr *servAddr, 240 connectWithTimeout( int sock, const struct sockaddr *servAddr,
256 socklen_t addrLen ) 241 socklen_t addrLen )
257 { 242 {
258 sig_t oldHandler; 243 sig_t oldHandler;
259 int r, to; 244 int r, to;
260 245
261 oldHandler = installSignalHandler( SIGALRM, connectAlarm ); 246 oldHandler = Utl_installSignalHandler( SIGALRM, connectAlarm );
262 if ( oldHandler == SIG_ERR ) 247 if ( oldHandler == SIG_ERR )
263 { 248 {
264 Log_err( "client.c:connectWithTimeout: signal failed." ); 249 Log_err( "client.c:connectWithTimeout: signal failed." );
265 return FALSE; 250 return FALSE;
266 } 251 }
267 to = Cfg_connectTimeout(); 252 to = Cfg_connectTimeout();
268 if ( alarm( ( unsigned int ) to ) != 0 ) 253 if ( alarm( ( unsigned int ) to ) != 0 )
269 Log_err( "client.c:connectWithTimeout: Alarm was already set." ); 254 Log_err( "client.c:connectWithTimeout: Alarm was already set." );
270 r = connect( sock, servAddr, addrLen ); 255 r = connect( sock, servAddr, addrLen );
271 alarm( 0 ); 256 alarm( 0 );
272 installSignalHandler( SIGALRM, oldHandler ); 257 Utl_installSignalHandler( SIGALRM, oldHandler );
273 return ( r >= 0 ); 258 return ( r >= 0 );
274 } 259 }
275 260
276 static DynStr * 261 static DynStr *
277 collectTxt( void ) 262 collectTxt( void )
1098 retrievingFailed( msgId, "Connection broke down" ); 1083 retrievingFailed( msgId, "Connection broke down" );
1099 else if ( getStat() != STAT_ART_FOLLOWS ) 1084 else if ( getStat() != STAT_ART_FOLLOWS )
1100 retrievingFailed( msgId, client.lastStat ); 1085 retrievingFailed( msgId, client.lastStat );
1101 else 1086 else
1102 retrieveAndStoreArt( msgId, 0, 0 ); 1087 retrieveAndStoreArt( msgId, 0, 0 );
1088 Lock_openDatabases();
1103 } 1089 }
1104 1090
1105 void 1091 void
1106 Client_retrieveArtList( const char *list, int *artcnt, int artmax ) 1092 Client_retrieveArtList( const char *list, int *artcnt, int artmax )
1107 { 1093 {