From d0585befb341939ee1925d6dc253eb3888982f5c Mon Sep 17 00:00:00 2001 From: axel Date: Thu, 26 Apr 2007 04:30:02 +1000 Subject: [PATCH] Make sure that io redirections are respected by the '.' builtin. This was not the case earlier, which caused various bugs, especially after eval was made into a function that internally used '.' darcs-hash:20070425183002-ac50b-d7d93e3b74e7274fe3e0aad98e95dd608bb903ae.gz --- builtin.c | 16 ++++++++++++---- builtin.h | 3 ++- exec.c | 2 +- main.c | 4 ++-- reader.c | 8 ++++---- reader.h | 3 ++- 6 files changed, 23 insertions(+), 13 deletions(-) diff --git a/builtin.c b/builtin.c index d14c9eab8..6a87f064f 100644 --- a/builtin.c +++ b/builtin.c @@ -137,6 +137,13 @@ static int builtin_stdin; */ static hash_table_t *desc=0; +/** + The underyion IO redirections behind the current builtin. This + should normally not be used - sb_out and friends are already + configured to handle everything. +*/ +static io_data_t *real_io; + /** Counts the number of non null pointers in the specified array */ @@ -2292,7 +2299,7 @@ static int builtin_source( wchar_t ** argv ) parse_util_set_argv( (argc>2)?(argv+2):(argv+1), 0); - res = reader_read( fd ); + res = reader_read( fd, real_io ); parser_pop_block(); @@ -2877,7 +2884,7 @@ static int builtin_breakpoint( wchar_t **argv ) { parser_push_block( BREAKPOINT ); - reader_read( 0 ); + reader_read( 0, real_io ); parser_pop_block(); @@ -3262,10 +3269,11 @@ static int internal_help( wchar_t *cmd ) } -int builtin_run( wchar_t **argv ) +int builtin_run( wchar_t **argv, io_data_t *io ) { int (*cmd)(wchar_t **argv)=0; - + real_io = io; + CHECK( argv, STATUS_BUILTIN_ERROR ); CHECK( argv[0], STATUS_BUILTIN_ERROR ); diff --git a/builtin.h b/builtin.h index 722b31ed8..24d5f582a 100644 --- a/builtin.h +++ b/builtin.h @@ -8,6 +8,7 @@ #include #include "util.h" +#include "io.h" enum { @@ -131,7 +132,7 @@ int builtin_exists( wchar_t *cmd ); \return the exit status of the builtin command */ -int builtin_run( wchar_t **argv ); +int builtin_run( wchar_t **argv, io_data_t *io ); /** Insert all builtin names into l. These are not copies of the strings and should not be freed after use. diff --git a/exec.c b/exec.c index 01d2c929c..0ca0e754a 100644 --- a/exec.c +++ b/exec.c @@ -1158,7 +1158,7 @@ void exec( job_t *j ) signal_unblock(); - p->status = builtin_run( p->argv ); + p->status = builtin_run( p->argv, j->io ); builtin_out_redirect=old_out; builtin_err_redirect=old_err; diff --git a/main.c b/main.c index c9034eaab..55452661a 100644 --- a/main.c +++ b/main.c @@ -332,7 +332,7 @@ int main( int argc, char **argv ) { if( my_optind == argc ) { - res = reader_read( 0 ); + res = reader_read( 0, 0 ); } else { @@ -374,7 +374,7 @@ int main( int argc, char **argv ) free( rel_filename ); free( abs_filename ); - res = reader_read( fd ); + res = reader_read( fd, 0 ); if( res ) { diff --git a/reader.c b/reader.c index 8b1c7449d..3bd965506 100644 --- a/reader.c +++ b/reader.c @@ -2933,7 +2933,7 @@ wchar_t *reader_readline() the prompt, using syntax highlighting. This is used for reading scripts and init files. */ -static int read_ni( int fd ) +static int read_ni( int fd, io_data_t *io ) { FILE *in_stream; wchar_t *buff=0; @@ -2996,7 +2996,7 @@ static int read_ni( int fd ) if( !parser_test( str, 0, &sb, L"fish" ) ) { - eval( str, 0, TOP ); + eval( str, io, TOP ); } else { @@ -3035,7 +3035,7 @@ static int read_ni( int fd ) return res; } -int reader_read( int fd ) +int reader_read( int fd, io_data_t *io ) { int res; @@ -3047,7 +3047,7 @@ int reader_read( int fd ) proc_push_interactive( ((fd == 0) && isatty(STDIN_FILENO))); - res= is_interactive?read_i():read_ni( fd ); + res= is_interactive?read_i():read_ni( fd, io ); /* If the exit command was called in a script, only exit the diff --git a/reader.h b/reader.h index 36f22726f..2159deec0 100644 --- a/reader.h +++ b/reader.h @@ -12,11 +12,12 @@ #include #include "util.h" +#include "io.h" /** Read commands from \c fd until encountering EOF */ -int reader_read( int fd); +int reader_read( int fd, io_data_t *io); /** Tell the shell that it should exit after the currently running command finishes.