diff options
author | 2012-02-05 02:48:56 -0500 | |
---|---|---|
committer | 2012-02-05 02:48:56 -0500 | |
commit | 6a792d0ef603f04b560b6423881dd54d48c86615 (patch) | |
tree | b4b1af23db7798c420d57c30f712765accd425ce | |
parent | Port to GFile, and add shell_utils_trivial_set_and_save() to simplify on_hand... (diff) | |
download | openrc-settingsd-6a792d0ef603f04b560b6423881dd54d48c86615.tar.gz openrc-settingsd-6a792d0ef603f04b560b6423881dd54d48c86615.tar.bz2 openrc-settingsd-6a792d0ef603f04b560b6423881dd54d48c86615.zip |
Enable/disable debug at runtime via --debug flag
-rw-r--r-- | configure.ac | 9 | ||||
-rw-r--r-- | src/hostnamed.c | 4 | ||||
-rw-r--r-- | src/main.c | 34 | ||||
-rw-r--r-- | src/shell-utils.c | 14 |
4 files changed, 33 insertions, 28 deletions
diff --git a/configure.ac b/configure.ac index 5abb61c..9e64fea 100644 --- a/configure.ac +++ b/configure.ac @@ -19,15 +19,6 @@ if test "x$GDBUS_CODEGEN" = x; then AC_MSG_ERROR([Failed to find gdbus-codegen]) fi -AC_ARG_ENABLE([debug], - [AS_HELP_STRING([--enable-debug], - [enable extra debugging messages])], - [], [enable_debug=no]) -if test "x$enable_debug" = "xyes" ; then - AC_MSG_RESULT([enabling extra debugging messages]) - AC_DEFINE(OPENRC_SETTINGSD_DEBUG,1,[Enable extra debugging messages.]) -fi - AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([ Makefile diff --git a/src/hostnamed.c b/src/hostnamed.c index c21d875..4f95d04 100644 --- a/src/hostnamed.c +++ b/src/hostnamed.c @@ -261,9 +261,7 @@ on_bus_acquired (GDBusConnection *connection, gchar *name; GError *err = NULL; -#ifdef OPENRC_SETTINGSD_DEBUG g_debug ("Acquired a message bus connection"); -#endif hostname1 = openrc_settingsd_hostnamed_hostname1_skeleton_new (); @@ -293,9 +291,7 @@ on_name_acquired (GDBusConnection *connection, const gchar *bus_name, gpointer user_data) { -#ifdef OPENRC_SETTINGSD_DEBUG g_debug ("Acquired the name %s", bus_name); -#endif } static void @@ -16,6 +16,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include <stdlib.h> +#include <string.h> + #include <glib.h> #include <gio/gio.h> @@ -24,16 +27,45 @@ #include "config.h" +#define DEFAULT_LEVELS (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE) + +static gboolean debug = FALSE; + +static GOptionEntry entries[] = +{ + { "debug", 0, 0, G_OPTION_ARG_NONE, &debug, "Enable debugging messages", NULL }, + { NULL } +}; + +static void +log_handler (const gchar *log_domain, + GLogLevelFlags log_level, + const gchar *message, + gpointer user_data) +{ + if (debug || log_level & DEFAULT_LEVELS) + g_log_default_handler (log_domain, log_level, message, user_data); +} + gint main (gint argc, gchar *argv[]) { + GError *error = NULL; + GOptionContext *context; GMainLoop *loop = NULL; g_type_init (); + g_log_set_default_handler (log_handler, NULL); + + context = g_option_context_new ("- system settings D-Bus service for OpenRC"); + g_option_context_add_main_entries (context, entries, NULL); + if (!g_option_context_parse (context, &argc, &argv, &error)) { + g_printerr ("Failed to parse options: %s\n", error->message); + exit (1); + } shell_utils_init (); hostnamed_init (FALSE); - loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); diff --git a/src/shell-utils.c b/src/shell-utils.c index 4f76fee..41a77db 100644 --- a/src/shell-utils.c +++ b/src/shell-utils.c @@ -160,9 +160,7 @@ shell_utils_trivial_new (GFile *file, gboolean want_separator = FALSE; /* Do we expect the next entry to be a separator or comment? */ s = filebuf; while (*s != 0) { -#ifdef OPENRC_SETTINGSD_DEBUG g_debug ("Scanning string: ``%s''", s); -#endif gboolean matched = FALSE; GMatchInfo *match_info = NULL; struct ShellEntry *entry = NULL; @@ -174,9 +172,7 @@ shell_utils_trivial_new (GFile *file, entry->string = g_match_info_fetch (match_info, 0); ret->entry_list = g_list_prepend (ret->entry_list, entry); s += strlen (entry->string); -#ifdef OPENRC_SETTINGSD_DEBUG g_debug ("Scanned comment: ``%s''", entry->string); -#endif g_match_info_free (match_info); match_info = NULL; want_separator = FALSE; @@ -192,9 +188,7 @@ shell_utils_trivial_new (GFile *file, entry->string = g_match_info_fetch (match_info, 0); ret->entry_list = g_list_prepend (ret->entry_list, entry); s += strlen (entry->string); -#ifdef OPENRC_SETTINGSD_DEBUG g_debug ("Scanned separator: ``%s''", entry->string); -#endif g_match_info_free (match_info); match_info = NULL; want_separator = FALSE; @@ -210,9 +204,7 @@ shell_utils_trivial_new (GFile *file, entry->string = g_match_info_fetch (match_info, 0); ret->entry_list = g_list_prepend (ret->entry_list, entry); s += strlen (entry->string); -#ifdef OPENRC_SETTINGSD_DEBUG g_debug ("Scanned indent: ``%s''", entry->string); -#endif g_match_info_free (match_info); match_info = NULL; continue; @@ -231,17 +223,13 @@ shell_utils_trivial_new (GFile *file, entry->string = g_match_info_fetch (match_info, 0); entry->variable = g_match_info_fetch (match_info, 1); s += strlen (entry->string); -#ifdef OPENRC_SETTINGSD_DEBUG g_debug ("Scanned variable: ``%s''", entry->string); -#endif g_match_info_free (match_info); match_info = NULL; want_separator = TRUE; while (*s != 0) { -#ifdef OPENRC_SETTINGSD_DEBUG g_debug ("Scanning string for values: ``%s''", s); -#endif gboolean matched2 = FALSE; gchar *temp1 = NULL, *temp2 = NULL; @@ -272,9 +260,7 @@ append_value: temp2 = g_match_info_fetch (match_info, 0); entry->string = g_strconcat (temp1, temp2, NULL); s += strlen (temp2); -#ifdef OPENRC_SETTINGSD_DEBUG g_debug ("Scanned value: ``%s''", temp2); -#endif g_free (temp1); g_free (temp2); g_match_info_free (match_info); |