pidgin: 4d6cb564: Redirect stderr to the debug window.

sadrul at pidgin.im sadrul at pidgin.im
Wed Dec 31 18:55:57 EST 2008


-----------------------------------------------------------------
Revision: 4d6cb5643e4c49b8e02ddd9f3ba663148fc05113
Ancestor: 97920674b6fdd5f82741d1e33f3379faad6743dc
Author: sadrul at pidgin.im
Date: 2008-12-31T23:49:36
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/4d6cb5643e4c49b8e02ddd9f3ba663148fc05113

Modified files:
        ChangeLog finch/gntdebug.c

ChangeLog: 

Redirect stderr to the debug window.

This should be useful when some libraries (e.g. libnm etc.) print stuff
to the stderr.

-------------- next part --------------
============================================================
--- ChangeLog	327667b3f81cfbf5353c31c3d2aed31962f30322
+++ ChangeLog	b3826c06dad19ec25ea3f47a703c78fbb16ad30d
@@ -16,6 +16,9 @@ version 2.5.4 (??/??/????):
 	* Fix a crash in the Add Account dialog when changing protocols under
 	  certain circumstances.
 
+	Finch:
+	* Redirect stderr outputs to the debug window.
+
 version 2.5.3 (12/20/2008):
 	libpurple:
 	* The Buddy State Notification plugin no longer prints duplicate
============================================================
--- finch/gntdebug.c	c8d27ecf2e5e2492248f9f4197b09588131956cf
+++ finch/gntdebug.c	3c50d168613dd61ac43ff2e08bff23ad6f440042
@@ -43,6 +43,48 @@
 
 #define PREF_ROOT "/finch/debug"
 
+static gboolean
+handle_fprintf_stderr_cb(GIOChannel *source, GIOCondition cond, gpointer null)
+{
+	gssize size;
+	char message[1024];
+
+	size = read(g_io_channel_unix_get_fd(source), message, sizeof(message) - 1);
+	if (size <= 0) {
+		/* Something bad probably happened elsewhere ... let's ignore */
+	} else {
+		message[size] = '\0';
+		g_log("stderr", G_LOG_LEVEL_WARNING, "%s", message);
+	}
+
+	return TRUE;
+}
+
+static void
+handle_fprintf_stderr(gboolean stop)
+{
+	GIOChannel *stderrch;
+	static int readhandle = -1;
+	int pipes[2];
+
+	if (stop) {
+		if (readhandle >= 0) {
+			g_source_remove(readhandle);
+			readhandle = -1;
+		}
+		return;
+	}
+	pipe(pipes);
+	dup2(pipes[1], STDERR_FILENO);
+
+	stderrch = g_io_channel_unix_new(pipes[0]);
+	g_io_channel_set_close_on_unref(stderrch, TRUE);
+	readhandle = g_io_add_watch_full(stderrch, G_PRIORITY_HIGH,
+			G_IO_IN | G_IO_ERR | G_IO_PRI,
+			handle_fprintf_stderr_cb, NULL, NULL);
+	g_io_channel_unref(stderrch);
+}
+
 static struct
 {
 	GntWidget *window;
@@ -143,10 +185,6 @@ static void
 }
 
 static void
-suppress_error_messages(const char *message)
-{}
-
-static void
 toggle_pause(GntWidget *w, gpointer n)
 {
 	debug.paused = !debug.paused;
@@ -348,10 +386,11 @@ void finch_debug_init()
 #ifdef USE_GSTREAMER
 	REGISTER_G_LOG_HANDLER("GStreamer");
 #endif
+	REGISTER_G_LOG_HANDLER("stderr");
 
 	g_set_print_handler(print_stderr);   /* Redirect the debug messages to stderr */
 	if (!purple_debug_is_enabled())
-		g_set_printerr_handler(suppress_error_messages);
+		handle_fprintf_stderr(FALSE);
 
 	purple_prefs_add_none(PREF_ROOT);
 	purple_prefs_add_string(PREF_ROOT "/filter", "");
@@ -365,5 +404,6 @@ void finch_debug_uninit()
 
 void finch_debug_uninit()
 {
+	handle_fprintf_stderr(TRUE);
 }
 


More information about the Commits mailing list