tools: add qvm-start-gui --notify-monitor-layout option
This is mostly what 'qubes-monitor-layout-notify' tool did in Qubes 3.2.
This commit is contained in:
parent
bf053769bf
commit
8eed508864
@ -28,6 +28,7 @@ import asyncio
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
import daemon.pidfile
|
||||||
import qubesmgmt
|
import qubesmgmt
|
||||||
import qubesmgmt.events
|
import qubesmgmt.events
|
||||||
import qubesmgmt.tools
|
import qubesmgmt.tools
|
||||||
@ -310,10 +311,21 @@ class GUILauncher(object):
|
|||||||
self.on_connection_established)
|
self.on_connection_established)
|
||||||
|
|
||||||
|
|
||||||
|
if 'XDG_RUNTIME_DIR' in os.environ:
|
||||||
|
pidfile_path = os.path.join(os.environ['XDG_RUNTIME_DIR'],
|
||||||
|
'qvm-start-gui.pid')
|
||||||
|
else:
|
||||||
|
pidfile_path = os.path.join(os.environ.get('HOME', '/'),
|
||||||
|
'.qvm-start-gui.pid')
|
||||||
|
|
||||||
parser = qubesmgmt.tools.QubesArgumentParser(
|
parser = qubesmgmt.tools.QubesArgumentParser(
|
||||||
description='forceful shutdown of a domain', vmname_nargs='*')
|
description='forceful shutdown of a domain', vmname_nargs='*')
|
||||||
parser.add_argument('--watch', action='store_true',
|
parser.add_argument('--watch', action='store_true',
|
||||||
help='Keep watching for further domains startups, must be used with --all')
|
help='Keep watching for further domains startups, must be used with --all')
|
||||||
|
parser.add_argument('--pidfile', action='store', default=pidfile_path,
|
||||||
|
help='Pidfile path to create in --watch mode')
|
||||||
|
parser.add_argument('--notify-monitory-layout', action='store_true',
|
||||||
|
help='Notify running instance in --watch mode about changed monitor layout')
|
||||||
|
|
||||||
|
|
||||||
def main(args=None):
|
def main(args=None):
|
||||||
@ -321,27 +333,39 @@ def main(args=None):
|
|||||||
args = parser.parse_args(args)
|
args = parser.parse_args(args)
|
||||||
if args.watch and not args.all_domains:
|
if args.watch and not args.all_domains:
|
||||||
parser.error('--watch option must be used with --all')
|
parser.error('--watch option must be used with --all')
|
||||||
|
if args.watch and args.notify_monitor_layout:
|
||||||
|
parser.error('--watch cannot be used with --notify-monitor-layout')
|
||||||
launcher = GUILauncher(args.app)
|
launcher = GUILauncher(args.app)
|
||||||
if args.watch:
|
if args.watch:
|
||||||
loop = asyncio.get_event_loop()
|
with daemon.pidfile.TimeoutPIDLockFile(args.pidfile):
|
||||||
events = qubesmgmt.events.EventsDispatcher(args.app)
|
loop = asyncio.get_event_loop()
|
||||||
launcher.register_events(events)
|
events = qubesmgmt.events.EventsDispatcher(args.app)
|
||||||
|
launcher.register_events(events)
|
||||||
|
|
||||||
events_listener = asyncio.ensure_future(events.listen_for_events())
|
events_listener = asyncio.ensure_future(events.listen_for_events())
|
||||||
|
|
||||||
for signame in ('SIGINT', 'SIGTERM'):
|
for signame in ('SIGINT', 'SIGTERM'):
|
||||||
loop.add_signal_handler(getattr(signal, signame),
|
loop.add_signal_handler(getattr(signal, signame),
|
||||||
events_listener.cancel) # pylint: disable=no-member
|
events_listener.cancel) # pylint: disable=no-member
|
||||||
|
|
||||||
loop.add_signal_handler(signal.SIGHUP, launcher.send_monitor_layout_all)
|
loop.add_signal_handler(signal.SIGHUP,
|
||||||
|
launcher.send_monitor_layout_all)
|
||||||
|
|
||||||
|
try:
|
||||||
|
loop.run_until_complete(events_listener)
|
||||||
|
except asyncio.CancelledError:
|
||||||
|
pass
|
||||||
|
loop.stop()
|
||||||
|
loop.run_forever()
|
||||||
|
loop.close()
|
||||||
|
elif args.notify_monitor_layout:
|
||||||
try:
|
try:
|
||||||
loop.run_until_complete(events_listener)
|
with open(pidfile_path, 'r') as pidfile:
|
||||||
except asyncio.CancelledError:
|
pid = int(pidfile.read().strip())
|
||||||
pass
|
os.kill(pid, signal.SIGHUP)
|
||||||
loop.stop()
|
except (FileNotFoundError, ValueError) as e:
|
||||||
loop.run_forever()
|
parser.error('Cannot open pidfile {}: {}'.format(pidfile_path,
|
||||||
loop.close()
|
str(e)))
|
||||||
else:
|
else:
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
tasks = []
|
tasks = []
|
||||||
|
Loading…
Reference in New Issue
Block a user