From 80b4055eab16e5b96015f128367d980f9fee4a1f Mon Sep 17 00:00:00 2001 From: axel Date: Sat, 18 Mar 2006 11:04:59 +1000 Subject: [PATCH] Add support for the -n switch to skip execution of any commands darcs-hash:20060318010459-ac50b-9d9e5c489e0e4df2159d8c1d0ff952d42e2a2a82.gz --- exec.c | 7 +++++-- main.c | 21 +++++++++++++++++++-- parser.c | 2 +- proc.c | 2 ++ proc.h | 6 ++++++ share/completions/fish.fish | 1 + 6 files changed, 34 insertions(+), 5 deletions(-) diff --git a/exec.c b/exec.c index 9dff5985a..e93731608 100644 --- a/exec.c +++ b/exec.c @@ -653,8 +653,6 @@ void exec( job_t *j ) pid_t pid; int mypipe[2]; sigset_t chldset; - sigemptyset( &chldset ); - sigaddset( &chldset, SIGCHLD ); int skip_fork; io_data_t pipe_read, pipe_write; @@ -667,6 +665,11 @@ void exec( job_t *j ) */ int exec_error=0; + if( no_exec ) + return; + + sigemptyset( &chldset ); + sigaddset( &chldset, SIGCHLD ); debug( 4, L"Exec job '%ls' with id %d", j->command, j->job_id ); diff --git a/main.c b/main.c index 9e0b90bcd..85f92f344 100644 --- a/main.c +++ b/main.c @@ -138,6 +138,10 @@ int main( int argc, char **argv ) "login", no_argument, 0, 'l' } , + { + "no-execute", no_argument, 0, 'n' + } + , { "profile", required_argument, 0, 'p' } @@ -160,14 +164,14 @@ int main( int argc, char **argv ) int opt = getopt_long( argc, argv, - "hilvc:p:d:", + "hilnvc:p:d:", long_options, &opt_index ); #else int opt = getopt( argc, argv, - "hilvc:p:d:" ); + "hilnvc:p:d:" ); #endif if( opt == -1 ) break; @@ -210,6 +214,10 @@ int main( int argc, char **argv ) is_login=1; break; + case 'n': + no_exec=1; + break; + case 'p': profile = optarg; break; @@ -236,6 +244,15 @@ int main( int argc, char **argv ) is_interactive_session &= isatty(STDIN_FILENO); is_interactive_session |= force_interactive; + /* + No-exec is prohibited when in interactive mode + */ + if( is_interactive_session && no_exec) + { + debug( 1, _(L"Can not use the no-execute mode when running an interactive session") ); + no_exec = 0; + } + common_init(); halloc_util_init(); diff --git a/parser.c b/parser.c index 9ab8b5ca1..b882c6e33 100644 --- a/parser.c +++ b/parser.c @@ -2521,7 +2521,7 @@ int parser_test( wchar_t * buff, current_tokenizer = &tok; for( tok_init( &tok, buff, 0 ); - tok_has_next( &tok ) && !err; + tok_has_next( &tok ); tok_next( &tok ) ) { current_tokenizer_pos = tok_get_pos( &tok ); diff --git a/proc.c b/proc.c index 431d8e2cf..799cf2e1b 100644 --- a/proc.c +++ b/proc.c @@ -90,6 +90,8 @@ int is_event=0; int proc_had_barrier; pid_t proc_last_bg_pid = 0; int job_control_mode = JOB_CONTROL_INTERACTIVE; +int no_exec=0; + /** The event variable used to send all process event diff --git a/proc.h b/proc.h index 98b365b0f..274966602 100644 --- a/proc.h +++ b/proc.h @@ -231,6 +231,12 @@ extern pid_t proc_last_bg_pid; */ extern int job_control_mode; +/** + If this flag is set, fish will never fork or run execve. +*/ +extern int no_exec; + + /** Sets the status of the last process to exit */ diff --git a/share/completions/fish.fish b/share/completions/fish.fish index 4e20d92aa..5b34ac380 100644 --- a/share/completions/fish.fish +++ b/share/completions/fish.fish @@ -1,6 +1,7 @@ complete -c fish -s c -l "command" -d (N_ "Run fish with this command") complete -c fish -s h -l help -d (N_ "Display help and exit") complete -c fish -s v -l version -d (N_ "Display version and exit") +complete -c fish -s n -l no-execute -d (N_ "Only parse input, do not execute") complete -c fish -s i -l interactive -d (N_ "Run in interactive mode") complete -c fish -s l -l login -d (N_ "Run in login mode") complete -c fish -s p -l profile -d (N_ "Output profiling information to specified file") -f