Skip to content

Commit

Permalink
Cleanup and improve the exit status numbers and the messages generate…
Browse files Browse the repository at this point in the history
…d on error as well as make sure that keyboard shortcuts don't change the status

darcs-hash:20080108193145-75c98-56c8aa2dd081af643d206820aa36bf3b6e49e0f2.gz
  • Loading branch information
liljencrantz committed Jan 8, 2008
1 parent da4a4bc commit 71c2cde
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 16 deletions.
5 changes: 3 additions & 2 deletions doc_src/index.hdr.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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] )
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 10 additions & 2 deletions parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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 );
}
}
}
Expand Down
24 changes: 22 additions & 2 deletions path.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,37 @@ 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 )
{
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
{
Expand Down Expand Up @@ -107,6 +123,8 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd )
free( path_cpy );
return new_cmd;
}
err = EACCES;

}
else
{
Expand All @@ -130,6 +148,8 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd )
free( path_cpy );

}

errno = err;
return 0;
}

Expand Down
1 change: 0 additions & 1 deletion proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 7 additions & 2 deletions proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 71c2cde

Please sign in to comment.