mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 04:43:10 +00:00
Handle exit status of processes terminated by signals
darcs-hash:20090221164656-ac50b-7bcbf6cb0bb8384560fbf9bf1059480cb4089def.gz
This commit is contained in:
parent
b1357d11b2
commit
f5be301a2f
4 changed files with 43 additions and 19 deletions
|
@ -928,7 +928,7 @@ values of most of these variables.
|
|||
- \c history, which is an array containing the last commands that where entered.
|
||||
- \c HOME, which is the users home directory. This variable can only be changed by the root user.
|
||||
- \c PWD, which is the current working directory.
|
||||
- \c status, which is the exit status of the last foreground job to exit.
|
||||
- \c status, which is the exit status of the last foreground job to exit. If the job was terminated through a signal, the exit status will be 128 plus the signal number.
|
||||
- \c USER, which is the username. This variable can only be changed by the root user.
|
||||
|
||||
The names of these variables are mostly derived from the csh family of
|
||||
|
@ -967,6 +967,8 @@ variable may also be set to a specific value:
|
|||
- 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
|
||||
|
||||
If a process exits through a signal, the exit status will be 128 plus the number of the signal.
|
||||
|
||||
\subsection variables-color Variables for changing highlighting colors
|
||||
|
||||
The colors used by fish for syntax highlighting can be configured by
|
||||
|
|
3
exec.c
3
exec.c
|
@ -1556,7 +1556,8 @@ void exec( job_t *j )
|
|||
{
|
||||
debug( 3, L"Set status of %ls to %d using short circut", j->command, p->status );
|
||||
|
||||
proc_set_last_status( job_get_flag( j, JOB_NEGATE )?(!p->status):p->status );
|
||||
int status = proc_format_status(p->status);
|
||||
proc_set_last_status( job_get_flag( j, JOB_NEGATE )?(!status):status );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
49
proc.c
49
proc.c
|
@ -343,30 +343,29 @@ static void mark_process_status( job_t *j,
|
|||
process_t *p,
|
||||
int status )
|
||||
{
|
||||
p->status = status;
|
||||
// debug( 0, L"Process %ls %ls", p->argv[0], WIFSTOPPED (status)?L"stopped":(WIFEXITED( status )?L"exited":(WIFSIGNALED( status )?L"signaled to exit":L"BLARGH")) );
|
||||
p->status = status;
|
||||
|
||||
if (WIFSTOPPED (status))
|
||||
{
|
||||
p->stopped = 1;
|
||||
}
|
||||
else
|
||||
else if (WIFSIGNALED(status) || WIFEXITED(status))
|
||||
{
|
||||
p->completed = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This should never be reached */
|
||||
p->completed = 1;
|
||||
|
||||
char mess[MESS_SIZE];
|
||||
snprintf( mess,
|
||||
MESS_SIZE,
|
||||
"Process %d exited abnormally\n",
|
||||
(int) p->pid );
|
||||
|
||||
if (( !WIFEXITED( status ) ) &&
|
||||
(! WIFSIGNALED( status )) )
|
||||
{
|
||||
/* This should never be reached */
|
||||
char mess[MESS_SIZE];
|
||||
snprintf( mess,
|
||||
MESS_SIZE,
|
||||
"Process %d exited abnormally\n",
|
||||
(int) p->pid );
|
||||
|
||||
write( 2, mess, strlen(mess) );
|
||||
}
|
||||
write( 2, mess, strlen(mess) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1106,7 +1105,7 @@ void job_continue (job_t *j, int cont)
|
|||
while( p->next )
|
||||
p = p->next;
|
||||
|
||||
if( WIFEXITED( p->status ) )
|
||||
if( WIFEXITED( p->status ) || WIFSIGNALED(p->status))
|
||||
{
|
||||
/*
|
||||
Mark process status only if we are in the foreground
|
||||
|
@ -1114,8 +1113,9 @@ void job_continue (job_t *j, int cont)
|
|||
*/
|
||||
if( p->pid )
|
||||
{
|
||||
debug( 3, L"Set status of %ls to %d", j->command, WEXITSTATUS(p->status) );
|
||||
proc_set_last_status( job_get_flag( j, JOB_NEGATE )?(WEXITSTATUS(p->status)?0:1):WEXITSTATUS(p->status) );
|
||||
int status = proc_format_status(p->status);
|
||||
|
||||
proc_set_last_status( job_get_flag( j, JOB_NEGATE )?!status:status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1140,6 +1140,21 @@ void job_continue (job_t *j, int cont)
|
|||
|
||||
}
|
||||
|
||||
int proc_format_status(int status)
|
||||
{
|
||||
if( WIFSIGNALED( status ) )
|
||||
{
|
||||
return 128+WTERMSIG(status);
|
||||
}
|
||||
else if( WIFEXITED( status ) )
|
||||
{
|
||||
return WEXITSTATUS(status);
|
||||
}
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void proc_sanity_check()
|
||||
{
|
||||
job_t *j;
|
||||
|
|
6
proc.h
6
proc.h
|
@ -485,4 +485,10 @@ void proc_push_interactive( int value );
|
|||
*/
|
||||
void proc_pop_interactive();
|
||||
|
||||
/**
|
||||
Format an exit status code as returned by e.g. wait into a fish exit code number as accepted by proc_set_last_status.
|
||||
*/
|
||||
int proc_format_status(int status) ;
|
||||
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue