mirror of
https://github.com/lucannez64/darling-lol.git
synced 2026-10-26 19:47:42 +00:00
A terminal, IDE or service manager can leave descriptors open in the launcher, and the guest inherited all of them. tools/exec-guest.py closes every descriptor above stderr and then execs the guest command. A shell loop over /proc/self/fd cannot do this portably: dash only parses single-digit descriptors in redirections, so "exec 10>&-" runs a command named 10 and ends the launcher on Debian and Ubuntu. The launcher offline check now leaks descriptors 3, 4, 12 and 200 into the launcher and asserts the guest sees only 0, 1 and 2. It runs in CI. Split from #61. Co-authored-by: DevWebeloper <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
31 lines
825 B
Python
Executable File
31 lines
825 B
Python
Executable File
#!/usr/bin/env python3
|
|
"""Run a command without the host file descriptors this launcher inherited (anything above stderr)."""
|
|
import os
|
|
import sys
|
|
|
|
|
|
def close_inherited_fds():
|
|
"""A terminal, IDE or service manager can leak descriptors; the guest must not inherit them."""
|
|
try:
|
|
names = os.listdir('/proc/self/fd')
|
|
except OSError:
|
|
os.closerange(3, 65536)
|
|
return
|
|
for name in names:
|
|
if name.isdigit() and int(name) > 2:
|
|
try:
|
|
os.close(int(name))
|
|
except OSError:
|
|
pass # the descriptor listdir used is already closed
|
|
|
|
|
|
def main(argv):
|
|
if len(argv) < 2:
|
|
sys.exit('usage: exec-guest.py COMMAND [ARGUMENT]...')
|
|
close_inherited_fds()
|
|
os.execvp(argv[1], argv[1:])
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main(sys.argv)
|