From: Jason Abele <[email protected]> To enable easier debugging in the field, allow connman users to change log verbosity at runtime.
Signed-off-by: Jason Abele <[email protected]> --- src/connman.h | 2 ++ src/log.c | 23 +++++++++++++++++++---- src/manager.c | 21 ++++++++++++++++++++- 3 files changed, 41 insertions(+), 5 deletions(-) Obviously this lacks the entry in docs and probably should be available from connmanctl as well, but I wanted to get feedback on whether this is something acceptable upstream before filling out the rest of the details. diff --git a/src/connman.h b/src/connman.h index 2524f07..c553c5d 100644 --- a/src/connman.h +++ b/src/connman.h @@ -134,6 +134,8 @@ int __connman_log_init(const char *program, const char *debug, void __connman_log_cleanup(gboolean backtrace); void __connman_log_enable(struct connman_debug_desc *start, struct connman_debug_desc *stop); +const char *__connman_log_get_debug(void); +void __connman_log_set_debug(const char *debug); #include <connman/option.h> diff --git a/src/log.c b/src/log.c index a693bd0..0eacbc1 100644 --- a/src/log.c +++ b/src/log.c @@ -241,6 +241,7 @@ static void signal_setup(sighandler_t handler) extern struct connman_debug_desc __start___debug[]; extern struct connman_debug_desc __stop___debug[]; +static gchar *debuglog = NULL; static gchar **enabled = NULL; static bool is_enabled(struct connman_debug_desc *desc) @@ -288,9 +289,25 @@ void __connman_log_enable(struct connman_debug_desc *start, if (is_enabled(desc)) desc->flags |= CONNMAN_DEBUG_FLAG_PRINT; + else + desc->flags &= !CONNMAN_DEBUG_FLAG_PRINT; } } +const char *__connman_log_get_debug(void) { + return debuglog; +} + +void __connman_log_set_debug(const char *debug) { + if (g_strcmp0(debuglog, debug) != 0) { + g_free(debuglog); + debuglog = g_strdup(debug); + enabled = g_strsplit_set(debuglog, ":, ", 0); + } + + __connman_log_enable(__start___debug, __stop___debug); +} + int __connman_log_init(const char *program, const char *debug, gboolean detach, gboolean backtrace, const char *program_name, const char *program_version) @@ -301,10 +318,7 @@ int __connman_log_init(const char *program, const char *debug, program_exec = program; program_path = getcwd(path, sizeof(path)); - if (debug) - enabled = g_strsplit_set(debug, ":, ", 0); - - __connman_log_enable(__start___debug, __stop___debug); + __connman_log_set_debug(debug); if (!detach) option |= LOG_PERROR; @@ -329,4 +343,5 @@ void __connman_log_cleanup(gboolean backtrace) signal_setup(SIG_DFL); g_strfreev(enabled); + g_free(debuglog); } diff --git a/src/manager.c b/src/manager.c index d15ce20..12bd308 100644 --- a/src/manager.c +++ b/src/manager.c @@ -40,7 +40,7 @@ static DBusMessage *get_properties(DBusConnection *conn, DBusMessage *reply; DBusMessageIter array, dict; dbus_bool_t offlinemode; - const char *str; + const char *str, *debuglog; DBG("conn %p", conn); @@ -64,6 +64,13 @@ static DBusMessage *get_properties(DBusConnection *conn, DBUS_TYPE_BOOLEAN, &sessionmode); + debuglog = __connman_log_get_debug(); + if (debuglog == NULL) + debuglog = ""; + connman_dbus_dict_append_basic(&dict, "DebugLog", + DBUS_TYPE_STRING, + &debuglog); + connman_dbus_dict_close(&array, &dict); return reply; @@ -110,6 +117,18 @@ static DBusMessage *set_property(DBusConnection *conn, dbus_message_iter_get_basic(&value, &sessionmode); + } else if (g_str_equal(name, "DebugLog")) { + const char *str; + + if (type != DBUS_TYPE_STRING) + return __connman_error_invalid_arguments(msg); + + dbus_message_iter_get_basic(&value, &str); + if (strlen(str) == 0) + str = NULL; + __connman_log_set_debug(str); + + } else return __connman_error_invalid_property(msg); -- 1.9.1 _______________________________________________ connman mailing list [email protected] https://lists.connman.net/mailman/listinfo/connman
