From 619bfc34cd11d67956deda83e6447fcf1c223373 Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Sun, 8 Aug 2021 20:05:34 +0800 Subject: [PATCH] pty: set TERM env for the pty process --- src/protocol.c | 1 + src/pty.c | 6 ++++++ src/pty.h | 1 + 3 files changed, 8 insertions(+) diff --git a/src/protocol.c b/src/protocol.c index e7255c3..8aa2021 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -110,6 +110,7 @@ static bool spawn_process(struct pss_tty *pss, uint16_t columns, uint16_t rows) pty_process *process = process_init((void *) pss, server->loop, argv); if (columns > 0) process->columns = columns; if (rows > 0) process->rows = rows; + strncpy(process->term, server->terminal_type, sizeof(process->term)); if (pty_spawn(process, process_read_cb, process_exit_cb) != 0) { lwsl_err("pty_spawn: %d (%s)\n", errno, strerror(errno)); process_free(process); diff --git a/src/pty.c b/src/pty.c index daa34c3..1a9d17f 100644 --- a/src/pty.c +++ b/src/pty.c @@ -334,6 +334,11 @@ int pty_spawn(pty_process *process, pty_read_cb read_cb, pty_exit_cb exit_cb) { cmdline = join_args(process->argv); if (cmdline == NULL) goto cleanup; + // TODO: restore env after process creation + if (!SetEnvironmentVariable("TERM", process->term)) { + print_error("SetEnvironmentVariable"); + } + if (!CreateProcessW(NULL, cmdline, NULL, NULL, FALSE, flags, NULL, NULL, &process->si.StartupInfo, &pi)) { print_error("CreateProcessW"); goto cleanup; @@ -421,6 +426,7 @@ int pty_spawn(pty_process *process, pty_read_cb read_cb, pty_exit_cb exit_cb) { return status; } else if (pid == 0) { setsid(); + setenv("TERM", process->term, true); int ret = execvp(process->argv[0], process->argv); if (ret < 0) { perror("execvp failed\n"); diff --git a/src/pty.h b/src/pty.h index 07f9fc1..51ff97b 100644 --- a/src/pty.h +++ b/src/pty.h @@ -39,6 +39,7 @@ typedef void (*pty_exit_cb)(void *, pty_process *); struct pty_process_ { int pid, exit_code, exit_signal; uint16_t columns, rows; + char term[30]; bool killed; #ifdef _WIN32 STARTUPINFOEXW si; -- 2.43.4