pty: set TERM env for the pty process

This commit is contained in:
Shuanglei Tao
2021-08-08 20:05:34 +08:00
parent 9e9c2ac142
commit 619bfc34cd
3 changed files with 8 additions and 0 deletions

View File

@@ -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);

View File

@@ -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");

View File

@@ -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;