Check exit status of close and fclose in a few extra places

darcs-hash:20060621095430-ac50b-52afcee91b856f706d6df6bcf2e3a6bc7d746e40.gz
This commit is contained in:
axel 2006-06-21 19:54:30 +10:00
parent b016438c08
commit 3ddd5e5981
8 changed files with 80 additions and 15 deletions

View File

@ -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 )
{

View File

@ -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 );

23
exec.c
View File

@ -86,9 +86,10 @@ void exec_close( int fd )
{
debug( 1, FD_ERROR, fd );
wperror( L"close" );
break;
}
}
if( open_fds )
{
for( i=0; i<al_get_count( open_fds ); i++ )
@ -260,7 +261,11 @@ static int handle_child_io( io_data_t *io, int exit_on_error )
switch( io->io_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 )

View File

@ -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();

View File

@ -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 );

View File

@ -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; i<me->level; 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 );
}

4
proc.c
View File

@ -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;

View File

@ -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