diff options
author | 2007-01-22 00:58:10 +1000 | |
---|---|---|
committer | 2007-01-22 00:58:10 +1000 | |
commit | a1ec38f53bd5c5072894dcbbfe19caf4ebde69ff (patch) | |
tree | 3d79f0709361c846a9dbf73e0d7e651a4930ca67 | |
parent | 64f1024eb50486466e7c8347de90dc9d7bfda44f (diff) |
Check error code when writing output from builtins - try to report errors
darcs-hash:20070121145810-ac50b-46ecb601ce9f0d862f00e4a97f25b6034e52f4cc.gz
-rw-r--r-- | exec.c | 33 |
1 files changed, 29 insertions, 4 deletions
@@ -762,6 +762,34 @@ static pid_t exec_fork() } +static void do_builtin_io( wchar_t *out, wchar_t *err ) +{ + + if( out ) + { + if( fwprintf( stdout, L"%ls", out ) == -1 || fflush( stdout ) == EOF ) + { + debug( 0, L"Error while writing to stdout" ); + wperror( L"fwprintf" ); + show_stackframe(); + } + } + + if( err ) + { + if( fwprintf( stderr, L"%ls", err ) == -1 || fflush( stderr ) == EOF ) + { + /* + Can't really show any error message here, since stderr is + dead. Complain a bit on stdout. + */ + fwprintf( stdout, L"fish: Error while writing to stderr\n" ); + } + } + +} + + void exec( job_t *j ) { process_t *p; @@ -1351,10 +1379,7 @@ void exec( job_t *j ) p->pid = getpid(); setup_child_process( j, p ); - if( sb_out->used ) - fwprintf( stdout, L"%ls", sb_out->buff ); - if( sb_err->used ) - fwprintf( stderr, L"%ls", sb_err->buff ); + do_builtin_io( sb_out->used ? (wchar_t *)sb_out->buff : 0, sb_err->used ? (wchar_t *)sb_err->buff : 0 ); exit( p->status ); |