qubes/tools/qubesd: properly unlink UNIX sockets at shutdown

This commit is contained in:
Wojtek Porczyk 2017-06-05 16:41:14 +02:00 committed by Marek Marczykowski-Górecki
parent 4b8e5c3704
commit 71a4390fdb
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 17 additions and 1 deletions

View File

@ -352,5 +352,7 @@ def create_server(sockpath, handler, app, debug=False, *, loop=None):
finally: finally:
os.umask(old_umask) os.umask(old_umask)
shutil.chown(sockpath, group='qubes') for sock in server.sockets:
shutil.chown(sock.getsockname(), group='qubes')
return server return server

View File

@ -50,6 +50,11 @@ def main(args=None):
qubes.api.misc.QubesMiscAPI, qubes.api.misc.QubesMiscAPI,
app=args.app, debug=args.debug))) app=args.app, debug=args.debug)))
socknames = []
for server in servers:
for sock in server.sockets:
socknames.append(sock.getsockname())
for signame in ('SIGINT', 'SIGTERM'): for signame in ('SIGINT', 'SIGTERM'):
loop.add_signal_handler(getattr(signal, signame), loop.add_signal_handler(getattr(signal, signame),
sighandler, loop, signame, servers) sighandler, loop, signame, servers)
@ -62,6 +67,15 @@ def main(args=None):
loop.run_forever() loop.run_forever()
loop.run_until_complete(asyncio.wait([ loop.run_until_complete(asyncio.wait([
server.wait_closed() for server in servers])) server.wait_closed() for server in servers]))
for sockname in socknames:
try:
os.unlink(sockname)
except FileNotFoundError:
# XXX
# We had our socket unlinked by somebody else, possibly other
# qubesd instance. That also means we probably unlinked their
# socket when creating our server...
pass
finally: finally:
loop.close() loop.close()