Blame SOURCES/virt-manager-Yet-more-fixes-for-DISPLAY-unset-error.patch

343f27
From 545284051b48f787db28a26359b545b4b2d1faae Mon Sep 17 00:00:00 2001
343f27
From: Cole Robinson <crobinso@redhat.com>
343f27
Date: Thu, 5 Dec 2013 14:20:07 +0100
343f27
Subject: [RHEL-7.0 virt-manager PATCH] virt-manager: Yet more fixes for
343f27
 DISPLAY unset error
343f27
343f27
Since these days we have to import Gtk _after_ forking, _and_ Gtk
343f27
doesn't raise a nice error for us, we need to postpone dropping stdio
343f27
so the user has any chance of seeing the error. Also try to add an
343f27
explicit error about DISPLAY again, since we don't get it from Gtk
343f27
these days.
343f27
343f27
Closes: https://bugzilla.redhat.com/show_bug.cgi?id=1038496
343f27
(cherry picked from commit 395a20edd82f1072d23e80ecbb25dbeed9359304)
343f27
343f27
Conflicts:
343f27
	virt-manager
343f27
---
343f27
 virt-manager | 23 ++++++++++++++++++-----
343f27
 1 file changed, 18 insertions(+), 5 deletions(-)
343f27
343f27
diff --git a/virt-manager b/virt-manager
343f27
index 656c84b..55cc30a 100755
343f27
--- a/virt-manager
343f27
+++ b/virt-manager
343f27
@@ -209,15 +209,16 @@ def main():
343f27
         virtManager.module_trace.wrap_module(libvirt)
343f27
343f27
     # Now we've got basic environment up & running we can fork
343f27
+    do_drop_stdio = False
343f27
     if not options.nofork and not options.debug:
343f27
         drop_tty()
343f27
-        drop_stdio()
343f27
+        do_drop_stdio = True
343f27
343f27
         # Ignore SIGHUP, otherwise a serial console closing drops the whole app
343f27
         signal.signal(signal.SIGHUP, signal.SIG_IGN)
343f27
343f27
     # The never ending fork+gconf/gsettings problems now require
343f27
-    # us to import Gtk before the fork. This creates a funny race,
343f27
+    # us to import Gtk _after_ the fork. This creates a funny race,
343f27
     # since we need to parse the command line arguments to know if
343f27
     # we need to fork, but need to import Gtk before cli processing
343f27
     # so it can handle --g-fatal-args. We strip out our flags first
343f27
@@ -226,20 +227,32 @@ def main():
343f27
     try:
343f27
         sys.argv = origargv[:1] + leftovers[:]
343f27
         from gi.repository import Gtk  # pylint: disable=E0611
343f27
-        globals()["Gtk"] = Gtk
343f27
         leftovers = sys.argv[1:]
343f27
343f27
+        # This will error if Gtk wasn't correctly initialized
343f27
+        Gtk.Window()
343f27
+
343f27
+        globals()["Gtk"] = Gtk
343f27
         import virtManager.config
343f27
         import virtManager.util
343f27
-    except:
343f27
+    except Exception, e:
343f27
         # Don't just let the exception raise here. abrt reports bugs
343f27
         # when users mess up su/sudo and DISPLAY isn't set. Printing
343f27
         # it avoids the issue
343f27
-        print "".join(traceback.format_exc())
343f27
+        display = os.environ.get("DISPLAY", "")
343f27
+        msg = str(e)
343f27
+        if not display:
343f27
+            msg += ": Could not open display: %s" % display
343f27
+        logging.debug("".join(traceback.format_exc()))
343f27
+        print msg
343f27
         return 1
343f27
     finally:
343f27
         sys.argv = origargv
343f27
343f27
+    # Do this after the Gtk import so the user has a chance of seeing any error
343f27
+    if do_drop_stdio:
343f27
+        drop_stdio()
343f27
+
343f27
     if leftovers:
343f27
         raise RuntimeError("Unhandled command line options '%s'" % leftovers)
343f27
343f27
-- 
343f27
1.8.5.1
343f27