mirror of
https://github.com/vim/vim.git
synced 2025-09-27 04:14:06 -04:00
patch 7.4.1378
Problem: Can't change job settings after it started. Solution: Add job_setoptions() with the "stoponexit" flag.
This commit is contained in:
139
src/eval.c
139
src/eval.c
@@ -451,9 +451,6 @@ static dict_T *dict_copy(dict_T *orig, int deep, int copyID);
|
|||||||
static long dict_len(dict_T *d);
|
static long dict_len(dict_T *d);
|
||||||
static char_u *dict2string(typval_T *tv, int copyID);
|
static char_u *dict2string(typval_T *tv, int copyID);
|
||||||
static int get_dict_tv(char_u **arg, typval_T *rettv, int evaluate);
|
static int get_dict_tv(char_u **arg, typval_T *rettv, int evaluate);
|
||||||
#ifdef FEAT_JOB
|
|
||||||
static void job_free(job_T *job);
|
|
||||||
#endif
|
|
||||||
static char_u *echo_string(typval_T *tv, char_u **tofree, char_u *numbuf, int copyID);
|
static char_u *echo_string(typval_T *tv, char_u **tofree, char_u *numbuf, int copyID);
|
||||||
static char_u *tv2string(typval_T *tv, char_u **tofree, char_u *numbuf, int copyID);
|
static char_u *tv2string(typval_T *tv, char_u **tofree, char_u *numbuf, int copyID);
|
||||||
static char_u *string_quote(char_u *str, int function);
|
static char_u *string_quote(char_u *str, int function);
|
||||||
@@ -633,6 +630,7 @@ static void f_items(typval_T *argvars, typval_T *rettv);
|
|||||||
# ifdef FEAT_CHANNEL
|
# ifdef FEAT_CHANNEL
|
||||||
static void f_job_getchannel(typval_T *argvars, typval_T *rettv);
|
static void f_job_getchannel(typval_T *argvars, typval_T *rettv);
|
||||||
# endif
|
# endif
|
||||||
|
static void f_job_setoptions(typval_T *argvars, typval_T *rettv);
|
||||||
static void f_job_start(typval_T *argvars, typval_T *rettv);
|
static void f_job_start(typval_T *argvars, typval_T *rettv);
|
||||||
static void f_job_stop(typval_T *argvars, typval_T *rettv);
|
static void f_job_stop(typval_T *argvars, typval_T *rettv);
|
||||||
static void f_job_status(typval_T *argvars, typval_T *rettv);
|
static void f_job_status(typval_T *argvars, typval_T *rettv);
|
||||||
@@ -7751,7 +7749,9 @@ channel_unref(channel_T *channel)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FEAT_JOB
|
#if defined(FEAT_JOB) || defined(PROTO)
|
||||||
|
static job_T *first_job = NULL;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
job_free(job_T *job)
|
job_free(job_T *job)
|
||||||
{
|
{
|
||||||
@@ -7765,6 +7765,15 @@ job_free(job_T *job)
|
|||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
mch_clear_job(job);
|
mch_clear_job(job);
|
||||||
|
|
||||||
|
if (job->jv_next != NULL)
|
||||||
|
job->jv_next->jv_prev = job->jv_prev;
|
||||||
|
if (job->jv_prev == NULL)
|
||||||
|
first_job = job->jv_next;
|
||||||
|
else
|
||||||
|
job->jv_prev->jv_next = job->jv_next;
|
||||||
|
|
||||||
|
vim_free(job->jv_stoponexit);
|
||||||
vim_free(job);
|
vim_free(job);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7776,7 +7785,7 @@ job_unref(job_T *job)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocate a job. Sets the refcount to one.
|
* Allocate a job. Sets the refcount to one and sets options default.
|
||||||
*/
|
*/
|
||||||
static job_T *
|
static job_T *
|
||||||
job_alloc(void)
|
job_alloc(void)
|
||||||
@@ -7785,10 +7794,45 @@ job_alloc(void)
|
|||||||
|
|
||||||
job = (job_T *)alloc_clear(sizeof(job_T));
|
job = (job_T *)alloc_clear(sizeof(job_T));
|
||||||
if (job != NULL)
|
if (job != NULL)
|
||||||
|
{
|
||||||
job->jv_refcount = 1;
|
job->jv_refcount = 1;
|
||||||
|
job->jv_stoponexit = vim_strsave((char_u *)"term");
|
||||||
|
|
||||||
|
if (first_job != NULL)
|
||||||
|
{
|
||||||
|
first_job->jv_prev = job;
|
||||||
|
job->jv_next = first_job;
|
||||||
|
}
|
||||||
|
first_job = job;
|
||||||
|
}
|
||||||
return job;
|
return job;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
job_set_options(job_T *job, jobopt_T *opt)
|
||||||
|
{
|
||||||
|
if (opt->jo_set & JO_STOPONEXIT)
|
||||||
|
{
|
||||||
|
vim_free(job->jv_stoponexit);
|
||||||
|
if (opt->jo_stoponexit == NULL || *opt->jo_stoponexit == NUL)
|
||||||
|
job->jv_stoponexit = NULL;
|
||||||
|
else
|
||||||
|
job->jv_stoponexit = vim_strsave(opt->jo_stoponexit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Called when Vim is exiting: kill all jobs that have the "stoponexit" flag.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
job_stop_on_exit()
|
||||||
|
{
|
||||||
|
job_T *job;
|
||||||
|
|
||||||
|
for (job = first_job; job != NULL; job = job->jv_next)
|
||||||
|
if (job->jv_stoponexit != NULL && *job->jv_stoponexit != NUL)
|
||||||
|
mch_stop_job(job, job->jv_stoponexit);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
@@ -7797,9 +7841,9 @@ get_var_special_name(int nr)
|
|||||||
switch (nr)
|
switch (nr)
|
||||||
{
|
{
|
||||||
case VVAL_FALSE: return "v:false";
|
case VVAL_FALSE: return "v:false";
|
||||||
case VVAL_TRUE: return "v:true";
|
case VVAL_TRUE: return "v:true";
|
||||||
case VVAL_NONE: return "v:none";
|
case VVAL_NONE: return "v:none";
|
||||||
case VVAL_NULL: return "v:null";
|
case VVAL_NULL: return "v:null";
|
||||||
}
|
}
|
||||||
EMSG2(_(e_intern2), "get_var_special_name()");
|
EMSG2(_(e_intern2), "get_var_special_name()");
|
||||||
return "42";
|
return "42";
|
||||||
@@ -8260,6 +8304,7 @@ static struct fst
|
|||||||
# ifdef FEAT_CHANNEL
|
# ifdef FEAT_CHANNEL
|
||||||
{"job_getchannel", 1, 1, f_job_getchannel},
|
{"job_getchannel", 1, 1, f_job_getchannel},
|
||||||
# endif
|
# endif
|
||||||
|
{"job_setoptions", 2, 2, f_job_setoptions},
|
||||||
{"job_start", 1, 2, f_job_start},
|
{"job_start", 1, 2, f_job_start},
|
||||||
{"job_status", 1, 1, f_job_status},
|
{"job_status", 1, 1, f_job_status},
|
||||||
{"job_stop", 1, 2, f_job_stop},
|
{"job_stop", 1, 2, f_job_stop},
|
||||||
@@ -10050,6 +10095,19 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported)
|
|||||||
opt->jo_set |= JO_ID;
|
opt->jo_set |= JO_ID;
|
||||||
opt->jo_id = get_tv_number(item);
|
opt->jo_id = get_tv_number(item);
|
||||||
}
|
}
|
||||||
|
else if (STRCMP(hi->hi_key, "stoponexit") == 0)
|
||||||
|
{
|
||||||
|
if (!(supported & JO_STOPONEXIT))
|
||||||
|
break;
|
||||||
|
opt->jo_set |= JO_STOPONEXIT;
|
||||||
|
opt->jo_stoponexit = get_tv_string_buf_chk(item,
|
||||||
|
opt->jo_soe_buf);
|
||||||
|
if (opt->jo_stoponexit == NULL)
|
||||||
|
{
|
||||||
|
EMSG2(_(e_invarg2), "stoponexit");
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
--todo;
|
--todo;
|
||||||
@@ -14714,6 +14772,26 @@ f_items(typval_T *argvars, typval_T *rettv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FEAT_JOB
|
#ifdef FEAT_JOB
|
||||||
|
/*
|
||||||
|
* Get the job from the argument.
|
||||||
|
* Returns NULL if the job is invalid.
|
||||||
|
*/
|
||||||
|
static job_T *
|
||||||
|
get_job_arg(typval_T *tv)
|
||||||
|
{
|
||||||
|
job_T *job;
|
||||||
|
|
||||||
|
if (tv->v_type != VAR_JOB)
|
||||||
|
{
|
||||||
|
EMSG2(_(e_invarg2), get_tv_string(tv));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
job = tv->vval.v_job;
|
||||||
|
|
||||||
|
if (job == NULL)
|
||||||
|
EMSG(_("E916: not a valid job"));
|
||||||
|
return job;
|
||||||
|
}
|
||||||
|
|
||||||
# ifdef FEAT_CHANNEL
|
# ifdef FEAT_CHANNEL
|
||||||
/*
|
/*
|
||||||
@@ -14722,12 +14800,10 @@ f_items(typval_T *argvars, typval_T *rettv)
|
|||||||
static void
|
static void
|
||||||
f_job_getchannel(typval_T *argvars, typval_T *rettv)
|
f_job_getchannel(typval_T *argvars, typval_T *rettv)
|
||||||
{
|
{
|
||||||
if (argvars[0].v_type != VAR_JOB)
|
job_T *job = get_job_arg(&argvars[0]);
|
||||||
EMSG(_(e_invarg));
|
|
||||||
else
|
|
||||||
{
|
|
||||||
job_T *job = argvars[0].vval.v_job;
|
|
||||||
|
|
||||||
|
if (job != NULL)
|
||||||
|
{
|
||||||
rettv->v_type = VAR_CHANNEL;
|
rettv->v_type = VAR_CHANNEL;
|
||||||
rettv->vval.v_channel = job->jv_channel;
|
rettv->vval.v_channel = job->jv_channel;
|
||||||
if (job->jv_channel != NULL)
|
if (job->jv_channel != NULL)
|
||||||
@@ -14736,6 +14812,23 @@ f_job_getchannel(typval_T *argvars, typval_T *rettv)
|
|||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* "job_setoptions()" function
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
f_job_setoptions(typval_T *argvars, typval_T *rettv UNUSED)
|
||||||
|
{
|
||||||
|
job_T *job = get_job_arg(&argvars[0]);
|
||||||
|
jobopt_T opt;
|
||||||
|
|
||||||
|
if (job == NULL)
|
||||||
|
return;
|
||||||
|
clear_job_options(&opt);
|
||||||
|
if (get_job_options(&argvars[1], &opt, JO_STOPONEXIT) == FAIL)
|
||||||
|
return;
|
||||||
|
job_set_options(job, &opt);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "job_start()" function
|
* "job_start()" function
|
||||||
*/
|
*/
|
||||||
@@ -14765,8 +14858,9 @@ f_job_start(typval_T *argvars UNUSED, typval_T *rettv)
|
|||||||
clear_job_options(&opt);
|
clear_job_options(&opt);
|
||||||
opt.jo_mode = MODE_NL;
|
opt.jo_mode = MODE_NL;
|
||||||
if (get_job_options(&argvars[1], &opt,
|
if (get_job_options(&argvars[1], &opt,
|
||||||
JO_MODE_ALL + JO_CB_ALL + JO_TIMEOUT_ALL) == FAIL)
|
JO_MODE_ALL + JO_CB_ALL + JO_TIMEOUT_ALL + JO_STOPONEXIT) == FAIL)
|
||||||
return;
|
return;
|
||||||
|
job_set_options(job, &opt);
|
||||||
|
|
||||||
#ifndef USE_ARGV
|
#ifndef USE_ARGV
|
||||||
ga_init2(&ga, (int)sizeof(char*), 20);
|
ga_init2(&ga, (int)sizeof(char*), 20);
|
||||||
@@ -14870,14 +14964,11 @@ theend:
|
|||||||
static void
|
static void
|
||||||
f_job_status(typval_T *argvars, typval_T *rettv)
|
f_job_status(typval_T *argvars, typval_T *rettv)
|
||||||
{
|
{
|
||||||
char *result;
|
job_T *job = get_job_arg(&argvars[0]);
|
||||||
|
char *result;
|
||||||
|
|
||||||
if (argvars[0].v_type != VAR_JOB)
|
if (job != NULL)
|
||||||
EMSG(_(e_invarg));
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
job_T *job = argvars[0].vval.v_job;
|
|
||||||
|
|
||||||
if (job->jv_status == JOB_ENDED)
|
if (job->jv_status == JOB_ENDED)
|
||||||
/* No need to check, dead is dead. */
|
/* No need to check, dead is dead. */
|
||||||
result = "dead";
|
result = "dead";
|
||||||
@@ -14896,9 +14987,9 @@ f_job_status(typval_T *argvars, typval_T *rettv)
|
|||||||
static void
|
static void
|
||||||
f_job_stop(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
|
f_job_stop(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
|
||||||
{
|
{
|
||||||
if (argvars[0].v_type != VAR_JOB)
|
job_T *job = get_job_arg(&argvars[0]);
|
||||||
EMSG(_(e_invarg));
|
|
||||||
else
|
if (job != NULL)
|
||||||
{
|
{
|
||||||
char_u *arg;
|
char_u *arg;
|
||||||
|
|
||||||
@@ -14913,7 +15004,7 @@ f_job_stop(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mch_stop_job(argvars[0].vval.v_job, arg) == FAIL)
|
if (mch_stop_job(job, arg) == FAIL)
|
||||||
rettv->vval.v_number = 0;
|
rettv->vval.v_number = 0;
|
||||||
else
|
else
|
||||||
rettv->vval.v_number = 1;
|
rettv->vval.v_number = 1;
|
||||||
|
@@ -1486,6 +1486,9 @@ getout(int exitval)
|
|||||||
windgoto((int)Rows - 1, 0);
|
windgoto((int)Rows - 1, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef FEAT_JOB
|
||||||
|
job_stop_on_exit();
|
||||||
|
#endif
|
||||||
#ifdef FEAT_LUA
|
#ifdef FEAT_LUA
|
||||||
lua_end();
|
lua_end();
|
||||||
#endif
|
#endif
|
||||||
|
@@ -80,6 +80,7 @@ dictitem_T *dict_find(dict_T *d, char_u *key, int len);
|
|||||||
char_u *get_dict_string(dict_T *d, char_u *key, int save);
|
char_u *get_dict_string(dict_T *d, char_u *key, int save);
|
||||||
long get_dict_number(dict_T *d, char_u *key);
|
long get_dict_number(dict_T *d, char_u *key);
|
||||||
int channel_unref(channel_T *channel);
|
int channel_unref(channel_T *channel);
|
||||||
|
void job_stop_on_exit(void);
|
||||||
int string2float(char_u *text, float_T *value);
|
int string2float(char_u *text, float_T *value);
|
||||||
char_u *get_function_name(expand_T *xp, int idx);
|
char_u *get_function_name(expand_T *xp, int idx);
|
||||||
char_u *get_expr_name(expand_T *xp, int idx);
|
char_u *get_expr_name(expand_T *xp, int idx);
|
||||||
|
@@ -1253,6 +1253,8 @@ typedef enum
|
|||||||
*/
|
*/
|
||||||
struct jobvar_S
|
struct jobvar_S
|
||||||
{
|
{
|
||||||
|
job_T *jv_next;
|
||||||
|
job_T *jv_prev;
|
||||||
#ifdef UNIX
|
#ifdef UNIX
|
||||||
pid_t jv_pid;
|
pid_t jv_pid;
|
||||||
int jv_exitval;
|
int jv_exitval;
|
||||||
@@ -1262,6 +1264,7 @@ struct jobvar_S
|
|||||||
HANDLE jv_job_object;
|
HANDLE jv_job_object;
|
||||||
#endif
|
#endif
|
||||||
jobstatus_T jv_status;
|
jobstatus_T jv_status;
|
||||||
|
char_u *jv_stoponexit; /* allocated */
|
||||||
|
|
||||||
int jv_refcount; /* reference count */
|
int jv_refcount; /* reference count */
|
||||||
channel_T *jv_channel; /* channel for I/O, reference counted */
|
channel_T *jv_channel; /* channel for I/O, reference counted */
|
||||||
@@ -1386,6 +1389,7 @@ struct channel_S {
|
|||||||
#define JO_ERR_TIMEOUT 0x0400 /* stderr timeouts */
|
#define JO_ERR_TIMEOUT 0x0400 /* stderr timeouts */
|
||||||
#define JO_PART 0x0800 /* "part" */
|
#define JO_PART 0x0800 /* "part" */
|
||||||
#define JO_ID 0x1000 /* "id" */
|
#define JO_ID 0x1000 /* "id" */
|
||||||
|
#define JO_STOPONEXIT 0x2000 /* "stoponexit" */
|
||||||
#define JO_ALL 0xffffff
|
#define JO_ALL 0xffffff
|
||||||
|
|
||||||
#define JO_MODE_ALL (JO_MODE + JO_IN_MODE + JO_OUT_MODE + JO_ERR_MODE)
|
#define JO_MODE_ALL (JO_MODE + JO_IN_MODE + JO_OUT_MODE + JO_ERR_MODE)
|
||||||
@@ -1412,6 +1416,8 @@ typedef struct
|
|||||||
int jo_err_timeout;
|
int jo_err_timeout;
|
||||||
int jo_part;
|
int jo_part;
|
||||||
int jo_id;
|
int jo_id;
|
||||||
|
char_u jo_soe_buf[NUMBUFLEN];
|
||||||
|
char_u *jo_stoponexit;
|
||||||
} jobopt_T;
|
} jobopt_T;
|
||||||
|
|
||||||
|
|
||||||
|
@@ -44,7 +44,8 @@ func s:run_server(testfunc, ...)
|
|||||||
|
|
||||||
try
|
try
|
||||||
if has('job')
|
if has('job')
|
||||||
let s:job = job_start(cmd)
|
let s:job = job_start(cmd, {"stoponexit": "hup"})
|
||||||
|
call job_setoptions(s:job, {"stoponexit": "kill"})
|
||||||
elseif has('win32')
|
elseif has('win32')
|
||||||
exe 'silent !start cmd /c start "test_channel" ' . cmd
|
exe 'silent !start cmd /c start "test_channel" ' . cmd
|
||||||
else
|
else
|
||||||
|
@@ -747,6 +747,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 */
|
||||||
|
/**/
|
||||||
|
1378,
|
||||||
/**/
|
/**/
|
||||||
1377,
|
1377,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user