diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-07-21 16:37:07 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2019-07-21 20:51:37 +0200 |
commit | b08dc3ec195feb4ab69c898ab816c104d2aa1aa1 (patch) | |
tree | 3e614d685f1b0335719df538377b93a491eae3ed /src | |
parent | 9d0f8224c97b36116f3c0523bcf6941382892a5b (diff) | |
download | rneovim-b08dc3ec195feb4ab69c898ab816c104d2aa1aa1.tar.gz rneovim-b08dc3ec195feb4ab69c898ab816c104d2aa1aa1.tar.bz2 rneovim-b08dc3ec195feb4ab69c898ab816c104d2aa1aa1.zip |
win: jobstart(), system(): $PATHEXT-resolve exe
Windows: In order for jobstart(['foo']), system(['foo']) to find
"foo.cmd", we must replace "foo" with "foo.cmd" before sending `argv` to
process_spawn().
Rationale: jobstart([…]), system([…]) "executable" semantics should be
consistent with the VimL executable() function.
fix #9569
related: #10554
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/eval.c | 19 | ||||
-rw-r--r-- | src/nvim/os/fs.c | 5 |
2 files changed, 17 insertions, 7 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 6774000ae4..f27e73a7a2 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -12084,10 +12084,11 @@ static void f_jobresize(typval_T *argvars, typval_T *rettv, FunPtr fptr) /// @param[out] executable Returns `false` if argv[0] is not executable. /// /// @returns Result of `shell_build_argv()` if `cmd_tv` is a String. -/// Else, string values of `cmd_tv` copied to a (char **) list. +/// Else, string values of `cmd_tv` copied to a (char **) list with +/// argv[0] resolved to full path ($PATHEXT-resolved on Windows). static char **tv_to_argv(typval_T *cmd_tv, const char **cmd, bool *executable) { - if (cmd_tv->v_type == VAR_STRING) { + if (cmd_tv->v_type == VAR_STRING) { // String => "shell semantics". const char *cmd_str = tv_get_string(cmd_tv); if (cmd) { *cmd = cmd_str; @@ -12107,16 +12108,17 @@ static char **tv_to_argv(typval_T *cmd_tv, const char **cmd, bool *executable) return NULL; } - const char *exe = tv_get_string_chk(TV_LIST_ITEM_TV(tv_list_first(argl))); - if (!exe || !os_can_exe((const char_u *)exe, NULL, true)) { - if (exe && executable) { + const char *arg0 = tv_get_string_chk(TV_LIST_ITEM_TV(tv_list_first(argl))); + char_u *exe_resolved = NULL; + if (!arg0 || !os_can_exe((const char_u *)arg0, &exe_resolved, true)) { + if (arg0 && executable) { *executable = false; } return NULL; } if (cmd) { - *cmd = exe; + *cmd = exe_resolved; } // Build the argument vector @@ -12127,10 +12129,15 @@ static char **tv_to_argv(typval_T *cmd_tv, const char **cmd, bool *executable) if (!a) { // Did emsg in tv_get_string_chk; just deallocate argv. shell_free_argv(argv); + xfree(exe_resolved); return NULL; } argv[i++] = xstrdup(a); }); + // Replace argv[0] with absolute path. The only reason for this is to make + // $PATHEXT work on Windows with jobstart([…]). #9569 + xfree(argv[0]); + argv[0] = exe_resolved; return argv; } diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 4a10b5199c..f34592d107 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -230,7 +230,7 @@ int os_exepath(char *buffer, size_t *size) /// Checks if the file `name` is executable. /// /// @param[in] name Filename to check. -/// @param[out] abspath Returns resolved executable path, if not NULL. +/// @param[out,allocated] abspath Returns resolved exe path, if not NULL. /// @param[in] use_path Also search $PATH. /// /// @return true if `name` is executable and @@ -271,6 +271,9 @@ bool os_can_exe(const char_u *name, char_u **abspath, bool use_path) } /// Returns true if `name` is an executable file. +/// +/// @param[in] name Filename to check. +/// @param[out,allocated] abspath Returns full exe path, if not NULL. static bool is_executable(const char *name, char_u **abspath) FUNC_ATTR_NONNULL_ARG(1) { |