From 31319f0b6509296b0db6d3b6a1ba4a69cda7f0ea Mon Sep 17 00:00:00 2001 From: Samuel Tam Date: Sun, 19 Mar 2023 18:45:47 +0800 Subject: [PATCH 1/2] kitty_tests/ssh.py: skip login shell detection if getpwuid() fails --- kitty_tests/ssh.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kitty_tests/ssh.py b/kitty_tests/ssh.py index b03668d1e..cd38f4847 100644 --- a/kitty_tests/ssh.py +++ b/kitty_tests/ssh.py @@ -173,7 +173,11 @@ env COLORTERM methods.append('using_passwd') self.assertTrue(methods) import pwd - expected_login_shell = pwd.getpwuid(os.geteuid()).pw_shell + try: + expected_login_shell = pwd.getpwuid(os.geteuid()).pw_shell + except KeyError: + with suppress(Exception): + self.skipTest('Skipping login shell detection as getpwuid() failed to read login shell') if os.path.basename(expected_login_shell) == 'nologin': self.skipTest('Skipping login shell detection as login shell is set to nologin') for m in methods: From 8a7491722f2066b767aa6a2634e0604d8423049a Mon Sep 17 00:00:00 2001 From: Samuel Tam Date: Sun, 19 Mar 2023 19:09:14 +0800 Subject: [PATCH 2/2] shell-integration/ssh/bootstrap.py: suppress getpwuid() exceptions Reference: 89e5ae28bb60d5bf3aaadf25d62ea0864e5136bb --- shell-integration/ssh/bootstrap.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/shell-integration/ssh/bootstrap.py b/shell-integration/ssh/bootstrap.py index 4cc4afef2..9c73f2e54 100644 --- a/shell-integration/ssh/bootstrap.py +++ b/shell-integration/ssh/bootstrap.py @@ -20,7 +20,12 @@ echo_on = int('ECHO_ON') data_dir = shell_integration_dir = '' request_data = int('REQUEST_DATA') leading_data = b'' -login_shell = pwd.getpwuid(os.geteuid()).pw_shell or os.environ.get('SHELL') or 'sh' +try: + login_shell = pwd.getpwuid(os.geteuid()).pw_shell or os.environ.get('SHELL') or '/bin/sh' +except KeyError: + login_shell = os.environ.get('SHELL') or '/bin/sh' + with suppress(Exception): + print('Failed to read login shell via getpwuid() for current user, falling back to', login_shell, file=sys.stderr) export_home_cmd = b'EXPORT_HOME_CMD' if export_home_cmd: HOME = base64.standard_b64decode(export_home_cmd).decode('utf-8')