From cc7e668ad69f54f4d3eddd52c3760a304748ab32 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 26 Jul 2022 16:38:37 +0530 Subject: [PATCH] Cleanup editing of proc environ --- kitty_tests/prewarm.py | 2 +- prewarm-launcher.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/kitty_tests/prewarm.py b/kitty_tests/prewarm.py index 108562aa4..a098c11fb 100644 --- a/kitty_tests/prewarm.py +++ b/kitty_tests/prewarm.py @@ -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) pty.wait_till(lambda: 'child ready:' in pty.screen_contents()) 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) with self.subTest(msg='test passing of data via cwd, env vars and stdin/stdout redirection'): diff --git a/prewarm-launcher.c b/prewarm-launcher.c index f6304894b..0bc61eddf 100644 --- a/prewarm-launcher.c +++ b/prewarm-launcher.c @@ -702,9 +702,15 @@ use_prewarmed_process(int argc, char *argv[], char *envp[]) { #undef fail while (*envp) { - if (strncmp(*envp, "KITTY_PREWARM_SOCKET_REAL_TTY=", 2) == 0) { - char *p = *envp + sizeof("KITTY_PREWARM_SOCKET_REAL_TTY=") - 1; - snprintf(p, strlen(p) + 1, "%s", child_tty_name); + char *p = *envp; + const char *q = "KITTY_PREWARM_SOCKET_REAL_TTY="; + while (*p && *q && *p == *q) { + if (*p == '=') { + p++; + snprintf(p, strlen(p) + 1, "%s", child_tty_name); + break; + } + p++; q++; } envp++; }