summaryrefslogtreecommitdiff
path: root/virt-manager
diff options
context:
space:
mode:
authorCole Robinson <crobinso@redhat.com>2016-05-17 17:18:57 -0400
committerCole Robinson <crobinso@redhat.com>2016-05-17 17:49:56 -0400
commitfb0fea4cdfbb370ce5c578ee9e27ad2bdbadab63 (patch)
treea4954776c5f79aad9fbdeb7c8449b1f366807259 /virt-manager
parentdfcac3fe9c0c78053beb3aad2e4ff8db8f4c961a (diff)
downloadvirt-manager-fb0fea4cdfbb370ce5c578ee9e27ad2bdbadab63.tar.gz
virt-manager: Move Gtk import handling to a separate function
since it's all sorts of crazy
Diffstat (limited to 'virt-manager')
-rwxr-xr-xvirt-manager77
1 files changed, 42 insertions, 35 deletions
diff --git a/virt-manager b/virt-manager
index 36f86680..da12dba5 100755
--- a/virt-manager
+++ b/virt-manager
@@ -61,6 +61,46 @@ def _show_startup_error(msg, details):
debug=False)
+def _import_gtk(leftovers):
+ # The never ending fork+gsettings problems now require us to
+ # import Gtk _after_ the fork. This creates a funny race, since we
+ # need to parse the command line arguments to know if we need to
+ # fork, but need to import Gtk before cli processing so it can
+ # handle --g-fatal-args. We strip out our flags first and pass the
+ # left overs to gtk
+ origargv = sys.argv
+ try:
+ sys.argv = origargv[:1] + leftovers[:]
+ gi.require_version('Gtk', '3.0')
+ from gi.repository import Gtk
+ leftovers = sys.argv[1:]
+
+ if Gtk.check_version(3, 14, 0):
+ print "gtk3 3.14.0 or later is required."
+ sys.exit(1)
+
+ # This will error if Gtk wasn't correctly initialized
+ Gtk.Window()
+
+ globals()["Gtk"] = Gtk
+ import virtManager.config
+ except Exception, e:
+ # Don't just let the exception raise here. abrt reports bugs
+ # when users mess up su/sudo and DISPLAY isn't set. Printing
+ # it avoids the issue
+ display = os.environ.get("DISPLAY", "")
+ msg = str(e)
+ if display:
+ msg += ": Could not open display: %s" % display
+ logging.debug("".join(traceback.format_exc()))
+ print msg
+ sys.exit(1)
+ finally:
+ sys.argv = origargv
+
+ return leftovers
+
+
def drop_tty():
# We fork and setsid so that we drop the controlling
# tty. This prevents libvirt's SSH tunnels from prompting
@@ -157,41 +197,8 @@ def main():
# Ignore SIGHUP, otherwise a serial console closing drops the whole app
signal.signal(signal.SIGHUP, signal.SIG_IGN)
- # The never ending fork+gsettings problems now require us to
- # import Gtk _after_ the fork. This creates a funny race, since we
- # need to parse the command line arguments to know if we need to
- # fork, but need to import Gtk before cli processing so it can
- # handle --g-fatal-args. We strip out our flags first and pass the
- # left overs to gtk
- origargv = sys.argv
- try:
- sys.argv = origargv[:1] + leftovers[:]
- gi.require_version('Gtk', '3.0')
- from gi.repository import Gtk
- leftovers = sys.argv[1:]
-
- if Gtk.check_version(3, 14, 0):
- print "gtk3 3.14.0 or later is required."
- return
-
- # This will error if Gtk wasn't correctly initialized
- Gtk.Window()
-
- globals()["Gtk"] = Gtk
- import virtManager.config
- except Exception, e:
- # Don't just let the exception raise here. abrt reports bugs
- # when users mess up su/sudo and DISPLAY isn't set. Printing
- # it avoids the issue
- display = os.environ.get("DISPLAY", "")
- msg = str(e)
- if display:
- msg += ": Could not open display: %s" % display
- logging.debug("".join(traceback.format_exc()))
- print msg
- return
- finally:
- sys.argv = origargv
+ leftovers = _import_gtk(leftovers)
+ Gtk = globals()["Gtk"]
# Do this after the Gtk import so the user has a chance of seeing any error
if do_drop_stdio: