From 80dc652115e275a95b05bb6809825cc324d9475a Mon Sep 17 00:00:00 2001 From: William Jon McCann Date: Tue, 3 Apr 2007 11:42:43 -0400 Subject: add a glib message to syslog handler Also add ability to toggle debugging when SIGUSR1 is received. --- src/main.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 7 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index fda1249..fe2e9ec 100644 --- a/src/main.c +++ b/src/main.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -38,7 +39,7 @@ #include #include "ck-manager.h" -#include "ck-debug.h" +#include "ck-log.h" #define CK_DBUS_NAME "org.freedesktop.ConsoleKit" @@ -172,7 +173,7 @@ bus_reconnect (CkManager *manager) G_CALLBACK (bus_proxy_destroyed_cb), manager); - ck_debug ("Successfully reconnected to D-Bus"); + g_debug ("Successfully reconnected to D-Bus"); ret = FALSE; @@ -184,7 +185,7 @@ static void bus_proxy_destroyed_cb (DBusGProxy *bus_proxy, CkManager *manager) { - ck_debug ("Disconnected from D-Bus"); + g_debug ("Disconnected from D-Bus"); g_object_unref (manager); manager = NULL; @@ -198,6 +199,58 @@ delete_pid (void) unlink (CONSOLE_KIT_PID_FILE); } +/* copied from nautilus */ +static int debug_log_pipes[2]; + +static gboolean +debug_log_io_cb (GIOChannel *io, + GIOCondition condition, + gpointer data) +{ + char a; + + while (read (debug_log_pipes[0], &a, 1) != 1) + ; + + ck_log_toggle_debug (); + + return TRUE; +} + +static void +sigusr1_handler (int sig) +{ + while (write (debug_log_pipes[1], "a", 1) != 1) + ; +} + +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); + sa.sa_flags = 0; + sigaction (SIGUSR1, &sa, NULL); +} + +static void +setup_debug_log (gboolean debug) +{ + ck_log_init (); + ck_log_set_debug (debug); + setup_debug_log_signals (); +} + int main (int argc, char **argv) @@ -235,6 +288,8 @@ main (int argc, g_option_context_parse (context, &argc, &argv, NULL); g_option_context_free (context); + setup_debug_log (debug); + connection = get_system_bus (); if (connection == NULL) { goto out; @@ -251,9 +306,7 @@ main (int argc, goto out; } - /* debug to a file if in deamon mode */ - ck_debug_init (debug, ! no_daemon); - ck_debug ("initializing console-kit-daemon %s", VERSION); + g_debug ("initializing console-kit-daemon %s", VERSION); if (! no_daemon && daemon (0, 0)) { g_error ("Could not daemonize: %s", g_strerror (errno)); @@ -299,4 +352,3 @@ main (int argc, return ret; } - -- cgit