Mercurial > noffle
comparison src/protocol.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 | cb799054bd61 |
children | fed1334d766b |
comparison
equal
deleted
inserted
replaced
163:3d243292468d | 164:94f2e5607772 |
---|---|
1 /* | 1 /* |
2 protocol.c | 2 protocol.c |
3 | 3 |
4 $Id: protocol.c 228 2000-10-26 21:29:55Z bears $ | 4 $Id: protocol.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 |
31 UNUSED( sig ); | 31 UNUSED( sig ); |
32 | 32 |
33 return; | 33 return; |
34 } | 34 } |
35 | 35 |
36 static sig_t | |
37 installSignalHandler( int sig, sig_t handler ) | |
38 { | |
39 struct sigaction act, oldAct; | |
40 | |
41 act.sa_handler = handler; | |
42 sigemptyset( &act.sa_mask ); | |
43 act.sa_flags = 0; | |
44 if ( sig == SIGALRM ) | |
45 act.sa_flags |= SA_INTERRUPT; | |
46 else | |
47 act.sa_flags |= SA_RESTART; | |
48 if ( sigaction( sig, &act, &oldAct ) < 0 ) | |
49 return SIG_ERR; | |
50 return oldAct.sa_handler; | |
51 } | |
52 | |
53 Bool | 36 Bool |
54 Prt_getLn( Str line, FILE *f, int timeoutSeconds ) | 37 Prt_getLn( Str line, FILE *f, int timeoutSeconds ) |
55 { | 38 { |
56 size_t len; | 39 size_t len; |
57 char *ret; | 40 char *ret; |
58 sig_t oldHandler = NULL; | 41 sig_t oldHandler = NULL; |
59 | 42 |
60 if ( timeoutSeconds >= 0 ) | 43 if ( timeoutSeconds >= 0 ) |
61 { | 44 { |
62 oldHandler = installSignalHandler( SIGALRM, readAlarm ); | 45 oldHandler = Utl_installSignalHandler( SIGALRM, readAlarm ); |
63 if ( oldHandler == SIG_ERR ) | 46 if ( oldHandler == SIG_ERR ) |
64 { | 47 { |
65 Log_err( "Prt_getLn: signal failed." ); | 48 Log_err( "Prt_getLn: signal failed." ); |
66 return FALSE; | 49 return FALSE; |
67 } | 50 } |
74 */ | 57 */ |
75 ret = fgets( line, MAXCHAR, f ); | 58 ret = fgets( line, MAXCHAR, f ); |
76 if ( timeoutSeconds >= 0 ) | 59 if ( timeoutSeconds >= 0 ) |
77 { | 60 { |
78 alarm( 0 ); | 61 alarm( 0 ); |
79 installSignalHandler( SIGALRM, oldHandler ); | 62 Utl_installSignalHandler( SIGALRM, oldHandler ); |
80 } | 63 } |
81 if ( ret == NULL ) | 64 if ( ret == NULL ) |
82 return FALSE; | 65 return FALSE; |
83 len = strlen( line ); | 66 len = strlen( line ); |
84 if ( len > 0 && line[ len - 1 ] == '\n' ) | 67 if ( len > 0 && line[ len - 1 ] == '\n' ) |