[Xfce4-commits] [xfce/xfwm4] 05/05: Send debug messages to a log file

noreply at xfce.org noreply at xfce.org
Thu Jan 29 22:19:53 CET 2015


This is an automated email from the git hooks/post-receive script.

olivier pushed a commit to branch master
in repository xfce/xfwm4.

commit 19df756912baf0f28490bb21823fdff345ae1511
Author: Olivier Fourdan <fourdan at xfce.org>
Date:   Thu Jan 29 21:58:37 2015 +0100

    Send debug messages to a log file
    
    Bug: 10564
    
    Logging to an X terminal while the X servder is grabbed (which happens
    quite often in a window manager) may lead to a dead lock.
    
    Only way to reliably avoid this is to send log and debug messages to a
    file instead.
    
    Log file can be specified using the environment variable XFWM4_LOG_FILE.
    
    Signed-off-by: Olivier Fourdan <fourdan at xfce.org>
---
 src/compositor.c |   27 ++++++++++------------
 src/display.c    |    5 +++--
 src/main.c       |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 81 insertions(+), 17 deletions(-)

diff --git a/src/compositor.c b/src/compositor.c
index bf5165b..fcd3fe3 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -2499,8 +2499,8 @@ zoom_timeout_cb (gpointer data)
     }
 
     XQueryPointer (screen_info->display_info->dpy, screen_info->xroot,
-			    &root_return, &child_return,
-			    &x_root, &y_root, &x_win, &y_win, &mask);
+                            &root_return, &child_return,
+                            &x_root, &y_root, &x_win, &y_win, &mask);
     if (x_old != x_root || y_old != y_root)
     {
         x_old = x_root; y_old = y_root;
@@ -3216,11 +3216,10 @@ compositorInitDisplay (DisplayInfo *display_info)
     {
         display_info->have_composite = TRUE;
         XCompositeQueryVersion (display_info->dpy, &composite_major, &composite_minor);
-#if DEBUG
-        g_print ("composite event base: %i\n", display_info->composite_event_base);
-        g_print ("composite error base: %i\n", display_info->composite_error_base);
-        g_print ("composite version: %i.%i\n", composite_major, composite_minor);
-#endif
+
+        DBG ("composite event base: %i", display_info->composite_event_base);
+        DBG ("composite error base: %i", display_info->composite_error_base);
+        DBG ("composite version: %i.%i", composite_major, composite_minor);
     }
 
     if (!XDamageQueryExtension (display_info->dpy,
@@ -3235,10 +3234,9 @@ compositorInitDisplay (DisplayInfo *display_info)
     else
     {
         display_info->have_damage = TRUE;
-#if DEBUG
-        g_print ("damage event base: %i\n", display_info->damage_event_base);
-        g_print ("damage error base: %i\n", display_info->damage_error_base);
-#endif
+
+        DBG ("damage event base: %i", display_info->damage_event_base);
+        DBG ("damage error base: %i", display_info->damage_error_base);
     }
 
     if (!XFixesQueryExtension (display_info->dpy,
@@ -3253,10 +3251,9 @@ compositorInitDisplay (DisplayInfo *display_info)
     else
     {
         display_info->have_fixes = TRUE;
-#if DEBUG
-        g_print ("fixes event base: %i\n", display_info->fixes_event_base);
-        g_print ("fixes error base: %i\n", display_info->fixes_error_base);
-#endif /* DEBUG */
+
+        DBG ("fixes event base: %i", display_info->fixes_event_base);
+        DBG ("fixes error base: %i", display_info->fixes_error_base);
     }
 
     display_info->enable_compositor = ((display_info->have_render)
diff --git a/src/display.c b/src/display.c
index f156412..6a1c036 100644
--- a/src/display.c
+++ b/src/display.c
@@ -24,6 +24,7 @@
 #include "config.h"
 #endif
 
+#include <stdio.h>
 #include <X11/X.h>
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
@@ -63,8 +64,8 @@ handleXError (Display * dpy, XErrorEvent * err)
     char buf[64];
 
     XGetErrorText (dpy, err->error_code, buf, 63);
-    g_print ("XError: %s\n", buf);
-    g_print ("==>  XID 0x%lx, Request %d, Error %d <==\n",
+    fprintf (stderr, "XError: %s\n", buf);
+    fprintf (stderr, "==>  XID 0x%lx, Request %d, Error %d <==\n",
               err->resourceid, err->request_code, err->error_code);
 #endif
     return 0;
diff --git a/src/main.c b/src/main.c
index 68e62ec..c041ade 100644
--- a/src/main.c
+++ b/src/main.c
@@ -40,6 +40,7 @@
 #include <sys/wait.h>
 #include <time.h>
 #include <unistd.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -95,6 +96,47 @@ static char revision[]="@(#)$ " PACKAGE " version " VERSION " revision " REVISIO
 static DisplayInfo *main_display_info = NULL;
 static gint compositor = COMPOSITOR_MODE_MANUAL;
 
+#ifdef DEBUG
+static gboolean
+setupLog (void)
+{
+    const gchar *str;
+    gchar *logfile;
+    int fd;
+
+    str = g_getenv ("XFWM4_LOG_FILE");
+    if (str)
+    {
+        logfile = g_strdup (str);
+    }
+    else
+    {
+        logfile = g_strdup_printf ("xfwm4-debug-%d.log", (int) getpid ());
+    }
+
+    fd = dup(fileno(stderr));
+    if (fd == -1)
+    {
+        g_warning ("Fail to open %s: %s", logfile, g_strerror (errno));
+        g_free (logfile);
+        return FALSE;
+    }
+
+    if (!freopen (logfile, "w", stderr))
+    {
+        g_warning ("Fail to redirect stderr: %s", g_strerror (errno));
+        g_free (logfile);
+        close (fd);
+        return FALSE;
+    }
+
+    g_print ("Logging to %s\n", logfile);
+    g_free (logfile);
+
+    return TRUE;
+}
+#endif /* DEBUG */
+
 static void
 handleSignal (int sig)
 {
@@ -522,6 +564,25 @@ initialize (gint compositor_mode, gboolean replace_wm)
     return sessionStart (main_display_info);
 }
 
+static void
+init_pango_cache (void)
+{
+    GtkWidget *tmp_win;
+    PangoLayout *layout;
+
+    /*
+     * The first time the first Gtk application on a display uses pango,
+     * pango grabs the XServer while it creates the font cache window.
+     * Therefore, force the cache window to be created now instead of
+     * trying to do it while we have another grab and deadlocking the server.
+     */
+    tmp_win = gtk_window_new (GTK_WINDOW_POPUP);
+    layout = gtk_widget_create_pango_layout (tmp_win, "-");
+    pango_layout_get_pixel_extents (layout, NULL, NULL);
+    g_object_unref (G_OBJECT (layout));
+    gtk_widget_destroy (GTK_WIDGET (tmp_win));
+}
+
 int
 main (int argc, char **argv)
 {
@@ -531,6 +592,7 @@ main (int argc, char **argv)
     int status;
     GOptionContext *context;
     GError *error = NULL;
+
 #ifndef HAVE_COMPOSITOR
     gchar *compositor_foo = NULL;
 #endif
@@ -551,6 +613,9 @@ main (int argc, char **argv)
         { NULL }
     };
 
+#ifdef DEBUG
+    setupLog ();
+#endif /* DEBUG */
     DBG ("xfwm4 starting");
 
     xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
@@ -577,6 +642,7 @@ main (int argc, char **argv)
          print_version ();
          return EXIT_SUCCESS;
     }
+    init_pango_cache ();
 
     status = initialize (compositor, replace_wm);
     /*

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list