From 14c84ffbcbbe0368e61b7bc59d44a1d7bc906d33 Mon Sep 17 00:00:00 2001 From: axel Date: Mon, 23 Feb 2009 06:28:52 +1000 Subject: Check return value of a few write calls and retry on EINTR, and fix a few other warnings, mostly by printing error messages before giving up. darcs-hash:20090222202852-ac50b-b0e79142af5b7a99e55271d4001fa252d9684a1d.gz --- exec.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'exec.c') diff --git a/exec.c b/exec.c index a6b98992..921002ea 100644 --- a/exec.c +++ b/exec.c @@ -53,6 +53,11 @@ */ #define FD_ERROR _( L"An error occurred while redirecting file descriptor %d" ) +/** + file descriptor redirection error message +*/ +#define WRITE_ERROR _( L"An error occurred while writing output" ) + /** file redirection error message */ @@ -92,6 +97,18 @@ static array_list_t *open_fds=0; static int set_child_group( job_t *j, process_t *p, int print_errors ); +static void exec_write_and_exit( int fd, char *buff, size_t count, int status ) +{ + if( write_loop(fd, buff, count) == -1 ) + { + debug( 0, WRITE_ERROR); + wperror( L"write" ); + exit(status); + } + exit( status ); +} + + void exec_close( int fd ) { int i; @@ -1426,15 +1443,17 @@ void exec( job_t *j ) if( pid == 0 ) { + /* This is the child process. Write out the contents of the pipeline. */ p->pid = getpid(); setup_child_process( j, p ); - write( io_buffer->fd, - io_buffer->param2.out_buffer->buff, - io_buffer->param2.out_buffer->used ); - exit( status ); + + exec_write_and_exit(io_buffer->fd, + io_buffer->param2.out_buffer->buff, + io_buffer->param2.out_buffer->used, + status); } else { @@ -1480,10 +1499,10 @@ void exec( job_t *j ) p->pid = getpid(); setup_child_process( j, p ); - write( 1, - input_redirect->param2.out_buffer->buff, - input_redirect->param2.out_buffer->used ); - exit( 0 ); + exec_write_and_exit( 1, + input_redirect->param2.out_buffer->buff, + input_redirect->param2.out_buffer->used, + 0); } else { -- cgit v1.2.3