Convert the hard-coded DGRAM communication to util.jsoncomm. This avoids hard-coding any IPC-details and simplifies the callers quite a bit.
25 lines
601 B
Python
Executable file
25 lines
601 B
Python
Executable file
#!/usr/bin/python3
|
|
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
from osbuild.util import jsoncomm
|
|
|
|
|
|
def setup_stdio():
|
|
with jsoncomm.Socket.new_client("/run/osbuild/api/osbuild") as client:
|
|
req = {'method': 'setup-stdio'}
|
|
client.send(req)
|
|
msg, fds, _ = client.recv()
|
|
for io in ['stdin', 'stdout', 'stderr']:
|
|
target = getattr(sys, io)
|
|
source = fds[msg[io]]
|
|
os.dup2(source, target.fileno())
|
|
fds.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
setup_stdio()
|
|
|
|
r = subprocess.run(sys.argv[1:], check=False)
|
|
sys.exit(r.returncode)
|