From 3ddd5e59810d0d1642a061a6342811a8be7a5251 Mon Sep 17 00:00:00 2001 From: axel Date: Wed, 21 Jun 2006 19:54:30 +1000 Subject: [PATCH] Check exit status of close and fclose in a few extra places darcs-hash:20060621095430-ac50b-52afcee91b856f706d6df6bcf2e3a6bc7d746e40.gz --- common.c | 3 +++ env_universal.c | 14 ++++++++++++-- exec.c | 23 ++++++++++++++++++++--- input.c | 3 +++ mimedb.c | 3 +++ parser.c | 42 +++++++++++++++++++++++++++++++++--------- proc.c | 4 ++++ wutil.c | 3 ++- 8 files changed, 80 insertions(+), 15 deletions(-) diff --git a/common.c b/common.c index 095687972..118edcb80 100644 --- a/common.c +++ b/common.c @@ -1335,6 +1335,9 @@ int acquire_lock_file( const char *lockfile, const int timeout, int force ) debug( 1, L"acquire_lock_file: open: %s", strerror( errno ) ); goto done; } + /* + Don't need to check exit status of close on read-only file descriptors + */ close( fd ); if( stat( linkfile, &statbuf ) != 0 ) { diff --git a/env_universal.c b/env_universal.c index 764ed0be1..5c3032242 100644 --- a/env_universal.c +++ b/env_universal.c @@ -182,7 +182,12 @@ static void check_connection() if( env_universal_server.killme ) { debug( 3, L"Lost connection to universal variable server." ); - close( env_universal_server.fd ); + + if( close( env_universal_server.fd ) ) + { + wperror( L"close" ); + } + env_universal_server.fd = -1; env_universal_server.killme=0; sb_clear( &env_universal_server.input ); @@ -252,7 +257,12 @@ void env_universal_destroy() } try_send_all( &env_universal_server ); } - close( env_universal_server.fd ); + + if( close( env_universal_server.fd ) ) + { + wperror( L"close" ); + } + env_universal_server.fd =-1; q_destroy( &env_universal_server.unsent ); sb_destroy( &env_universal_server.input ); diff --git a/exec.c b/exec.c index ee0d6b800..608ff1945 100644 --- a/exec.c +++ b/exec.c @@ -86,9 +86,10 @@ void exec_close( int fd ) { debug( 1, FD_ERROR, fd ); wperror( L"close" ); + break; } } - + if( open_fds ) { for( i=0; iio_mode ) { case IO_CLOSE: - close(io->fd); + if( close(io->fd) ) + { + debug( 0, _(L"Failed to close file descriptor %d"), io->fd ); + wperror( L"close" ); + } break; case IO_FILE: { @@ -283,8 +288,12 @@ static int handle_child_io( io_data_t *io, int exit_on_error ) } else if( tmp != io->fd) { + /* + This call will sometimes fail, but that is ok, + this is just a precausion. + */ close(io->fd); - + if(dup2( tmp, io->fd ) == -1 ) { debug( 1, @@ -307,6 +316,10 @@ static int handle_child_io( io_data_t *io, int exit_on_error ) case IO_FD: { + /* + This call will sometimes fail, but that is ok, + this is just a precausion. + */ close(io->fd); if( dup2( io->param1.old_fd, io->fd ) == -1 ) @@ -332,6 +345,10 @@ static int handle_child_io( io_data_t *io, int exit_on_error ) { int fd_to_dup = io->fd; + /* + This call will sometimes fail, but that is ok, + this is just a precausion. + */ close(io->fd); if( dup2( io->param1.pipe_fd[fd_to_dup?1:0], io->fd ) == -1 ) diff --git a/input.c b/input.c index 5fea828bf..a67ecd644 100644 --- a/input.c +++ b/input.c @@ -1132,6 +1132,9 @@ static void input_read_inputrc( wchar_t *fn ) } } free( buff ); + /* + Don't need to check exit status of fclose on read-only stream + */ fclose( rc ); } signal_unblock(); diff --git a/mimedb.c b/mimedb.c index 747b74782..1aa4f0152 100644 --- a/mimedb.c +++ b/mimedb.c @@ -548,6 +548,9 @@ static char *get_description( const char *mimetype ) return 0; } + /* + Don't need to check exit status of close on read-only file descriptors + */ close( fd ); free( fn ); diff --git a/parser.c b/parser.c index d472ffb40..1ec7f2408 100644 --- a/parser.c +++ b/parser.c @@ -866,7 +866,6 @@ void parser_init() al_init( &profile_data); } forbidden_function = al_new(); - } /** @@ -914,12 +913,27 @@ static void print_profile( array_list_t *p, if( me->cmd ) { - fwprintf( out, L"%d\t%d\t", my_time, me->parse+me->exec ); + if( fwprintf( out, L"%d\t%d\t", my_time, me->parse+me->exec ) < 0 ) + { + wperror( L"fwprintf" ); + return; + } + for( i=0; ilevel; i++ ) { - fwprintf( out, L"-" ); + if( fwprintf( out, L"-" ) < 0 ) + { + wperror( L"fwprintf" ); + return; + } + } - fwprintf( out, L"> %ls\n", me->cmd ); + if( fwprintf( out, L"> %ls\n", me->cmd ) < 0 ) + { + wperror( L"fwprintf" ); + return; + } + } } print_profile( p, pos+1, out ); @@ -943,11 +957,21 @@ void parser_destroy() } else { - fwprintf( f, - _(L"Time\tSum\tCommand\n"), - al_get_count( &profile_data ) ); - print_profile( &profile_data, 0, f ); - fclose( f ); + if( fwprintf( f, + _(L"Time\tSum\tCommand\n"), + al_get_count( &profile_data ) ) < 0 ) + { + wperror( L"fwprintf" ); + } + else + { + print_profile( &profile_data, 0, f ); + } + + if( fclose( f ) ) + { + wperror( L"fclose" ); + } } al_destroy( &profile_data ); } diff --git a/proc.c b/proc.c index 94fe8dc67..5c60c5b20 100644 --- a/proc.c +++ b/proc.c @@ -695,6 +695,10 @@ unsigned long proc_get_jiffies( process_t *p ) { return 0; } + + /* + Don't need to check exit status of fclose on read-only streams + */ fclose( f ); return utime+stime+cutime+cstime; diff --git a/wutil.c b/wutil.c index 89f27ca00..0fa055f67 100644 --- a/wutil.c +++ b/wutil.c @@ -303,11 +303,12 @@ int waccess(const wchar_t *file_name, int mode) void wperror(const wchar_t *s) { + int e = errno; if( s != 0 ) { fwprintf( stderr, L"%ls: ", s ); } - fwprintf( stderr, L"%s\n", strerror( errno ) ); + fwprintf( stderr, L"%s\n", strerror( e ) ); } #ifdef HAVE_REALPATH_NULL