mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 8.1.0863: cannot see what signal caused a job to end
Problem: Cannot see what signal caused a job to end. Solution: Add "termsig" to job_info(). (Ozaki Kiichi, closes #3786)
This commit is contained in:
@@ -5745,6 +5745,11 @@ job_info([{job}]) *job_info()*
|
|||||||
"exit_cb" function to be called on exit
|
"exit_cb" function to be called on exit
|
||||||
"stoponexit" |job-stoponexit|
|
"stoponexit" |job-stoponexit|
|
||||||
|
|
||||||
|
Only in Unix:
|
||||||
|
"termsig" the signal which terminated the process
|
||||||
|
(See |job_stop()| for the values)
|
||||||
|
only valid when "status" is "dead"
|
||||||
|
|
||||||
Without any arguments, returns a List with all Job objects.
|
Without any arguments, returns a List with all Job objects.
|
||||||
|
|
||||||
job_setoptions({job}, {options}) *job_setoptions()*
|
job_setoptions({job}, {options}) *job_setoptions()*
|
||||||
|
@@ -5152,6 +5152,9 @@ job_free_contents(job_T *job)
|
|||||||
vim_free(job->jv_tty_in);
|
vim_free(job->jv_tty_in);
|
||||||
vim_free(job->jv_tty_out);
|
vim_free(job->jv_tty_out);
|
||||||
vim_free(job->jv_stoponexit);
|
vim_free(job->jv_stoponexit);
|
||||||
|
#ifdef UNIX
|
||||||
|
vim_free(job->jv_termsig);
|
||||||
|
#endif
|
||||||
free_callback(job->jv_exit_cb, job->jv_exit_partial);
|
free_callback(job->jv_exit_cb, job->jv_exit_partial);
|
||||||
if (job->jv_argv != NULL)
|
if (job->jv_argv != NULL)
|
||||||
{
|
{
|
||||||
@@ -5908,6 +5911,9 @@ job_info(job_T *job, dict_T *dict)
|
|||||||
dict_add_number(dict, "exitval", job->jv_exitval);
|
dict_add_number(dict, "exitval", job->jv_exitval);
|
||||||
dict_add_string(dict, "exit_cb", job->jv_exit_cb);
|
dict_add_string(dict, "exit_cb", job->jv_exit_cb);
|
||||||
dict_add_string(dict, "stoponexit", job->jv_stoponexit);
|
dict_add_string(dict, "stoponexit", job->jv_stoponexit);
|
||||||
|
#ifdef UNIX
|
||||||
|
dict_add_string(dict, "termsig", job->jv_termsig);
|
||||||
|
#endif
|
||||||
|
|
||||||
l = list_alloc();
|
l = list_alloc();
|
||||||
if (l != NULL)
|
if (l != NULL)
|
||||||
|
@@ -5655,6 +5655,23 @@ failed:
|
|||||||
close(pty_slave_fd);
|
close(pty_slave_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char_u *
|
||||||
|
get_signal_name(int sig)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char_u numbuf[NUMBUFLEN];
|
||||||
|
|
||||||
|
if (sig == SIGKILL)
|
||||||
|
return vim_strsave((char_u *)"kill");
|
||||||
|
|
||||||
|
for (i = 0; signal_info[i].sig != -1; i++)
|
||||||
|
if (sig == signal_info[i].sig)
|
||||||
|
return strlow_save((char_u *)signal_info[i].name);
|
||||||
|
|
||||||
|
vim_snprintf((char *)numbuf, NUMBUFLEN, "%d", sig);
|
||||||
|
return vim_strsave(numbuf);
|
||||||
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
mch_job_status(job_T *job)
|
mch_job_status(job_T *job)
|
||||||
{
|
{
|
||||||
@@ -5691,8 +5708,10 @@ mch_job_status(job_T *job)
|
|||||||
if (WIFSIGNALED(status))
|
if (WIFSIGNALED(status))
|
||||||
{
|
{
|
||||||
job->jv_exitval = -1;
|
job->jv_exitval = -1;
|
||||||
if (job->jv_status < JOB_ENDED)
|
job->jv_termsig = get_signal_name(WTERMSIG(status));
|
||||||
ch_log(job->jv_channel, "Job terminated by a signal");
|
if (job->jv_status < JOB_ENDED && job->jv_termsig != NULL)
|
||||||
|
ch_log(job->jv_channel, "Job terminated by signal \"%s\"",
|
||||||
|
job->jv_termsig);
|
||||||
goto return_dead;
|
goto return_dead;
|
||||||
}
|
}
|
||||||
return "run";
|
return "run";
|
||||||
@@ -5738,7 +5757,10 @@ mch_detect_ended_job(job_T *job_list)
|
|||||||
/* LINTED avoid "bitwise operation on signed value" */
|
/* LINTED avoid "bitwise operation on signed value" */
|
||||||
job->jv_exitval = WEXITSTATUS(status);
|
job->jv_exitval = WEXITSTATUS(status);
|
||||||
else if (WIFSIGNALED(status))
|
else if (WIFSIGNALED(status))
|
||||||
|
{
|
||||||
job->jv_exitval = -1;
|
job->jv_exitval = -1;
|
||||||
|
job->jv_termsig = get_signal_name(WTERMSIG(status));
|
||||||
|
}
|
||||||
if (job->jv_status < JOB_ENDED)
|
if (job->jv_status < JOB_ENDED)
|
||||||
{
|
{
|
||||||
ch_log(job->jv_channel, "Job ended");
|
ch_log(job->jv_channel, "Job ended");
|
||||||
|
@@ -1551,6 +1551,9 @@ struct jobvar_S
|
|||||||
char_u *jv_tty_out; /* controlling tty output, allocated */
|
char_u *jv_tty_out; /* controlling tty output, allocated */
|
||||||
jobstatus_T jv_status;
|
jobstatus_T jv_status;
|
||||||
char_u *jv_stoponexit; /* allocated */
|
char_u *jv_stoponexit; /* allocated */
|
||||||
|
#ifdef UNIX
|
||||||
|
char_u *jv_termsig; /* allocated */
|
||||||
|
#endif
|
||||||
int jv_exitval;
|
int jv_exitval;
|
||||||
char_u *jv_exit_cb; /* allocated */
|
char_u *jv_exit_cb; /* allocated */
|
||||||
partial_T *jv_exit_partial;
|
partial_T *jv_exit_partial;
|
||||||
|
@@ -2002,3 +2002,27 @@ func Test_raw_large_data()
|
|||||||
unlet g:out
|
unlet g:out
|
||||||
endtry
|
endtry
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_job_exitval_and_termsig()
|
||||||
|
if !has('unix')
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Terminate job normally
|
||||||
|
let cmd = ['echo']
|
||||||
|
let job = job_start(cmd)
|
||||||
|
call WaitForAssert({-> assert_equal("dead", job_status(job))})
|
||||||
|
let info = job_info(job)
|
||||||
|
call assert_equal(0, info.exitval)
|
||||||
|
call assert_equal("", info.termsig)
|
||||||
|
|
||||||
|
" Terminate job by signal
|
||||||
|
let cmd = ['sleep', '10']
|
||||||
|
let job = job_start(cmd)
|
||||||
|
sleep 10m
|
||||||
|
call job_stop(job)
|
||||||
|
call WaitForAssert({-> assert_equal("dead", job_status(job))})
|
||||||
|
let info = job_info(job)
|
||||||
|
call assert_equal(-1, info.exitval)
|
||||||
|
call assert_equal("term", info.termsig)
|
||||||
|
endfunc
|
||||||
|
@@ -783,6 +783,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
863,
|
||||||
/**/
|
/**/
|
||||||
862,
|
862,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user