diff options
Diffstat (limited to 'src/nvim/os/pty_process_win.c')
-rw-r--r-- | src/nvim/os/pty_process_win.c | 168 |
1 files changed, 22 insertions, 146 deletions
diff --git a/src/nvim/os/pty_process_win.c b/src/nvim/os/pty_process_win.c index f78f3e66f5..6233a90638 100644 --- a/src/nvim/os/pty_process_win.c +++ b/src/nvim/os/pty_process_win.c @@ -4,7 +4,6 @@ #include <assert.h> #include <stdbool.h> #include <stdlib.h> -#include <winpty_constants.h> #include "nvim/ascii.h" #include "nvim/mbyte.h" // for utf8_to_utf16, utf16_to_utf8 @@ -23,11 +22,7 @@ static void CALLBACK pty_process_finish1(void *context, BOOLEAN unused) PtyProcess *ptyproc = (PtyProcess *)context; Process *proc = (Process *)ptyproc; - if (ptyproc->type == kConpty - && ptyproc->object.conpty != NULL) { - os_conpty_free(ptyproc->object.conpty); - ptyproc->object.conpty = NULL; - } + os_conpty_free(ptyproc->conpty); uv_timer_init(&proc->loop->uv, &ptyproc->wait_eof_timer); ptyproc->wait_eof_timer.data = (void *)ptyproc; uv_timer_start(&ptyproc->wait_eof_timer, wait_eof_timer_cb, 200, 200); @@ -39,10 +34,6 @@ int pty_process_spawn(PtyProcess *ptyproc) { Process *proc = (Process *)ptyproc; int status = 0; - winpty_error_ptr_t err = NULL; - winpty_config_t *cfg = NULL; - winpty_spawn_config_t *spawncfg = NULL; - winpty_t *winpty_object = NULL; conpty_t *conpty_object = NULL; char *in_name = NULL; char *out_name = NULL; @@ -56,39 +47,11 @@ int pty_process_spawn(PtyProcess *ptyproc) assert(proc->err.closed); - if (os_has_conpty_working()) { - if ((conpty_object = - os_conpty_init(&in_name, &out_name, - ptyproc->width, ptyproc->height)) != NULL) { - ptyproc->type = kConpty; - } - } - - if (ptyproc->type == kWinpty) { - cfg = winpty_config_new(WINPTY_FLAG_ALLOW_CURPROC_DESKTOP_CREATION, &err); - if (cfg == NULL) { - emsg = "winpty_config_new failed"; - goto cleanup; - } - - winpty_config_set_initial_size(cfg, ptyproc->width, ptyproc->height); - winpty_object = winpty_open(cfg, &err); - if (winpty_object == NULL) { - emsg = "winpty_open failed"; - goto cleanup; - } - - status = utf16_to_utf8(winpty_conin_name(winpty_object), -1, &in_name); - if (status != 0) { - emsg = "utf16_to_utf8(winpty_conin_name) failed"; - goto cleanup; - } - - status = utf16_to_utf8(winpty_conout_name(winpty_object), -1, &out_name); - if (status != 0) { - emsg = "utf16_to_utf8(winpty_conout_name) failed"; - goto cleanup; - } + if (!os_has_conpty_working() || (conpty_object = os_conpty_init(&in_name, + &out_name, ptyproc->width, + ptyproc->height)) == NULL) { + status = UV_ENOSYS; + goto cleanup; } if (!proc->in.closed) { @@ -131,44 +94,15 @@ int pty_process_spawn(PtyProcess *ptyproc) goto cleanup; } - if (ptyproc->type == kConpty) { - if (!os_conpty_spawn(conpty_object, - &process_handle, - NULL, - cmd_line, - cwd, - env)) { - emsg = "os_conpty_spawn failed"; - status = (int)GetLastError(); - goto cleanup; - } - } else { - spawncfg = winpty_spawn_config_new(WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN, - NULL, // Optional application name - cmd_line, - cwd, - env, - &err); - if (spawncfg == NULL) { - emsg = "winpty_spawn_config_new failed"; - goto cleanup; - } - - DWORD win_err = 0; - if (!winpty_spawn(winpty_object, - spawncfg, - &process_handle, - NULL, // Optional thread handle - &win_err, - &err)) { - if (win_err) { - status = (int)win_err; - emsg = "failed to spawn process"; - } else { - emsg = "winpty_spawn failed"; - } - goto cleanup; - } + if (!os_conpty_spawn(conpty_object, + &process_handle, + NULL, + cmd_line, + cwd, + env)) { + emsg = "os_conpty_spawn failed"; + status = (int)GetLastError(); + goto cleanup; } proc->pid = (int)GetProcessId(process_handle); @@ -187,11 +121,8 @@ int pty_process_spawn(PtyProcess *ptyproc) uv_run(&proc->loop->uv, UV_RUN_ONCE); } - (ptyproc->type == kConpty) ? - (void *)(ptyproc->object.conpty = conpty_object) : - (void *)(ptyproc->object.winpty = winpty_object); + ptyproc->conpty = conpty_object; ptyproc->process_handle = process_handle; - winpty_object = NULL; conpty_object = NULL; process_handle = NULL; @@ -201,16 +132,7 @@ cleanup: ELOG("pty_process_spawn(%s): %s: error code: %d", proc->argv[0], emsg, status); status = os_translate_sys_error(status); - } else if (err != NULL) { - status = (int)winpty_error_code(err); - ELOG("pty_process_spawn(%s): %s: error code: %d", - proc->argv[0], emsg, status); - status = translate_winpty_error(status); } - winpty_error_free(err); - winpty_config_free(cfg); - winpty_spawn_config_free(spawncfg); - winpty_free(winpty_object); os_conpty_free(conpty_object); xfree(in_name); xfree(out_name); @@ -233,12 +155,7 @@ const char *pty_process_tty_name(PtyProcess *ptyproc) void pty_process_resize(PtyProcess *ptyproc, uint16_t width, uint16_t height) FUNC_ATTR_NONNULL_ALL { - if (ptyproc->type == kConpty - && ptyproc->object.conpty != NULL) { - os_conpty_set_size(ptyproc->object.conpty, width, height); - } else if (ptyproc->object.winpty != NULL) { - winpty_set_size(ptyproc->object.winpty, width, height, NULL); - } + os_conpty_set_size(ptyproc->conpty, width, height); } void pty_process_close(PtyProcess *ptyproc) @@ -255,18 +172,11 @@ void pty_process_close(PtyProcess *ptyproc) void pty_process_close_master(PtyProcess *ptyproc) FUNC_ATTR_NONNULL_ALL -{ - if (ptyproc->type == kWinpty - && ptyproc->object.winpty != NULL) { - winpty_free(ptyproc->object.winpty); - ptyproc->object.winpty = NULL; - } -} +{} void pty_process_teardown(Loop *loop) FUNC_ATTR_NONNULL_ALL -{ -} +{} static void pty_process_connect_cb(uv_connect_t *req, int status) FUNC_ATTR_NONNULL_ALL @@ -281,7 +191,7 @@ static void wait_eof_timer_cb(uv_timer_t *wait_eof_timer) PtyProcess *ptyproc = wait_eof_timer->data; Process *proc = (Process *)ptyproc; - if (proc->out.closed || !uv_is_readable(proc->out.uvstream)) { + if (proc->out.closed || proc->out.did_eof || !uv_is_readable(proc->out.uvstream)) { uv_timer_stop(&ptyproc->wait_eof_timer); pty_process_finish2(ptyproc); } @@ -308,7 +218,7 @@ static void pty_process_finish2(PtyProcess *ptyproc) /// Build the command line to pass to CreateProcessW. /// /// @param[in] argv Array with string arguments. -/// @param[out] cmd_line Location where saved builded cmd line. +/// @param[out] cmd_line Location where saved built cmd line. /// /// @returns zero on success, or error code of MultiByteToWideChar function. /// @@ -435,40 +345,6 @@ static void quote_cmd_arg(char *dest, size_t dest_remaining, const char *src) } } -/// Translate winpty error code to libuv error. -/// -/// @param[in] winpty_errno Winpty error code returned by winpty_error_code -/// function. -/// -/// @returns Error code of libuv error. -int translate_winpty_error(int winpty_errno) -{ - if (winpty_errno <= 0) { - return winpty_errno; // If < 0 then it's already a libuv error. - } - - switch (winpty_errno) { - case WINPTY_ERROR_OUT_OF_MEMORY: - return UV_ENOMEM; - case WINPTY_ERROR_SPAWN_CREATE_PROCESS_FAILED: - return UV_EAI_FAIL; - case WINPTY_ERROR_LOST_CONNECTION: - return UV_ENOTCONN; - case WINPTY_ERROR_AGENT_EXE_MISSING: - return UV_ENOENT; - case WINPTY_ERROR_UNSPECIFIED: - return UV_UNKNOWN; - case WINPTY_ERROR_AGENT_DIED: - return UV_ESRCH; - case WINPTY_ERROR_AGENT_TIMEOUT: - return UV_ETIMEDOUT; - case WINPTY_ERROR_AGENT_CREATION_FAILED: - return UV_EAI_FAIL; - default: - return UV_UNKNOWN; - } -} - typedef struct EnvNode { wchar_t *str; size_t len; @@ -485,7 +361,7 @@ static int build_env_block(dict_T *denv, wchar_t **env_block) { const size_t denv_size = (size_t)tv_dict_len(denv); size_t env_block_len = 0; - int rc; + int rc = 0; char **env = tv_dict_to_env(denv); QUEUE *q; |