Fix waiting for application exit in qubesagent.xdg.launch
This is especially important for qubes-desktop-run used inside DispVM. The DesktopAppInfo.launch() method returns after just launching the application. In DispVM case it worked by a coincidence - because the launched application was keeping stdin/out open, which also prevented DispVM killing. Use DesktopAppInfo.launch_uris_as_manager which at least allows to learn PIDs of spawned processes, to track them manually. This still doesn't fix gnome-terminal issue, or any other application using either DBus activation, or any other client-server model. But at least fix basic apps like firefox and xterm. Fixes QubesOS/qubes-issues#3213
This commit is contained in:
parent
15c740d95e
commit
321cd06591
@ -1,9 +1,15 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
from gi.repository import Gio
|
from gi.repository import Gio
|
||||||
|
from gi.repository import GLib
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
def launch(desktop, *files):
|
def pid_callback(launcher, pid, pid_list):
|
||||||
|
pid_list.append(pid)
|
||||||
|
|
||||||
|
def launch(desktop, *files, **kwargs):
|
||||||
|
wait = kwargs.pop('wait', True)
|
||||||
launcher = Gio.DesktopAppInfo.new_from_filename(desktop)
|
launcher = Gio.DesktopAppInfo.new_from_filename(desktop)
|
||||||
try:
|
try:
|
||||||
import dbus
|
import dbus
|
||||||
@ -18,10 +24,17 @@ def launch(desktop, *files):
|
|||||||
bus.start_service_by_name(service_id)
|
bus.start_service_by_name(service_id)
|
||||||
except dbus.DBusException:
|
except dbus.DBusException:
|
||||||
pass
|
pass
|
||||||
return launcher.launch(files, None)
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
launcher.launch(files, None)
|
if wait:
|
||||||
|
pid_list = []
|
||||||
|
flags = GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD
|
||||||
|
launcher.launch_uris_as_manager(files, None, flags, None, None,
|
||||||
|
pid_callback, pid_list)
|
||||||
|
for pid in pid_list:
|
||||||
|
os.waitpid(pid, 0)
|
||||||
|
else:
|
||||||
|
launcher.launch(files, None)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
launch(*sys.argv[1:])
|
launch(*sys.argv[1:])
|
||||||
|
Loading…
Reference in New Issue
Block a user