comparison finch/gntdebug.c @ 25382:c0b42d6c2785

propagate from branch 'im.pidgin.pidgin' (head f018e11a7ea08e07f22667e6daca2ec7e64f9710) to branch 'im.pidgin.pidgin.next.minor' (head 685e1461486f2e5322bc2952f8e8bbbf4313dee9)
author Richard Laager <rlaager@wiktel.com>
date Fri, 02 Jan 2009 22:35:12 +0000
parents bbcdb1786eda
children f0c2e27c7ae7
comparison
equal deleted inserted replaced
25381:43b721aa4b76 25382:c0b42d6c2785
41 #include <stdio.h> 41 #include <stdio.h>
42 #include <string.h> 42 #include <string.h>
43 43
44 #define PREF_ROOT "/finch/debug" 44 #define PREF_ROOT "/finch/debug"
45 45
46 static gboolean
47 handle_fprintf_stderr_cb(GIOChannel *source, GIOCondition cond, gpointer null)
48 {
49 gssize size;
50 char message[1024];
51
52 size = read(g_io_channel_unix_get_fd(source), message, sizeof(message) - 1);
53 if (size <= 0) {
54 /* Something bad probably happened elsewhere ... let's ignore */
55 } else {
56 message[size] = '\0';
57 g_log("stderr", G_LOG_LEVEL_WARNING, "%s", message);
58 }
59
60 return TRUE;
61 }
62
63 static void
64 handle_fprintf_stderr(gboolean stop)
65 {
66 GIOChannel *stderrch;
67 static int readhandle = -1;
68 int pipes[2];
69
70 if (stop) {
71 if (readhandle >= 0) {
72 g_source_remove(readhandle);
73 readhandle = -1;
74 }
75 return;
76 }
77 pipe(pipes);
78 dup2(pipes[1], STDERR_FILENO);
79
80 stderrch = g_io_channel_unix_new(pipes[0]);
81 g_io_channel_set_close_on_unref(stderrch, TRUE);
82 readhandle = g_io_add_watch_full(stderrch, G_PRIORITY_HIGH,
83 G_IO_IN | G_IO_ERR | G_IO_PRI,
84 handle_fprintf_stderr_cb, NULL, NULL);
85 g_io_channel_unref(stderrch);
86 }
87
46 static struct 88 static struct
47 { 89 {
48 GntWidget *window; 90 GntWidget *window;
49 GntWidget *tview; 91 GntWidget *tview;
50 GntWidget *search; 92 GntWidget *search;
139 static void 181 static void
140 print_stderr(const char *string) 182 print_stderr(const char *string)
141 { 183 {
142 g_printerr("%s", string); 184 g_printerr("%s", string);
143 } 185 }
144
145 static void
146 suppress_error_messages(const char *message)
147 {}
148 186
149 static void 187 static void
150 toggle_pause(GntWidget *w, gpointer n) 188 toggle_pause(GntWidget *w, gpointer n)
151 { 189 {
152 debug.paused = !debug.paused; 190 debug.paused = !debug.paused;
346 REGISTER_G_LOG_HANDLER("GThread"); 384 REGISTER_G_LOG_HANDLER("GThread");
347 REGISTER_G_LOG_HANDLER("Gnt"); 385 REGISTER_G_LOG_HANDLER("Gnt");
348 #ifdef USE_GSTREAMER 386 #ifdef USE_GSTREAMER
349 REGISTER_G_LOG_HANDLER("GStreamer"); 387 REGISTER_G_LOG_HANDLER("GStreamer");
350 #endif 388 #endif
389 REGISTER_G_LOG_HANDLER("stderr");
351 390
352 g_set_print_handler(print_stderr); /* Redirect the debug messages to stderr */ 391 g_set_print_handler(print_stderr); /* Redirect the debug messages to stderr */
353 if (!purple_debug_is_enabled()) 392 if (!purple_debug_is_enabled())
354 g_set_printerr_handler(suppress_error_messages); 393 handle_fprintf_stderr(FALSE);
355 394
356 purple_prefs_add_none(PREF_ROOT); 395 purple_prefs_add_none(PREF_ROOT);
357 purple_prefs_add_string(PREF_ROOT "/filter", ""); 396 purple_prefs_add_string(PREF_ROOT "/filter", "");
358 purple_prefs_add_none(PREF_ROOT "/size"); 397 purple_prefs_add_none(PREF_ROOT "/size");
359 purple_prefs_add_int(PREF_ROOT "/size/width", 60); 398 purple_prefs_add_int(PREF_ROOT "/size/width", 60);
363 g_timeout_add(0, start_with_debugwin, NULL); 402 g_timeout_add(0, start_with_debugwin, NULL);
364 } 403 }
365 404
366 void finch_debug_uninit() 405 void finch_debug_uninit()
367 { 406 {
368 } 407 handle_fprintf_stderr(TRUE);
369 408 }
409