Merge #5750 from justinmk/jobstart

jobstart(): Return -1 if cmd is non-executable
This commit is contained in:
Justin M. Keyes 2016-12-11 01:38:17 +01:00 committed by GitHub
commit 0fe89fc9d7
32 changed files with 29 additions and 152 deletions

View File

@ -11581,7 +11581,7 @@ static void f_jobresize(typval_T *argvars, typval_T *rettv, FunPtr fptr)
rettv->vval.v_number = 1;
}
static char **tv_to_argv(typval_T *cmd_tv, char **cmd)
static char **tv_to_argv(typval_T *cmd_tv, char **cmd, bool *executable)
{
if (cmd_tv->v_type == VAR_STRING) {
char *cmd_str = (char *)get_tv_string(cmd_tv);
@ -11599,7 +11599,7 @@ static char **tv_to_argv(typval_T *cmd_tv, char **cmd)
list_T *argl = cmd_tv->vval.v_list;
int argc = argl->lv_len;
if (!argc) {
EMSG(_("Argument vector must have at least one item"));
EMSG(_(e_invarg)); // List must have at least one item.
return NULL;
}
@ -11607,9 +11607,8 @@ static char **tv_to_argv(typval_T *cmd_tv, char **cmd)
const char_u *exe = get_tv_string_chk(&argl->lv_first->li_tv);
if (!exe || !os_can_exe(exe, NULL, true)) {
// String is not executable
if (exe) {
EMSG2(e_jobexe, exe);
if (exe && executable) {
*executable = false;
}
return NULL;
}
@ -11617,7 +11616,7 @@ static char **tv_to_argv(typval_T *cmd_tv, char **cmd)
if (cmd) {
*cmd = (char *)exe;
}
// Build the argument vector
int i = 0;
char **argv = xcalloc(argc + 1, sizeof(char *));
@ -11644,8 +11643,10 @@ static void f_jobstart(typval_T *argvars, typval_T *rettv, FunPtr fptr)
return;
}
char **argv = tv_to_argv(&argvars[0], NULL);
bool executable = true;
char **argv = tv_to_argv(&argvars[0], NULL, &executable);
if (!argv) {
rettv->vval.v_number = executable ? 0 : -1;
return; // Did error message in tv_to_argv.
}
@ -16235,7 +16236,7 @@ static void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv,
}
// get shell command to execute
char **argv = tv_to_argv(&argvars[0], NULL);
char **argv = tv_to_argv(&argvars[0], NULL, NULL);
if (!argv) {
xfree(input);
return; // Already did emsg.
@ -16468,8 +16469,10 @@ static void f_termopen(typval_T *argvars, typval_T *rettv, FunPtr fptr)
}
char *cmd;
char **argv = tv_to_argv(&argvars[0], &cmd);
bool executable = true;
char **argv = tv_to_argv(&argvars[0], &cmd, &executable);
if (!argv) {
rettv->vval.v_number = executable ? 0 : -1;
return; // Did error message in tv_to_argv.
}

View File

@ -1125,7 +1125,6 @@ EXTERN char_u e_invcmd[] INIT(= N_("E476: Invalid command"));
EXTERN char_u e_isadir2[] INIT(= N_("E17: \"%s\" is a directory"));
EXTERN char_u e_invjob[] INIT(= N_("E900: Invalid job id"));
EXTERN char_u e_jobtblfull[] INIT(= N_("E901: Job table is full"));
EXTERN char_u e_jobexe[] INIT(= N_("E902: \"%s\" is not an executable"));
EXTERN char_u e_jobspawn[] INIT(= N_(
"E903: Process for command \"%s\" could not be spawned"));
EXTERN char_u e_jobnotpty[] INIT(= N_("E904: Job is not connected to a pty"));

View File

@ -2722,11 +2722,6 @@ msgstr "E49: Ongeldige rolgrootte"
msgid "E901: Job table is full"
msgstr ""
#: ../globals.h:1022
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr ""
#: ../globals.h:1024
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -2717,11 +2717,6 @@ msgstr "E49: La dist
msgid "E901: Job table is full"
msgstr ""
#: ../globals.h:1022
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr ""
#: ../globals.h:1024
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -2763,11 +2763,6 @@ msgstr "E49: Chybn
msgid "E901: Job table is full"
msgstr ""
#: ../globals.h:1022
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr ""
#: ../globals.h:1024
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -2763,11 +2763,6 @@ msgstr "E49: Chybn
msgid "E901: Job table is full"
msgstr ""
#: ../globals.h:1022
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr ""
#: ../globals.h:1024
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -2137,11 +2137,6 @@ msgstr "E900: Ung
msgid "E901: Job table is full"
msgstr "E901: Job-Tabelle ist voll"
#: ../globals.h:1021
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr "E902: \"%s\" ist nicht ausführbar"
#: ../globals.h:1023
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -2623,11 +2623,6 @@ msgstr ""
msgid "E901: Job table is full"
msgstr ""
#: ../globals.h:1022
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr ""
#: ../globals.h:1024
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -2697,11 +2697,6 @@ msgstr "E49: Nevalida grando de rulumo"
msgid "E901: Job table is full"
msgstr ""
#: ../globals.h:1022
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr ""
#: ../globals.h:1024
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -2748,11 +2748,6 @@ msgstr "E49: La longitud de desplazamiento no es válida"
msgid "E901: Job table is full"
msgstr ""
#: ../globals.h:1022
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr ""
#: ../globals.h:1024
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -2691,11 +2691,6 @@ msgstr "E49: Virheellinen vierityskoko"
msgid "E901: Job table is full"
msgstr ""
#: ../globals.h:1022
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr ""
#: ../globals.h:1024
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -2879,11 +2879,6 @@ msgstr "E49: Valeur de d
msgid "E901: Job table is full"
msgstr ""
#: ../globals.h:1022
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr ""
#: ../globals.h:1024
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -2684,11 +2684,6 @@ msgstr "E49: M
msgid "E901: Job table is full"
msgstr ""
#: ../globals.h:1022
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr ""
#: ../globals.h:1024
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -2704,11 +2704,6 @@ msgstr "E900: 'Job id' non valido"
msgid "E901: Job table is full"
msgstr "E901: Job table piena"
#: ../globals.h:1022
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr "E902: \"%s\" non è un esegubile"
#: ../globals.h:1024
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -2684,11 +2684,6 @@ msgstr "E49: ̵
msgid "E901: Job table is full"
msgstr ""
#: ../globals.h:1022
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr ""
#: ../globals.h:1024
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -2683,11 +2683,6 @@ msgstr "E49: 無効なスクロール量です"
msgid "E901: Job table is full"
msgstr ""
#: ../globals.h:1022
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr ""
#: ../globals.h:1024
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -2648,11 +2648,6 @@ msgstr "E49: 스크롤 크기가 잘못되었습니다"
msgid "E901: Job table is full"
msgstr ""
#: ../globals.h:1022
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr ""
#: ../globals.h:1024
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -2699,11 +2699,6 @@ msgstr "E49: Ugyldig \"scroll\"-verdi"
msgid "E901: Job table is full"
msgstr ""
#: ../globals.h:1022
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr ""
#: ../globals.h:1024
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -2685,11 +2685,6 @@ msgstr "E49: ongeldige scroll-grootte"
msgid "E901: Job table is full"
msgstr ""
#: ../globals.h:1022
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr ""
#: ../globals.h:1024
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -2699,11 +2699,6 @@ msgstr "E49: Ugyldig \"scroll\"-verdi"
msgid "E901: Job table is full"
msgstr ""
#: ../globals.h:1022
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr ""
#: ../globals.h:1024
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -2658,11 +2658,6 @@ msgstr "E49: Niewłaściwa wielkość przewinięcia"
msgid "E901: Job table is full"
msgstr ""
#: ../globals.h:1022
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr ""
#: ../globals.h:1024
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -2478,11 +2478,6 @@ msgstr "E900: Id do job
msgid "E901: Job table is full"
msgstr "E901: Tabela de jobs está cheia"
#: ../globals.h:1021
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr "E902: \"%s\" não é um executável"
#: ../globals.h:1023
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -2676,11 +2676,6 @@ msgstr "E49: Недопустимый размер прокрутки"
msgid "E901: Job table is full"
msgstr ""
#: ../globals.h:1022
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr ""
#: ../globals.h:1024
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -2689,11 +2689,6 @@ msgstr "E49: Chybn
msgid "E901: Job table is full"
msgstr ""
#: ../globals.h:1022
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr ""
#: ../globals.h:1024
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -2689,11 +2689,6 @@ msgstr "E49: Chybn
msgid "E901: Job table is full"
msgstr ""
#: ../globals.h:1022
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr ""
#: ../globals.h:1024
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -4742,11 +4742,6 @@ msgstr "E900: Ogiltigt jobb-id"
msgid "E901: Job table is full"
msgstr "E901: Jobbtabellen är full"
#: ../globals.h:1008
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr "E902: \"%s\" är inte körbar"
#: ../globals.h:1009
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -2432,10 +2432,6 @@ msgstr "E900: Некоректний ід. завдання"
msgid "E901: Job table is full"
msgstr "E901: Таблиця завдань заповнена"
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr "E902: \"%s\" не можна виконати"
#, c-format
msgid "E903: Process for command \"%s\" could not be spawned"
msgstr "E903: Не вдалося запустити процес для команди «%s»"

View File

@ -2720,11 +2720,6 @@ msgstr "E49: Kích thước thanh cuộn không cho phép"
msgid "E901: Job table is full"
msgstr ""
#: ../globals.h:1022
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr ""
#: ../globals.h:1024
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -2675,11 +2675,6 @@ msgstr "E49: 无效的滚动大小"
msgid "E901: Job table is full"
msgstr ""
#: ../globals.h:1022
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr ""
#: ../globals.h:1024
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -2725,11 +2725,6 @@ msgstr "E49: 錯誤的捲動大小"
msgid "E901: Job table is full"
msgstr ""
#: ../globals.h:1022
#, c-format
msgid "E902: \"%s\" is not an executable"
msgstr ""
#: ../globals.h:1024
#, c-format
msgid "E364: Library call failed for \"%s()\""

View File

@ -65,9 +65,22 @@ describe('jobs', function()
end)
it('returns 0 when it fails to start', function()
local status, rv = pcall(eval, "jobstart([])")
eq(false, status)
ok(rv ~= nil)
eq("", eval("v:errmsg"))
execute("let g:test_jobid = jobstart([])")
eq(0, eval("g:test_jobid"))
eq("E474:", string.match(eval("v:errmsg"), "E%d*:"))
end)
it('returns -1 when target is not executable #5465', function()
local function new_job() return eval([[jobstart(['echo', 'foo'])]]) end
local executable_jobid = new_job()
local nonexecutable_jobid = eval(
"jobstart(['./test/functional/fixtures/non_executable.txt'])")
eq(-1, nonexecutable_jobid)
-- Should _not_ throw an error.
eq("", eval("v:errmsg"))
-- Non-executable job should not increment the job ids. #5465
eq(executable_jobid + 1, new_job())
end)
it('invokes callbacks when the job writes and exits', function()

View File

@ -0,0 +1 @@
This file is not an executable