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/Makefile.am | 4 +- src/ck-debug.c | 153 ---------------------------------------- src/ck-debug.h | 72 ------------------- src/ck-job.c | 21 +++--- src/ck-log.c | 197 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ck-log.h | 41 +++++++++++ src/ck-manager.c | 41 ++++++----- src/ck-seat.c | 21 +++--- src/ck-session.c | 31 ++++----- src/ck-vt-monitor.c | 30 ++++---- src/main.c | 66 ++++++++++++++++-- 11 files changed, 366 insertions(+), 311 deletions(-) delete mode 100644 src/ck-debug.c delete mode 100644 src/ck-debug.h create mode 100644 src/ck-log.c create mode 100644 src/ck-log.h diff --git a/src/Makefile.am b/src/Makefile.am index 6d128ce..26eb8e7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -65,8 +65,8 @@ console_kit_daemon_SOURCES = \ ck-seat.c \ ck-session.h \ ck-session.c \ - ck-debug.h \ - ck-debug.c \ + ck-log.h \ + ck-log.c \ getfd.c \ proc.h \ $(PLATFORM_SOURCES) \ diff --git a/src/ck-debug.c b/src/ck-debug.c deleted file mode 100644 index adf17d5..0000000 --- a/src/ck-debug.c +++ /dev/null @@ -1,153 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2005-2006 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * Authors: William Jon McCann - * - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "ck-debug.h" - -static gboolean debugging = FALSE; -static FILE *debug_out = NULL; - -/* Based on rhythmbox/lib/rb-debug.c */ -/* Our own funky debugging function, should only be used when something - * is not going wrong, if something *is* wrong use g_warning. - */ -void -ck_debug_real (const char *func, - const char *file, - const int line, - const char *format, ...) -{ - va_list args; - char buffer [256]; - char *str_time; - time_t the_time; - FILE *stream; - - if (debugging == FALSE) - return; - - va_start (args, format); - - g_vsnprintf (buffer, 255, format, args); - - va_end (args); - - time (&the_time); - str_time = g_new0 (char, 255); - strftime (str_time, 254, "%H:%M:%S", localtime (&the_time)); - - stream = debug_out ? debug_out : stderr; - setbuf (stream, NULL); - fprintf (stream, - "[%s] %s:%d (%s):\t %s\n", - func, file, line, str_time, buffer); - - g_free (str_time); -} - -gboolean -ck_debug_enabled (void) -{ - return debugging; -} - -void -ck_debug_init (gboolean debug, - gboolean to_file) -{ - /* return if already initialized */ - if (debugging == TRUE) { - return; - } - - debugging = debug; - - if (debug && to_file) { - const char path [50] = "ck_debug_XXXXXX"; - int fd; - - fd = g_file_open_tmp (path, NULL, NULL); - - if (fd >= 0) { - debug_out = fdopen (fd, "a"); - } - } - - ck_debug ("Debugging %s", (debug) ? "enabled" : "disabled"); -} - -void -ck_debug_shutdown (void) -{ - if (! debugging) - return; - - ck_debug ("Shutting down debugging"); - - debugging = FALSE; - - if (debug_out != NULL) { - fclose (debug_out); - debug_out = NULL; - } -} - -void -_ck_profile_log (const char *func, - const char *note, - const char *format, - ...) -{ - va_list args; - char *str; - char *formatted; - - if (format == NULL) { - formatted = g_strdup (""); - } else { - va_start (args, format); - formatted = g_strdup_vprintf (format, args); - va_end (args); - } - - if (func != NULL) { - str = g_strdup_printf ("MARK: %s %s: %s %s", g_get_prgname(), func, note ? note : "", formatted); - } else { - str = g_strdup_printf ("MARK: %s: %s %s", g_get_prgname(), note ? note : "", formatted); - } - - g_free (formatted); - - g_access (str, F_OK); - g_free (str); -} diff --git a/src/ck-debug.h b/src/ck-debug.h deleted file mode 100644 index 88ff9e1..0000000 --- a/src/ck-debug.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2005-2006 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * Authors: William Jon McCann - * - */ - -#ifndef __CK_DEBUG_H -#define __CK_DEBUG_H - -#include -#include - -G_BEGIN_DECLS - -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L -#define ck_debug(...) ck_debug_real (__func__, __FILE__, __LINE__, __VA_ARGS__) -#elif defined(__GNUC__) && __GNUC__ >= 3 -#define ck_debug(...) ck_debug_real (__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__) -#else -#define ck_debug(...) -#endif - -void ck_debug_init (gboolean debug, - gboolean to_file); -gboolean ck_debug_enabled (void); -void ck_debug_shutdown (void); -void ck_debug_real (const char *func, - const char *file, - int line, - const char *format, ...); - -#define ENABLE_PROFILING 1 -#ifdef ENABLE_PROFILING -#ifdef G_HAVE_ISO_VARARGS -#define ck_profile_start(...) _ck_profile_log (G_STRFUNC, "start", __VA_ARGS__) -#define ck_profile_end(...) _ck_profile_log (G_STRFUNC, "end", __VA_ARGS__) -#define ck_profile_msg(...) _ck_profile_log (NULL, NULL, __VA_ARGS__) -#elif defined(G_HAVE_GNUC_VARARGS) -#define ck_profile_start(format...) _ck_profile_log (G_STRFUNC, "start", format) -#define ck_profile_end(format...) _ck_profile_log (G_STRFUNC, "end", format) -#define ck_profile_msg(format...) _ck_profile_log (NULL, NULL, format) -#endif -#else -#define ck_profile_start(...) -#define ck_profile_end(...) -#define ck_profile_msg(...) -#endif - -void _ck_profile_log (const char *func, - const char *note, - const char *format, - ...) G_GNUC_PRINTF (3, 4); - -G_END_DECLS - -#endif /* __CK_DEBUG_H */ diff --git a/src/ck-job.c b/src/ck-job.c index 44e9a57..1093629 100644 --- a/src/ck-job.c +++ b/src/ck-job.c @@ -34,7 +34,6 @@ #include #include "ck-job.h" -#include "ck-debug.h" #include "ck-marshal.h" #define CK_JOB_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CK_TYPE_JOB, CkJobPrivate)) @@ -87,7 +86,7 @@ wait_on_child (int pid) } else if (errno == ECHILD) { ; /* do nothing, child already reaped */ } else { - ck_debug ("waitpid () should not fail"); + g_debug ("waitpid () should not fail"); } } @@ -116,7 +115,7 @@ maybe_complete_job (CkJob *job) status = wait_on_job (job); - ck_debug ("Emitting completed"); + g_debug ("Emitting completed"); g_signal_emit (job, signals [COMPLETED], 0, status); } } @@ -138,7 +137,7 @@ error_watch (GIOChannel *source, switch (status) { case G_IO_STATUS_NORMAL: - ck_debug ("command error output: %s", line); + g_debug ("command error output: %s", line); g_string_append (job->priv->stderr, line); break; case G_IO_STATUS_EOF: @@ -146,7 +145,7 @@ error_watch (GIOChannel *source, break; case G_IO_STATUS_ERROR: finished = TRUE; - ck_debug ("Error reading from child: %s\n", error->message); + g_debug ("Error reading from child: %s\n", error->message); break; case G_IO_STATUS_AGAIN: default: @@ -183,7 +182,7 @@ out_watch (GIOChannel *source, switch (status) { case G_IO_STATUS_NORMAL: - ck_debug ("command output: %s", line); + g_debug ("command output: %s", line); g_string_append (job->priv->stdout, line); break; case G_IO_STATUS_EOF: @@ -191,7 +190,7 @@ out_watch (GIOChannel *source, break; case G_IO_STATUS_ERROR: finished = TRUE; - ck_debug ("Error reading from child: %s\n", error->message); + g_debug ("Error reading from child: %s\n", error->message); break; case G_IO_STATUS_AGAIN: default: @@ -223,10 +222,10 @@ ck_job_execute (CkJob *job, int argc; char **argv; - ck_debug ("Executing %s", job->priv->command); + g_debug ("Executing %s", job->priv->command); local_error = NULL; if (! g_shell_parse_argv (job->priv->command, &argc, &argv, &local_error)) { - ck_debug ("Could not parse command: %s", local_error->message); + g_debug ("Could not parse command: %s", local_error->message); g_propagate_error (error, local_error); return FALSE; } @@ -246,7 +245,7 @@ ck_job_execute (CkJob *job, g_strfreev (argv); if (! res) { - ck_debug ("Could not start command '%s': %s", + g_debug ("Could not start command '%s': %s", job->priv->command, local_error->message); g_propagate_error (error, local_error); @@ -357,7 +356,7 @@ ck_job_finalize (GObject *object) { CkJob *job; - ck_debug ("Finalizing job"); + g_debug ("Finalizing job"); g_return_if_fail (object != NULL); g_return_if_fail (CK_IS_JOB (object)); diff --git a/src/ck-log.c b/src/ck-log.c new file mode 100644 index 0000000..9f49352 --- /dev/null +++ b/src/ck-log.c @@ -0,0 +1,197 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Authors: William Jon McCann + * + */ + +#include "config.h" + +#include +#include +#include +#include + +#include + +#include +#include + +#include "ck-log.h" + +static gboolean initialized = FALSE; +static int syslog_levels = (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); + +static void +log_level_to_priority_and_prefix (GLogLevelFlags log_level, + int *priorityp, + const char **prefixp) +{ + int priority; + const char *prefix; + + /* Process the message prefix and priority */ + switch (log_level & G_LOG_LEVEL_MASK) { + case G_LOG_FLAG_FATAL: + priority = LOG_EMERG; + prefix = "FATAL"; + break; + case G_LOG_LEVEL_ERROR: + priority = LOG_ERR; + prefix = "ERROR"; + break; + case G_LOG_LEVEL_CRITICAL: + priority = LOG_CRIT; + prefix = "CRITICAL"; + break; + case G_LOG_LEVEL_WARNING: + priority = LOG_WARNING; + prefix = "WARNING"; + break; + case G_LOG_LEVEL_MESSAGE: + priority = LOG_NOTICE; + prefix = "MESSAGE"; + break; + case G_LOG_LEVEL_INFO: + priority = LOG_INFO; + prefix = "INFO"; + break; + case G_LOG_LEVEL_DEBUG: + /* if debug was requested then bump this up to ERROR + * to ensure it is seen in a log */ + if (syslog_levels & G_LOG_LEVEL_DEBUG) { + priority = LOG_WARNING; + } else { + priority = LOG_DEBUG; + } + prefix = "DEBUG"; + break; + default: + priority = LOG_DEBUG; + prefix = "UNKNOWN"; + break; + } + + if (priorityp != NULL) { + *priorityp = priority; + } + if (prefixp != NULL) { + *prefixp = prefix; + } +} + +void +ck_log_default_handler (const gchar *log_domain, + GLogLevelFlags log_level, + const gchar *message, + gpointer unused_data) +{ + GString *gstring; + int priority; + const char *level_prefix; + char *string; + gboolean do_log; + gboolean is_fatal; + + is_fatal = (log_level & G_LOG_FLAG_FATAL) != 0; + + do_log = (log_level & syslog_levels); + if (! do_log) { + return; + } + + if (! initialized) { + ck_log_init (); + } + + log_level_to_priority_and_prefix (log_level, + &priority, + &level_prefix); + + gstring = g_string_new (NULL); + + if (log_domain != NULL) { + g_string_append (gstring, log_domain); + g_string_append_c (gstring, '-'); + } + g_string_append (gstring, level_prefix); + + g_string_append (gstring, ": "); + if (message == NULL) { + g_string_append (gstring, "(NULL) message"); + } else { + g_string_append (gstring, message); + } + if (is_fatal) { + g_string_append (gstring, "\naborting...\n"); + } else { + g_string_append (gstring, "\n"); + } + + string = g_string_free (gstring, FALSE); + + syslog (priority, "%s", string); + + g_free (string); +} + +void +ck_log_toggle_debug (void) +{ + if (syslog_levels & G_LOG_LEVEL_DEBUG) { + g_debug ("Debugging disabled"); + syslog_levels &= ~G_LOG_LEVEL_DEBUG; + } else { + syslog_levels |= G_LOG_LEVEL_DEBUG; + g_debug ("Debugging enabled"); + } +} + +void +ck_log_set_debug (gboolean debug) +{ + if (debug) { + syslog_levels |= G_LOG_LEVEL_DEBUG; + g_debug ("Debugging enabled"); + } else { + g_debug ("Debugging disabled"); + syslog_levels &= ~G_LOG_LEVEL_DEBUG; + } +} + +void +ck_log_init (void) +{ + const char *prg_name; + + g_log_set_default_handler (ck_log_default_handler, NULL); + + prg_name = g_get_prgname (); + + openlog (prg_name, LOG_PERROR|LOG_PID, LOG_DAEMON); + + initialized = TRUE; +} + +void +ck_log_shutdown (void) +{ + closelog (); + initialized = FALSE; +} + diff --git a/src/ck-log.h b/src/ck-log.h new file mode 100644 index 0000000..0028598 --- /dev/null +++ b/src/ck-log.h @@ -0,0 +1,41 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Authors: William Jon McCann + * + */ + +#ifndef __CK_LOG_H +#define __CK_LOG_H + +#include + +G_BEGIN_DECLS + +void ck_log_default_handler (const gchar *log_domain, + GLogLevelFlags log_level, + const gchar *message, + gpointer unused_data); +void ck_log_set_debug (gboolean debug); +void ck_log_toggle_debug (void); +void ck_log_init (void); +void ck_log_shutdown (void); + +G_END_DECLS + +#endif /* __CK_LOG_H */ diff --git a/src/ck-manager.c b/src/ck-manager.c index c4c3faf..99eeed6 100644 --- a/src/ck-manager.c +++ b/src/ck-manager.c @@ -43,7 +43,6 @@ #include "ck-job.h" #include "ck-marshal.h" -#include "ck-debug.h" #include "proc.h" #define CK_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CK_TYPE_MANAGER, CkManagerPrivate)) @@ -111,7 +110,7 @@ remove_pending_job (CkJob *job) command = NULL; ck_job_get_command (job, &command); - ck_debug ("Removing pending job: %s", command); + g_debug ("Removing pending job: %s", command); g_free (command); ck_job_cancel (job); @@ -122,7 +121,7 @@ remove_pending_job (CkJob *job) static void _leader_info_free (LeaderInfo *info) { - ck_debug ("Freeing leader info: %s", info->ssid); + g_debug ("Freeing leader info: %s", info->ssid); g_free (info->ssid); info->ssid = NULL; @@ -294,7 +293,7 @@ add_new_seat (CkManager *manager, g_hash_table_insert (manager->priv->seats, sid, seat); - ck_debug ("Added seat: %s kind:%d", sid, kind); + g_debug ("Added seat: %s kind:%d", sid, kind); g_signal_emit (manager, signals [SEAT_ADDED], 0, sid); @@ -317,7 +316,7 @@ remove_seat (CkManager *manager, g_signal_emit (manager, signals [SEAT_REMOVED], 0, sid); - ck_debug ("Removed seat: %s", sid); + g_debug ("Removed seat: %s", sid); g_free (sid); } @@ -404,7 +403,7 @@ get_caller_info (CkManager *manager, G_TYPE_INVALID, G_TYPE_UINT, calling_uid, G_TYPE_INVALID)) { - ck_debug ("GetConnectionUnixUser() failed: %s", error->message); + g_debug ("GetConnectionUnixUser() failed: %s", error->message); g_error_free (error); goto out; } @@ -414,15 +413,15 @@ get_caller_info (CkManager *manager, G_TYPE_INVALID, G_TYPE_UINT, calling_pid, G_TYPE_INVALID)) { - ck_debug ("GetConnectionUnixProcessID() failed: %s", error->message); + g_debug ("GetConnectionUnixProcessID() failed: %s", error->message); g_error_free (error); goto out; } res = TRUE; - ck_debug ("uid = %d", *calling_uid); - ck_debug ("pid = %d", *calling_pid); + g_debug ("uid = %d", *calling_uid); + g_debug ("pid = %d", *calling_pid); out: return res; @@ -438,7 +437,7 @@ manager_set_system_idle_hint (CkManager *manager, /* FIXME: can we get a time from the dbus message? */ g_get_current_time (&manager->priv->system_idle_since_hint); - ck_debug ("Emitting system-idle-hint-changed: %d", idle_hint); + g_debug ("Emitting system-idle-hint-changed: %d", idle_hint); g_signal_emit (manager, signals [SYSTEM_IDLE_HINT_CHANGED], 0, idle_hint); } @@ -565,7 +564,7 @@ open_session_for_leader_info (CkManager *manager, if (session == NULL) { GError *error; - ck_debug ("Unable to create new session"); + g_debug ("Unable to create new session"); error = g_error_new (CK_MANAGER_ERROR, CK_MANAGER_ERROR_GENERAL, "Unable to create new session"); @@ -779,14 +778,14 @@ job_completed (CkJob *job, int status, JobData *data) { - ck_debug ("Job status: %d", status); + g_debug ("Job status: %d", status); if (status == 0) { char *output; GPtrArray *parameters; output = NULL; ck_job_get_stdout (job, &output); - ck_debug ("Job output: %s", output); + g_debug ("Job output: %s", output); parameters = parse_output (output); g_free (output); @@ -846,7 +845,7 @@ generate_session_for_leader_info (CkManager *manager, g_error_free (error); if (local_error != NULL) { - ck_debug ("stat on pid %d failed: %s", leader_info->pid, local_error->message); + g_debug ("stat on pid %d failed: %s", leader_info->pid, local_error->message); g_error_free (local_error); } @@ -889,7 +888,7 @@ create_session_for_sender (CkManager *manager, cookie = generate_session_cookie (manager); ssid = generate_session_id (manager); - ck_debug ("Creating new session ssid: %s", ssid); + g_debug ("Creating new session ssid: %s", ssid); leader_info = g_new0 (LeaderInfo, 1); leader_info->uid = uid; @@ -971,7 +970,7 @@ ck_manager_get_session_for_cookie (CkManager *manager, _("Unable to lookup information about calling process '%d'"), calling_pid); if (local_error != NULL) { - ck_debug ("stat on pid %d failed: %s", calling_pid, local_error->message); + g_debug ("stat on pid %d failed: %s", calling_pid, local_error->message); g_error_free (local_error); } @@ -1069,7 +1068,7 @@ ck_manager_get_session_for_unix_process (CkManager *manager, res = proc_stat_new_for_pid (calling_pid, &stat, &error); if (! res) { GError *error; - ck_debug ("stat on pid %d failed", calling_pid); + g_debug ("stat on pid %d failed", calling_pid); error = g_error_new (CK_MANAGER_ERROR, CK_MANAGER_ERROR_GENERAL, _("Unable to lookup information about calling process '%d'"), @@ -1179,7 +1178,7 @@ remove_session_for_cookie (CkManager *manager, char *ssid; char *sid; - ck_debug ("Removing session for cookie: %s", cookie); + g_debug ("Removing session for cookie: %s", cookie); leader_info = g_hash_table_lookup (manager->priv->leaders, cookie); @@ -1290,7 +1289,7 @@ ck_manager_close_session (CkManager *manager, pid_t calling_pid; GError *error; - ck_debug ("Closing session for cookie: %s", cookie); + g_debug ("Closing session for cookie: %s", cookie); sender = dbus_g_method_get_sender (context); res = get_caller_info (manager, @@ -1365,7 +1364,7 @@ remove_sessions_for_connection (CkManager *manager, data.service_name = service_name; data.manager = manager; - ck_debug ("Removing sessions for service name: %s", service_name); + g_debug ("Removing sessions for service name: %s", service_name); n_removed = g_hash_table_foreach_remove (manager->priv->leaders, (GHRFunc)remove_leader_for_connection, @@ -1384,7 +1383,7 @@ bus_name_owner_changed (DBusGProxy *bus_proxy, remove_sessions_for_connection (manager, old_service_name); } - ck_debug ("NameOwnerChanged: service_name='%s', old_service_name='%s' new_service_name='%s'", + g_debug ("NameOwnerChanged: service_name='%s', old_service_name='%s' new_service_name='%s'", service_name, old_service_name, new_service_name); } diff --git a/src/ck-seat.c b/src/ck-seat.c index 06f0240..a77e0b1 100644 --- a/src/ck-seat.c +++ b/src/ck-seat.c @@ -47,7 +47,6 @@ #include "ck-session.h" #include "ck-vt-monitor.h" -#include "ck-debug.h" #define CK_SEAT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CK_TYPE_SEAT, CkSeatPrivate)) @@ -225,12 +224,12 @@ _seat_activate_session (CkSeat *seat, 0); - ck_debug ("Attempting to activate VT %u", num); + g_debug ("Attempting to activate VT %u", num); vt_error = NULL; ret = ck_vt_monitor_set_active (seat->priv->vt_monitor, num, &vt_error); if (! ret) { - ck_debug ("Unable to activate session: %s", vt_error->message); + g_debug ("Unable to activate session: %s", vt_error->message); dbus_g_method_return_error (context, vt_error); g_signal_handler_disconnect (seat->priv->vt_monitor, adata->handler_id); g_error_free (vt_error); @@ -293,7 +292,7 @@ match_session_display_device (const char *key, if (device != NULL && display_device != NULL && strcmp (device, display_device) == 0) { - ck_debug ("Matched display-device %s to %s", display_device, key); + g_debug ("Matched display-device %s to %s", display_device, key); ret = TRUE; } out: @@ -323,7 +322,7 @@ match_session_x11_display_device (const char *key, if (device != NULL && x11_display_device != NULL && strcmp (device, x11_display_device) == 0) { - ck_debug ("Matched x11-display-device %s to %s", x11_display_device, key); + g_debug ("Matched x11-display-device %s to %s", x11_display_device, key); ret = TRUE; } out: @@ -473,7 +472,7 @@ change_active_session (CkSeat *seat, ck_session_set_active (session, TRUE, NULL); } - ck_debug ("Active session changed: %s", ssid); + g_debug ("Active session changed: %s", ssid); g_signal_emit (seat, signals [ACTIVE_SESSION_CHANGED], 0, ssid); @@ -489,7 +488,7 @@ update_active_vt (CkSeat *seat, device = g_strdup_printf (_PATH_TTY "%u", num); - ck_debug ("Active device: %s", device); + g_debug ("Active device: %s", device); session = find_session_for_display_device (seat, device); change_active_session (seat, session); @@ -537,7 +536,7 @@ ck_seat_remove_session (CkSeat *seat, ck_session_get_id (session, &ssid, NULL); if (g_hash_table_lookup (seat->priv->sessions, ssid) == NULL) { - ck_debug ("Session %s is not attached to seat %s", ssid, seat->priv->id); + g_debug ("Session %s is not attached to seat %s", ssid, seat->priv->id); g_set_error (error, CK_SEAT_ERROR, CK_SEAT_ERROR_GENERAL, @@ -547,7 +546,7 @@ ck_seat_remove_session (CkSeat *seat, g_signal_handlers_disconnect_by_func (session, session_activate, seat); - ck_debug ("Emitting removed signal: %s", ssid); + g_debug ("Emitting removed signal: %s", ssid); g_signal_emit (seat, signals [SESSION_REMOVED], 0, ssid); @@ -581,7 +580,7 @@ ck_seat_add_session (CkSeat *seat, g_signal_connect_object (session, "activate", G_CALLBACK (session_activate), seat, 0); /* FIXME: attach to property notify signals? */ - ck_debug ("Emitting added signal: %s", ssid); + g_debug ("Emitting added signal: %s", ssid); g_signal_emit (seat, signals [SESSION_ADDED], 0, ssid); @@ -639,7 +638,7 @@ active_vt_changed (CkVtMonitor *vt_monitor, guint num, CkSeat *seat) { - ck_debug ("Active vt changed: %u", num); + g_debug ("Active vt changed: %u", num); update_active_vt (seat, num); } diff --git a/src/ck-session.c b/src/ck-session.c index 91483fc..02211e7 100644 --- a/src/ck-session.c +++ b/src/ck-session.c @@ -39,7 +39,6 @@ #include "ck-session.h" #include "ck-session-glue.h" #include "ck-marshal.h" -#include "ck-debug.h" #define CK_SESSION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CK_TYPE_SESSION, CkSessionPrivate)) @@ -154,7 +153,7 @@ ck_session_lock (CkSession *session, { g_return_val_if_fail (CK_IS_SESSION (session), FALSE); - ck_debug ("Emitting lock for session %s", session->priv->id); + g_debug ("Emitting lock for session %s", session->priv->id); g_signal_emit (session, signals [LOCK], 0); dbus_g_method_return (context); @@ -168,7 +167,7 @@ ck_session_unlock (CkSession *session, { g_return_val_if_fail (CK_IS_SESSION (session), FALSE); - ck_debug ("Emitting unlock for session %s", session->priv->id); + g_debug ("Emitting unlock for session %s", session->priv->id); g_signal_emit (session, signals [UNLOCK], 0); dbus_g_method_return (context); @@ -214,8 +213,8 @@ get_caller_info (CkSession *session, res = TRUE; - ck_debug ("uid = %d", *calling_uid); - ck_debug ("pid = %d", *calling_pid); + g_debug ("uid = %d", *calling_uid); + g_debug ("pid = %d", *calling_pid); out: return res; @@ -232,7 +231,7 @@ session_set_idle_hint_internal (CkSession *session, /* FIXME: can we get a time from the dbus message? */ g_get_current_time (&session->priv->idle_since_hint); - ck_debug ("Emitting idle-changed for session %s", session->priv->id); + g_debug ("Emitting idle-changed for session %s", session->priv->id); g_signal_emit (session, signals [IDLE_HINT_CHANGED], 0, idle_hint); } @@ -371,7 +370,7 @@ ck_session_activate (CkSession *session, /* if the signal is not handled then either: a) aren't attached to seat b) seat doesn't support activation changes */ - ck_debug ("Activate signal not handled"); + g_debug ("Activate signal not handled"); error = g_error_new (CK_SESSION_ERROR, CK_SESSION_ERROR_GENERAL, @@ -811,7 +810,7 @@ session_is_text (CkSession *session) ret = TRUE; } - ck_debug ("Identified session '%s' as %s", + g_debug ("Identified session '%s' as %s", session->priv->id, ret ? "text" : "graphical"); @@ -848,7 +847,7 @@ check_tty_idle (CkSession *session) } if (g_stat (session->priv->display_device, &sb) < 0) { - ck_debug ("Unable to stat: %s: %s", session->priv->display_device, g_strerror (errno)); + g_debug ("Unable to stat: %s: %s", session->priv->display_device, g_strerror (errno)); return FALSE; } @@ -860,7 +859,7 @@ check_tty_idle (CkSession *session) static void add_idle_hint_timeout (CkSession *session) { - ck_debug ("Adding watch for text session idle"); + g_debug ("Adding watch for text session idle"); /* yes this sucks - we'll add file monitoring when it is in glib */ if (session->priv->idle_timeout_id == 0) { #if GLIB_CHECK_VERSION(2,14,0) @@ -1175,29 +1174,29 @@ ck_session_new_with_parameters (const char *ssid, 1, &prop_val, G_MAXUINT); if (! res) { - ck_debug ("Unable to extract parameter input"); + g_debug ("Unable to extract parameter input"); goto cont; } if (prop_name == NULL) { - ck_debug ("Skipping NULL parameter"); + g_debug ("Skipping NULL parameter"); goto cont; } if (strcmp (prop_name, "id") == 0 || strcmp (prop_name, "cookie") == 0) { - ck_debug ("Skipping restricted parameter: %s", prop_name); + g_debug ("Skipping restricted parameter: %s", prop_name); goto cont; } pspec = g_object_class_find_property (class, prop_name); if (! pspec) { - ck_debug ("Skipping unknown parameter: %s", prop_name); + g_debug ("Skipping unknown parameter: %s", prop_name); goto cont; } if (!(pspec->flags & G_PARAM_WRITABLE)) { - ck_debug ("property '%s' is not writable", pspec->name); + g_debug ("property '%s' is not writable", pspec->name); goto cont; } @@ -1206,7 +1205,7 @@ ck_session_new_with_parameters (const char *ssid, g_value_init (¶ms[n_params].value, G_PARAM_SPEC_VALUE_TYPE (pspec)); res = g_value_transform (prop_val, ¶ms[n_params].value); if (! res) { - ck_debug ("unable to transform property value for '%s'", pspec->name); + g_debug ("unable to transform property value for '%s'", pspec->name); goto cont; } diff --git a/src/ck-vt-monitor.c b/src/ck-vt-monitor.c index 1bb9f52..40f834a 100644 --- a/src/ck-vt-monitor.c +++ b/src/ck-vt-monitor.c @@ -45,7 +45,6 @@ #include "ck-vt-monitor.h" #include "ck-marshal.h" -#include "ck-debug.h" #define ERROR -1 @@ -168,7 +167,7 @@ change_active_num (CkVtMonitor *vt_monitor, { if (vt_monitor->priv->active_num != num) { - ck_debug ("Changing active VT: %d", num); + g_debug ("Changing active VT: %d", num); vt_monitor->priv->active_num = num; @@ -177,7 +176,7 @@ change_active_num (CkVtMonitor *vt_monitor, g_signal_emit (vt_monitor, signals[ACTIVE_CHANGED], 0, num); } else { - ck_debug ("VT activated but already active: %d", num); + g_debug ("VT activated but already active: %d", num); } } @@ -220,7 +219,7 @@ process_queue (CkVtMonitor *vt_monitor) g_async_queue_lock (vt_monitor->priv->event_queue); - ck_debug ("Processing VT event queue"); + g_debug ("Processing VT event queue"); queue_length = g_async_queue_length_unlocked (vt_monitor->priv->event_queue); data = NULL; @@ -236,7 +235,7 @@ process_queue (CkVtMonitor *vt_monitor) } if (data != NULL) { - ck_debug ("Compressing queue; skipping event for VT %d", data->num); + g_debug ("Compressing queue; skipping event for VT %d", data->num); event_data_free (data); } @@ -280,10 +279,10 @@ vt_thread_start (ThreadData *data) num = data->num; again: - ck_debug ("VT_WAITACTIVE for vt %d", num); + g_debug ("VT_WAITACTIVE for vt %d", num); ret = ioctl (vt_monitor->priv->vfd, VT_WAITACTIVE, num); - ck_debug ("VT_WAITACTIVE for vt %d returned %d", num, ret); + g_debug ("VT_WAITACTIVE for vt %d returned %d", num, ret); if (ret == ERROR) { const char *errmsg; @@ -291,15 +290,11 @@ vt_thread_start (ThreadData *data) errmsg = g_strerror (errno); if (errno == EINTR) { - ck_debug ("Interrupted waiting for native console %d activation: %s", + g_debug ("Interrupted waiting for native console %d activation: %s", num, errmsg); goto again; } else { - ck_debug ("Error waiting for native console %d activation: %s", - num, - errmsg); - g_warning ("Error waiting for native console %d activation: %s", num, errmsg); @@ -312,7 +307,7 @@ vt_thread_start (ThreadData *data) /* add event to queue */ event = g_new0 (EventData, 1); event->num = num; - ck_debug ("Pushing activation event for VT %d onto queue", num); + g_debug ("Pushing activation event for VT %d onto queue", num); g_async_queue_push (vt_monitor->priv->event_queue, event); @@ -345,14 +340,14 @@ vt_add_watch_unlocked (CkVtMonitor *vt_monitor, data->num = num; data->vt_monitor = vt_monitor; - ck_debug ("Creating thread for vt %d", num); + g_debug ("Creating thread for vt %d", num); id = GINT_TO_POINTER (num); error = NULL; thread = g_thread_create_full ((GThreadFunc)vt_thread_start, data, 65536, FALSE, TRUE, G_THREAD_PRIORITY_NORMAL, &error); if (thread == NULL) { - ck_debug ("Unable to create thread: %s", error->message); + g_debug ("Unable to create thread: %s", error->message); g_error_free (error); } else { g_hash_table_insert (vt_monitor->priv->vt_thread_hash, id, thread); @@ -403,12 +398,12 @@ get_active_native (CkVtMonitor *vt_monitor) { int i; - ck_debug ("Current VT: tty%d", stat.v_active); + g_debug ("Current VT: tty%d", stat.v_active); for (i = 1; i <= 16; i++) { gboolean is_on; is_on = stat.v_state & (1 << i); - ck_debug ("VT %d:%s", i, is_on ? "on" : "off"); + g_debug ("VT %d:%s", i, is_on ? "on" : "off"); } } @@ -450,7 +445,6 @@ ck_vt_monitor_init (CkVtMonitor *vt_monitor) if (fd == ERROR) { const char *errmsg; errmsg = g_strerror (errno); - ck_debug ("Unable to open a console: %s", errmsg); g_warning ("Unable to open a console: %s", errmsg); } else { vt_monitor->priv->event_queue = g_async_queue_new (); 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