2017-02-02 13:03:08 +01:00
|
|
|
#!/usr/bin/env python3.6
|
|
|
|
|
|
|
|
import asyncio
|
|
|
|
import os
|
|
|
|
import signal
|
|
|
|
|
2017-03-20 18:29:27 +01:00
|
|
|
import libvirtaio
|
|
|
|
|
2017-02-02 13:03:08 +01:00
|
|
|
import qubes
|
2017-05-12 19:07:41 +02:00
|
|
|
import qubes.api
|
|
|
|
import qubes.api.admin
|
|
|
|
import qubes.api.internal
|
2017-06-03 04:52:30 +02:00
|
|
|
import qubes.api.misc
|
2017-02-02 13:03:08 +01:00
|
|
|
import qubes.utils
|
|
|
|
import qubes.vm.qubesvm
|
|
|
|
|
2017-06-05 15:55:40 +02:00
|
|
|
def sighandler(loop, signame, servers):
|
2017-02-02 13:03:08 +01:00
|
|
|
print('caught {}, exiting'.format(signame))
|
2017-06-03 04:52:30 +02:00
|
|
|
for server in servers:
|
|
|
|
server.close()
|
2017-02-02 13:03:08 +01:00
|
|
|
loop.stop()
|
|
|
|
|
|
|
|
parser = qubes.tools.QubesArgumentParser(description='Qubes OS daemon')
|
2017-05-23 04:47:50 +02:00
|
|
|
parser.add_argument('--debug', action='store_true', default=False,
|
|
|
|
help='Enable verbose error logging (all exceptions with full '
|
|
|
|
'tracebacks) and also send tracebacks to Admin API clients')
|
2017-02-02 13:03:08 +01:00
|
|
|
|
|
|
|
def main(args=None):
|
|
|
|
loop = asyncio.get_event_loop()
|
2017-03-20 18:29:27 +01:00
|
|
|
libvirtaio.virEventRegisterAsyncIOImpl(loop=loop)
|
2017-04-27 00:40:55 +02:00
|
|
|
try:
|
|
|
|
args = parser.parse_args(args)
|
|
|
|
except:
|
|
|
|
loop.close()
|
|
|
|
raise
|
|
|
|
|
|
|
|
args.app.vmm.register_event_handlers(args.app)
|
2017-02-02 13:03:08 +01:00
|
|
|
|
2017-06-06 15:49:19 +02:00
|
|
|
servers = loop.run_until_complete(qubes.api.create_servers(
|
2017-06-05 15:55:40 +02:00
|
|
|
qubes.api.admin.QubesAdminAPI,
|
|
|
|
qubes.api.internal.QubesInternalAPI,
|
|
|
|
qubes.api.misc.QubesMiscAPI,
|
2017-06-06 15:49:19 +02:00
|
|
|
app=args.app, debug=args.debug))
|
2017-02-02 13:03:08 +01:00
|
|
|
|
2017-06-05 16:41:14 +02:00
|
|
|
socknames = []
|
|
|
|
for server in servers:
|
|
|
|
for sock in server.sockets:
|
|
|
|
socknames.append(sock.getsockname())
|
|
|
|
|
2017-02-02 13:03:08 +01:00
|
|
|
for signame in ('SIGINT', 'SIGTERM'):
|
|
|
|
loop.add_signal_handler(getattr(signal, signame),
|
2017-06-05 15:55:40 +02:00
|
|
|
sighandler, loop, signame, servers)
|
2017-02-02 13:03:08 +01:00
|
|
|
|
|
|
|
qubes.utils.systemd_notify()
|
2017-05-17 02:11:03 +02:00
|
|
|
# make sure children will not inherit this
|
|
|
|
os.environ.pop('NOTIFY_SOCKET', None)
|
2017-02-02 13:03:08 +01:00
|
|
|
|
|
|
|
try:
|
|
|
|
loop.run_forever()
|
2017-03-21 11:48:20 +01:00
|
|
|
loop.run_until_complete(asyncio.wait([
|
2017-06-05 15:55:40 +02:00
|
|
|
server.wait_closed() for server in servers]))
|
2017-06-05 16:41:14 +02:00
|
|
|
for sockname in socknames:
|
|
|
|
try:
|
|
|
|
os.unlink(sockname)
|
|
|
|
except FileNotFoundError:
|
2017-06-06 15:49:19 +02:00
|
|
|
args.app.log.warning(
|
|
|
|
'socket {} got unlinked sometime before shutdown'.format(
|
|
|
|
sockname))
|
2017-02-02 13:03:08 +01:00
|
|
|
finally:
|
|
|
|
loop.close()
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|