diff options
author | 2006-10-19 02:44:38 +1000 | |
---|---|---|
committer | 2006-10-19 02:44:38 +1000 | |
commit | bab168f1d1c0db1b1a9aba208a87380616ac0850 (patch) | |
tree | 29d7ae23e5460ccc470c6baf099dab152908da73 | |
parent | 2ab04f40437537a96bb11fcbe7ffd0ed3ee8e8d7 (diff) |
Fix yet another universal variable issue with initialization of the read buffer. This may fix fishd bugs reported by Philip Ganchev and Martin Bähr
darcs-hash:20061018164438-ac50b-c586b1ad36249853d613d0137b505377fe890d37.gz
-rw-r--r-- | env.c | 2 | ||||
-rw-r--r-- | env_universal.c | 22 | ||||
-rw-r--r-- | env_universal_common.c | 19 | ||||
-rw-r--r-- | env_universal_common.h | 3 | ||||
-rw-r--r-- | fishd.c | 31 |
5 files changed, 42 insertions, 35 deletions
@@ -59,7 +59,7 @@ /** Command used to start fishd */ -#define FISHD_CMD L"if which fishd 2>/dev/null >/dev/null; fishd ^/tmp/fishd.log.%s; end" +#define FISHD_CMD L"fishd ^/tmp/fishd.log.%s" /** Value denoting a null string diff --git a/env_universal.c b/env_universal.c index f686e684..c3e5cd90 100644 --- a/env_universal.c +++ b/env_universal.c @@ -193,7 +193,7 @@ static void check_connection() env_universal_server.fd = -1; env_universal_server.killme=0; - sb_clear( &env_universal_server.input ); + env_universal_server.input.used=0; env_universal_read_all(); } } @@ -230,15 +230,11 @@ void env_universal_init( wchar_t * p, user=u; start_fishd=sf; external_callback = cb; - - memset (&env_universal_server, 0, sizeof (connection_t)); - env_universal_server.fd = -1; - env_universal_server.killme = 0; + connection_init( &env_universal_server, -1 ); + env_universal_server.fd = get_socket(1); - q_init( &env_universal_server.unsent ); env_universal_common_init( &callback ); - b_init( &env_universal_server.input ); env_universal_read_all(); init = 1; if( env_universal_server.fd >= 0 ) @@ -258,17 +254,11 @@ void env_universal_destroy() { wperror( L"fcntl" ); } - try_send_all( &env_universal_server ); - - if( close( env_universal_server.fd ) ) - { - wperror( L"close" ); - } + try_send_all( &env_universal_server ); } - + + connection_destroy( &env_universal_server ); env_universal_server.fd =-1; - q_destroy( &env_universal_server.unsent ); - sb_destroy( &env_universal_server.input ); env_universal_common_destroy(); init = 0; } diff --git a/env_universal_common.c b/env_universal_common.c index b13b96c4..80f7119e 100644 --- a/env_universal_common.c +++ b/env_universal_common.c @@ -837,3 +837,22 @@ void enqueue_all( connection_t *c ) try_send_all( c ); } + +void connection_init( connection_t *c, int fd ) +{ + memset (c, 0, sizeof (connection_t)); + c->fd = fd; + b_init( &c->input ); + q_init( &c->unsent ); + c->buffer_consumed = c->buffer_used = 0; +} + +void connection_destroy( connection_t *c) +{ + q_destroy( &c->unsent ); + b_destroy( &c->input ); + if( close( c->fd ) ) + { + wperror( L"close" ); + } +} diff --git a/env_universal_common.h b/env_universal_common.h index 43ed5d48..21550a0f 100644 --- a/env_universal_common.h +++ b/env_universal_common.h @@ -164,5 +164,8 @@ int env_universal_common_get_export( const wchar_t *name ); */ void enqueue_all( connection_t *c ); +void connection_init( connection_t *c, int fd ); +void connection_destroy( connection_t *c); + #endif @@ -391,13 +391,14 @@ static void daemonize() /** Load or save all variables */ -void load_or_save( int save) +static void load_or_save( int save) { struct passwd *pw; char *name; char *dir = getenv( "HOME" ); char hostname[HOSTNAME_LEN]; connection_t c; + int fd; if( !dir ) { @@ -417,10 +418,11 @@ void load_or_save( int save) save?"saving":"loading", name ); - c.fd = open( name, save?(O_CREAT | O_TRUNC | O_WRONLY):O_RDONLY, 0600); + fd = open( name, save?(O_CREAT | O_TRUNC | O_WRONLY):O_RDONLY, 0600); + free( name ); - if( c.fd == -1 ) + if( fd == -1 ) { debug( 1, L"Could not open load/save file. No previous saves?" ); wperror( L"open" ); @@ -428,8 +430,7 @@ void load_or_save( int save) } debug( 4, L"File open on fd %d", c.fd ); - b_init( &c.input ); - q_init( &c.unsent ); + connection_init( &c, fd ); if( save ) { @@ -440,9 +441,7 @@ void load_or_save( int save) else read_message( &c ); - q_destroy( &c.unsent ); - sb_destroy( &c.input ); - close( c.fd ); + connection_destroy( &c ); } /** @@ -548,7 +547,7 @@ int main( int argc, char ** argv ) connection_t *c; int res; - t=sizeof( remote ); + t = sizeof( remote ); FD_ZERO( &read_fd ); FD_ZERO( &write_fd ); @@ -605,12 +604,9 @@ int main( int argc, char ** argv ) } else { - connection_t *new = calloc( 1, sizeof(connection_t)); - new->fd = child_socket; + connection_t *new = malloc( sizeof(connection_t)); + connection_init( new, child_socket ); new->next = conn; - q_init( &new->unsent ); - new->killme=0; - b_init( &new->input ); send( new->fd, GREETING, strlen(GREETING), MSG_DONTWAIT ); enqueue_all( new ); conn=new; @@ -654,9 +650,6 @@ int main( int argc, char ** argv ) { debug( 4, L"Close connection %d", c->fd ); - close(c->fd ); - sb_destroy( &c->input ); - while( !q_empty( &c->unsent ) ) { message_t *msg = (message_t *)q_get( &c->unsent ); @@ -665,7 +658,7 @@ int main( int argc, char ** argv ) free( msg ); } - q_destroy( &c->unsent ); + connection_destroy( c ); if( prev ) { prev->next=c->next; @@ -695,5 +688,7 @@ int main( int argc, char ** argv ) exit(0); c=c->next; } + } } + |