diff -r 8193c6b465e4 -r c3eccf04560f finch/gntdebug.c --- a/finch/gntdebug.c Sun Dec 28 10:17:15 2008 +0000 +++ b/finch/gntdebug.c Thu Jan 01 18:15:17 2009 +0000 @@ -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 -suppress_error_messages(const char *message) -{} - -static void toggle_pause(GntWidget *w, gpointer n) { debug.paused = !debug.paused; @@ -348,10 +386,11 @@ #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() { + handle_fprintf_stderr(TRUE); }