mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 22:28:24 +02:00
Make setting the real tty name more robust
This commit is contained in:
@@ -252,6 +252,7 @@ class Child:
|
||||
env['KITTY_PID'] = getpid()
|
||||
if not self.is_prewarmed:
|
||||
env['KITTY_PREWARM_SOCKET'] = fast_data_types.get_boss().prewarm.socket_env_var()
|
||||
env['KITTY_PREWARM_SOCKET_REAL_TTY'] = '0' * 32
|
||||
if self.cwd:
|
||||
# needed in case cwd is a symlink, in which case shells
|
||||
# can use it to display the current directory name rather
|
||||
@@ -457,7 +458,12 @@ class Child:
|
||||
import termios
|
||||
if self.child_fd is None:
|
||||
return False
|
||||
t = termios.tcgetattr(self.child_fd)
|
||||
tty_name = self.foreground_environ.get('KITTY_PREWARM_SOCKET_REAL_TTY')
|
||||
if tty_name and tty_name.startswith('/'):
|
||||
with open(os.open(tty_name, os.O_RDWR | os.O_CLOEXEC | os.O_NOCTTY, 0)) as real_tty:
|
||||
t = termios.tcgetattr(real_tty.fileno())
|
||||
else:
|
||||
t = termios.tcgetattr(self.child_fd)
|
||||
if not t[3] & termios.ISIG:
|
||||
return False
|
||||
cc = t[-1]
|
||||
|
||||
@@ -65,7 +65,13 @@ def socket_child_main(exit_code=0, initial_print=''):
|
||||
if p is None:
|
||||
return
|
||||
env = os.environ.copy()
|
||||
env.update({'TEST_ENV_PASS': 'xyz', 'KITTY_PREWARM_SOCKET': p.socket_env_var(), 'TERM': 'xterm-kitty', 'TERMINFO': terminfo_dir})
|
||||
env.update({
|
||||
'TEST_ENV_PASS': 'xyz',
|
||||
'KITTY_PREWARM_SOCKET': p.socket_env_var(),
|
||||
'KITTY_PREWARM_SOCKET_REAL_TTY': '0' * 32,
|
||||
'TERM': 'xterm-kitty',
|
||||
'TERMINFO': terminfo_dir
|
||||
})
|
||||
cols = 117
|
||||
|
||||
def wait_for_death(exit_code, timeout=5):
|
||||
@@ -120,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.assertTrue(environ_of_process(pty.child_pid).get('KITTY_PWPR'))
|
||||
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'):
|
||||
|
||||
@@ -699,8 +699,8 @@ use_prewarmed_process(int argc, char *argv[], char *envp[]) {
|
||||
#undef fail
|
||||
|
||||
while (*envp) {
|
||||
if (strncmp(*envp, "KITTY_PREWARM_SOCKET=", 2) == 0) {
|
||||
sprintf(*envp, "KITTY_PWPR=%s", child_tty_name);
|
||||
if (strncmp(*envp, "KITTY_PREWARM_SOCKET_REAL_TTY=", 2) == 0) {
|
||||
sprintf(*envp, "KITTY_PREWARM_SOCKET_REAL_TTY=%s", child_tty_name);
|
||||
}
|
||||
envp++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user