]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
sandbox: handle case where dev node for tty doesn't exist
authorClayton Craft <clayton@craftyguy.net>
Wed, 21 May 2025 22:59:36 +0000 (15:59 -0700)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 22 May 2025 03:57:31 +0000 (05:57 +0200)
This fixes this crash, which happens even when isatty(2) is True:

Traceback (most recent call last):
  File "/sandbox.py", line 1095, in <module>
    main()
  File "/sandbox.py", line 891, in main
    ttyname = os.ttyname(2) if os.isatty(2) else ""
              ^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory

IIUC this is because isatty(2) is a valid file descriptor (inherited
from the parent process?), but ttyname() is unable find a device node
for it because it's not mounted in the sandbox.

mkosi/sandbox.py

index c79b48739f3d7127375274bc0b1ef3463cae9032..81e27a5072040b3b9f8dc1915aebdbe57d4da5d3 100755 (executable)
@@ -885,7 +885,10 @@ def main() -> None:
     chdir = None
     become_root = suppress_chown = suppress_sync = unshare_net = unshare_ipc = suspend = pack_fds = False
 
-    ttyname = os.ttyname(2) if os.isatty(2) else ""
+    try:
+        ttyname = os.ttyname(2) if os.isatty(2) else ""
+    except FileNotFoundError:
+        ttyname = ""
 
     while argv:
         arg = argv.pop()