aboutsummaryrefslogtreecommitdiffhomepage
path: root/exec.c
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2009-02-23 06:28:52 +1000
committerGravatar axel <axel@liljencrantz.se>2009-02-23 06:28:52 +1000
commit14c84ffbcbbe0368e61b7bc59d44a1d7bc906d33 (patch)
treea0fbafe2d63e86d5adcd615a7bc70fade00f0803 /exec.c
parentf71c6f3f0e34c034c3dec54289527a68a136749f (diff)
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
Diffstat (limited to 'exec.c')
-rw-r--r--exec.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/exec.c b/exec.c
index a6b98992..921002ea 100644
--- a/exec.c
+++ b/exec.c
@@ -54,6 +54,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
*/
#define FILE_ERROR _( L"An error occurred while redirecting file '%ls'" )
@@ -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
{