From 71c2cde39073267a23cafd384ef9996be544c85d Mon Sep 17 00:00:00 2001 From: liljencrantz Date: Wed, 9 Jan 2008 05:31:45 +1000 Subject: [PATCH] Cleanup and improve the exit status numbers and the messages generated on error as well as make sure that keyboard shortcuts don't change the status darcs-hash:20080108193145-75c98-56c8aa2dd081af643d206820aa36bf3b6e49e0f2.gz --- doc_src/index.hdr.in | 5 +++-- exec.c | 11 +++++------ input.c | 5 ++++- parser.c | 12 ++++++++++-- path.c | 24 ++++++++++++++++++++++-- proc.c | 1 - proc.h | 9 +++++++-- 7 files changed, 51 insertions(+), 16 deletions(-) diff --git a/doc_src/index.hdr.in b/doc_src/index.hdr.in index 128099b..a45a9d4 100644 --- a/doc_src/index.hdr.in +++ b/doc_src/index.hdr.in @@ -955,8 +955,9 @@ If fish encounters a problem while executing a command, the status variable may also be set to a specific value: - 1 is the generally the exit status from fish builtins if they where supplied with invalid arguments -- 125 means an unknown error occured while trying to execute the command -- 126 means that the command was not executed because none of the wildcards in the command produced any matches +- 124 means that the command was not executed because none of the wildcards in the command produced any matches +- 125 means that while an executable with the specified name was located, the operating system could not actually execute the command +- 126 means that while a file with the specified name was located, it was not executable - 127 means that no function, builtin or command with the given name could be located \subsection variables-color Variables for changing highlighting colors diff --git a/exec.c b/exec.c index dbda6cb..090f7a4 100644 --- a/exec.c +++ b/exec.c @@ -509,7 +509,6 @@ static void launch_process( process_t *p ) } errno = err; - debug( 0, _( L"Failed to execute process '%ls'. Reason:" ), p->actual_cmd ); @@ -566,15 +565,15 @@ static void launch_process( process_t *p ) sb_destroy( &sz1 ); sb_destroy( &sz2 ); - exit(1); + exit(STATUS_EXEC_FAIL); break; } default: { - wperror( L"execve" ); - FATAL_EXIT(); + debug(0, L"The file '%ls' is marked as an executable but could not be run by the operating system.", p->actual_cmd); + exit(STATUS_EXEC_FAIL); } } @@ -1632,7 +1631,7 @@ int exec_subshell( const wchar_t *cmd, char sep=0; CHECK( cmd, -1 ); - + ifs = env_get(L"IFS"); if( ifs && ifs[0] ) @@ -1664,7 +1663,7 @@ int exec_subshell( const wchar_t *cmd, } io_buffer_read( io_buffer ); - + proc_set_last_status( prev_status ); is_subshell = prev_subshell; diff --git a/input.c b/input.c index 1e9a468..a45e26f 100644 --- a/input.c +++ b/input.c @@ -408,9 +408,12 @@ static wint_t input_exec_binding( input_mapping_t *m, const wchar_t *seq ) This key sequence is bound to a command, which is sent to the parser for evaluation. */ - + int last_status = proc_get_last_status(); + eval( m->command, 0, TOP ); + proc_set_last_status( last_status ); + /* We still need to return something to the caller, R_NULL tells the reader that no key press needs to be handled, diff --git a/parser.c b/parser.c index 916dd79..4e1bf6b 100644 --- a/parser.c +++ b/parser.c @@ -1970,7 +1970,10 @@ static int parse_job( process_t *p, } else { + int err; + p->actual_cmd = path_get_path( j, (wchar_t *)al_get( args, 0 ) ); + err = errno; /* Check if the specified command exists @@ -2062,12 +2065,17 @@ static int parse_job( process_t *p, cmd, cmd ); } + else if( err!=ENOENT ) + { + debug( 0, + _(L"The file '%ls' is not executable by this user"), + cmd?cmd:L"UNKNOWN" ); + } else { debug( 0, _(L"Unknown command '%ls'"), cmd?cmd:L"UNKNOWN" ); - } tmp = current_tokenizer_pos; @@ -2078,7 +2086,7 @@ static int parse_job( process_t *p, current_tokenizer_pos=tmp; job_set_flag( j, JOB_SKIP, 1 ); - proc_set_last_status( STATUS_UNKNOWN_COMMAND ); + proc_set_last_status( err==ENOENT?STATUS_UNKNOWN_COMMAND:STATUS_NOT_EXECUTABLE ); } } } diff --git a/path.c b/path.c index bfd054d..63baf3d 100644 --- a/path.c +++ b/path.c @@ -31,8 +31,10 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd ) { wchar_t *path; + int err = ENOENT; + CHECK( cmd, 0 ); - + debug( 3, L"path_get_path( '%ls' )", cmd ); if(wcschr( cmd, L'/' ) != 0 ) @@ -40,12 +42,26 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd ) if( waccess( cmd, X_OK )==0 ) { struct stat buff; - wstat( cmd, &buff ); + if(wstat( cmd, &buff )) + { + return 0; + } + if( S_ISREG(buff.st_mode) ) return halloc_wcsdup( context, cmd ); else + { + errno = EACCES; return 0; + } } + else + { + struct stat buff; + wstat( cmd, &buff ); + return 0; + } + } else { @@ -107,6 +123,8 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd ) free( path_cpy ); return new_cmd; } + err = EACCES; + } else { @@ -130,6 +148,8 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd ) free( path_cpy ); } + + errno = err; return 0; } diff --git a/proc.c b/proc.c index 8a2f826..259295b 100644 --- a/proc.c +++ b/proc.c @@ -190,7 +190,6 @@ void proc_destroy() void proc_set_last_status( int s ) { last_status = s; -// debug( 0, L"Set last status to %d\n", s ); } int proc_get_last_status() diff --git a/proc.h b/proc.h index 4d266ca..879e361 100644 --- a/proc.h +++ b/proc.h @@ -25,15 +25,20 @@ #define STATUS_UNKNOWN_COMMAND 127 /** - The status code use when a wildcard had no matches + The status code use when an unknown error occured during execution of a command */ -#define STATUS_UNMATCHED_WILDCARD 126 +#define STATUS_NOT_EXECUTABLE 126 /** The status code use when an unknown error occured during execution of a command */ #define STATUS_EXEC_FAIL 125 +/** + The status code use when a wildcard had no matches +*/ +#define STATUS_UNMATCHED_WILDCARD 124 + /** The status code used for normal exit in a builtin */