summaryrefslogtreecommitdiff
path: root/src/nautilus-main.c
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@novell.com>2006-11-23 16:26:05 +0000
committerFederico Mena Quintero <federico@src.gnome.org>2006-11-23 16:26:05 +0000
commit3b4411675420822f4edf580e2f01423c8720123b (patch)
tree327f9f335fd0f4038ba8bf6a6d2144e92ba9bad1 /src/nautilus-main.c
parent8ffdd1423d71f3691788190d201c98580500008d (diff)
downloadnautilus-3b4411675420822f4edf580e2f01423c8720123b.tar.gz
Use the write-to-a-pipe trick from the signal handler instead of queueing
2006-11-23 Federico Mena Quintero <federico@novell.com> Use the write-to-a-pipe trick from the signal handler instead of queueing an idle handler from there. * src/nautilus-main.c (setup_debug_log_signals): Set up a pair of pipes for the SIGUSR1 handler; set up a GIOChannel on them. (sigusr1_handler): Write a byte to our pipe instead of queueing an idle handler. (debug_log_io_cb): Replaces dump_debug_log_idle_cb(). Read from the pipe, and dump the debug log. Add a configuration file for the logging mechanism. You create ~/nautilus-debug-log.conf as a GKeyFile. * libnautilus-private/nautilus-debug-log.c (nautilus_debug_log_load_configuration): New function; loads the configuration from a key file like this: [debug log] enable domains = foo; bar; baz max lines = 1000 * libnautilus-private/nautilus-debug-log.c (dump_configuration): New utility function. (nautilus_debug_log_dump): At the end of the log, dump the configuration used for the debug log so that the user can re-create it later. * libnautilus-private/nautilus-debug-log.h: New prototype for nautilus_debug_log_load_configuration(). * src/nautilus-main.c (setup_debug_log): Load the debug log's configuration from ~/nautilus-debug-log.conf (setup_debug_log_domains): Removed. * src/nautilus-main.c (log_override_cb): If the log level of the message is G_LOG_LEVEL_DEBUG, don't log it as a milestone. We'll use this log level for miscellaneous debugging messages from gnome-vfs. Also, don't send G_LOG_LEVEL_DEBUG messages to the default log handler, to avoid a huge ~/.xsession-errors. (setup_debug_log_domains): Enable logging for NAUTILUS_DEBUG_LOG_DOMAIN_GLOG.
Diffstat (limited to 'src/nautilus-main.c')
-rw-r--r--src/nautilus-main.c47
1 files changed, 32 insertions, 15 deletions
diff --git a/src/nautilus-main.c b/src/nautilus-main.c
index 25d51f99d..61c43d9df 100644
--- a/src/nautilus-main.c
+++ b/src/nautilus-main.c
@@ -210,9 +210,16 @@ dump_debug_log (void)
g_free (filename);
}
+static int debug_log_pipes[2];
+
static gboolean
-dump_debug_log_idle_cb (gpointer data)
+debug_log_io_cb (GIOChannel *io, GIOCondition condition, gpointer data)
{
+ char a;
+
+ while (read (debug_log_pipes[0], &a, 1) != 1)
+ ;
+
nautilus_debug_log (TRUE, NAUTILUS_DEBUG_LOG_DOMAIN_USER,
"user requested dump of debug log");
@@ -230,7 +237,8 @@ static struct sigaction old_bus_sa;
static void
sigusr1_handler (int sig)
{
- g_idle_add (dump_debug_log_idle_cb, NULL);
+ while (write (debug_log_pipes[1], "a", 1) != 1)
+ ;
}
static void
@@ -280,6 +288,13 @@ static void
setup_debug_log_signals (void)
{
struct sigaction sa;
+ GIOChannel *io;
+
+ if (pipe (debug_log_pipes) == -1)
+ g_error ("Could not create pipe() for debug log");
+
+ io = g_io_channel_unix_new (debug_log_pipes[0]);
+ g_io_add_watch (io, G_IO_IN, debug_log_io_cb, NULL);
sa.sa_handler = sigusr1_handler;
sigemptyset (&sa.sa_mask);
@@ -297,16 +312,6 @@ setup_debug_log_signals (void)
sigaction(SIGBUS, &sa, &old_bus_sa);
}
-static void
-setup_debug_log_domains (void)
-{
- const char *domains[] = {
- NAUTILUS_DEBUG_LOG_DOMAIN_ASYNC
- };
-
- nautilus_debug_log_enable_domains (domains, G_N_ELEMENTS (domains));
-}
-
static GLogFunc default_log_handler;
static void
@@ -315,9 +320,16 @@ log_override_cb (const gchar *log_domain,
const gchar *message,
gpointer user_data)
{
- nautilus_debug_log (TRUE, NAUTILUS_DEBUG_LOG_DOMAIN_GLOG, "%s", message);
+ gboolean is_debug;
+ gboolean is_milestone;
+
+ is_debug = ((log_level & G_LOG_LEVEL_DEBUG) != 0);
+ is_milestone = !is_debug;
- (* default_log_handler) (log_domain, log_level, message, user_data);
+ nautilus_debug_log (is_milestone, NAUTILUS_DEBUG_LOG_DOMAIN_GLOG, "%s", message);
+
+ if (!is_debug)
+ (* default_log_handler) (log_domain, log_level, message, user_data);
}
static void
@@ -329,7 +341,12 @@ setup_debug_log_glog (void)
static void
setup_debug_log (void)
{
- setup_debug_log_domains ();
+ char *config_filename;
+
+ config_filename = g_build_filename (g_get_home_dir (), "nautilus-debug-log.conf", NULL);
+ nautilus_debug_log_load_configuration (config_filename, NULL); /* NULL GError */
+ g_free (config_filename);
+
setup_debug_log_signals ();
setup_debug_log_glog ();
}