|
|
|
@ -68,21 +68,8 @@ def spawn(func, **kwargs):
|
|
|
|
|
t.join()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run(command, environ):
|
|
|
|
|
log.debug('running %r with %r', command, environ)
|
|
|
|
|
env = dict(os.environ)
|
|
|
|
|
env.update(environ)
|
|
|
|
|
try:
|
|
|
|
|
p = subprocess.Popen(args=command, env=env)
|
|
|
|
|
except OSError as e:
|
|
|
|
|
raise OSError('cannot run %r: %s' % (command, e))
|
|
|
|
|
log.debug('subprocess %d is running', p.pid)
|
|
|
|
|
ret = p.wait()
|
|
|
|
|
log.debug('subprocess %d exited: %d', p.pid, ret)
|
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def serve(key_files, command, signer, sock_path=None):
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
|
def serve(key_files, signer, sock_path=None):
|
|
|
|
|
if sock_path is None:
|
|
|
|
|
sock_path = tempfile.mktemp(prefix='ssh-agent-')
|
|
|
|
|
|
|
|
|
@ -91,8 +78,21 @@ def serve(key_files, command, signer, sock_path=None):
|
|
|
|
|
with unix_domain_socket_server(sock_path) as server:
|
|
|
|
|
with spawn(server_thread, server=server, keys=keys, signer=signer):
|
|
|
|
|
try:
|
|
|
|
|
ret = run(command=command, environ=environ)
|
|
|
|
|
yield environ
|
|
|
|
|
finally:
|
|
|
|
|
log.debug('closing server')
|
|
|
|
|
server.shutdown(socket.SHUT_RD)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run_process(command, environ):
|
|
|
|
|
log.debug('running %r with %r', command, environ)
|
|
|
|
|
env = dict(os.environ)
|
|
|
|
|
env.update(environ)
|
|
|
|
|
try:
|
|
|
|
|
p = subprocess.Popen(args=command, env=env)
|
|
|
|
|
except OSError as e:
|
|
|
|
|
raise OSError('cannot run %r: %s' % (command, e))
|
|
|
|
|
log.debug('subprocess %d is running', p.pid)
|
|
|
|
|
ret = p.wait()
|
|
|
|
|
log.debug('subprocess %d exited: %d', p.pid, ret)
|
|
|
|
|
return ret
|
|
|
|
|