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
This commit is contained in:
liljencrantz 2008-01-09 05:31:45 +10:00
parent da4a4bcc18
commit 71c2cde390
7 changed files with 51 additions and 16 deletions

View file

@ -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

11
exec.c
View file

@ -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;

View file

@ -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,

View file

@ -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 );
}
}
}

24
path.c
View file

@ -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;
}

1
proc.c
View file

@ -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()

9
proc.h
View file

@ -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
*/