Cleanup editing of proc environ

This commit is contained in:
Kovid Goyal 2022-07-26 16:38:37 +05:30
parent a01dbbdf04
commit cc7e668ad6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 10 additions and 4 deletions

View File

@ -126,7 +126,7 @@ def socket_child_main(exit_code=0, initial_print=''):
argv=[kitty_exe(), '+runpy', src + 'socket_child_main(initial_print="child ready:")'], cols=cols, env=env, cwd=cwd) argv=[kitty_exe(), '+runpy', src + 'socket_child_main(initial_print="child ready:")'], cols=cols, env=env, cwd=cwd)
pty.wait_till(lambda: 'child ready:' in pty.screen_contents()) pty.wait_till(lambda: 'child ready:' in pty.screen_contents())
from kitty.child import environ_of_process from kitty.child import environ_of_process
self.assertIn('/', environ_of_process(pty.child_pid).get('KITTY_PREWARM_SOCKET_REAL_TTY')) self.assertIn('/', environ_of_process(pty.child_pid).get('KITTY_PREWARM_SOCKET_REAL_TTY', ''))
os.close(pty.master_fd) os.close(pty.master_fd)
with self.subTest(msg='test passing of data via cwd, env vars and stdin/stdout redirection'): with self.subTest(msg='test passing of data via cwd, env vars and stdin/stdout redirection'):

View File

@ -702,9 +702,15 @@ use_prewarmed_process(int argc, char *argv[], char *envp[]) {
#undef fail #undef fail
while (*envp) { while (*envp) {
if (strncmp(*envp, "KITTY_PREWARM_SOCKET_REAL_TTY=", 2) == 0) { char *p = *envp;
char *p = *envp + sizeof("KITTY_PREWARM_SOCKET_REAL_TTY=") - 1; const char *q = "KITTY_PREWARM_SOCKET_REAL_TTY=";
snprintf(p, strlen(p) + 1, "%s", child_tty_name); while (*p && *q && *p == *q) {
if (*p == '=') {
p++;
snprintf(p, strlen(p) + 1, "%s", child_tty_name);
break;
}
p++; q++;
} }
envp++; envp++;
} }