diff options
author | Thomas Haller <thaller@redhat.com> | 2015-06-09 09:59:18 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-06-16 15:38:47 +0200 |
commit | e88ab8bba383706e3c13efc29edc4d32df146f48 (patch) | |
tree | 2184fc1a7e207459307516eadbb7aadd1151441f | |
parent | b6d15828993b1c72ed4a1bc7caf2114ebee6bf14 (diff) | |
download | NetworkManager-e88ab8bba383706e3c13efc29edc4d32df146f48.tar.gz |
config: log configuration at startup and on reload
-rw-r--r-- | src/main.c | 1 | ||||
-rw-r--r-- | src/nm-config-data.c | 97 | ||||
-rw-r--r-- | src/nm-config-data.h | 2 | ||||
-rw-r--r-- | src/nm-config.c | 2 |
4 files changed, 102 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c index 68a6b2f2ac..668c9af28d 100644 --- a/src/main.c +++ b/src/main.c @@ -412,6 +412,7 @@ main (int argc, char *argv[]) dbus_glib_global_set_disable_legacy_property_access (); nm_log_info (LOGD_CORE, "Read config: %s", nm_config_data_get_config_description (nm_config_get_data (config))); + nm_config_data_log (nm_config_get_data (config), "CONFIG: "); nm_log_dbg (LOGD_CORE, "WEXT support is %s", #if HAVE_WEXT "enabled" diff --git a/src/nm-config-data.c b/src/nm-config-data.c index 55f119c0be..014097b946 100644 --- a/src/nm-config-data.c +++ b/src/nm-config-data.c @@ -29,6 +29,7 @@ #include "nm-core-internal.h" #include "nm-keyfile-internal.h" #include "nm-macros-internal.h" +#include "nm-logging.h" typedef struct { char *group_name; @@ -305,6 +306,102 @@ _merge_keyfiles (GKeyFile *keyfile_user, GKeyFile *keyfile_intern) /************************************************************************/ +static int +_nm_config_data_log_sort (const char **pa, const char **pb, gpointer dummy) +{ + gboolean a_is_connection, b_is_connection; + gboolean a_is_intern, b_is_intern; + const char *a = *pa; + const char *b = *pb; + + /* we sort intern groups to the end. */ + a_is_intern = g_str_has_prefix (a, NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN); + b_is_intern = g_str_has_prefix (b, NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN); + + if (a_is_intern && b_is_intern) + return 0; + if (a_is_intern) + return 1; + if (b_is_intern) + return -1; + + /* we sort connection groups before intern groups (to the end). */ + a_is_connection = a && g_str_has_prefix (a, NM_CONFIG_KEYFILE_GROUPPREFIX_CONNECTION); + b_is_connection = b && g_str_has_prefix (b, NM_CONFIG_KEYFILE_GROUPPREFIX_CONNECTION); + + if (a_is_connection && b_is_connection) { + /* if both are connection gruops, we want the explicit [connection] group first. */ + a_is_connection = !strcmp (a, NM_CONFIG_KEYFILE_GROUPPREFIX_CONNECTION); + b_is_connection = !strcmp (b, NM_CONFIG_KEYFILE_GROUPPREFIX_CONNECTION); + + if (a_is_connection == b_is_connection) + return 0; + if (a_is_connection) + return -1; + return 1; + } + if (a_is_connection && !b_is_connection) + return 1; + if (b_is_connection && !a_is_connection) + return -1; + + /* no reordering. */ + return 0; +} + +void +nm_config_data_log (const NMConfigData *self, const char *prefix) +{ + NMConfigDataPrivate *priv; + gs_strfreev char **groups = NULL; + gsize groups_len; + guint g, k; + + g_return_if_fail (NM_IS_CONFIG_DATA (self)); + + if (!nm_logging_enabled (LOGL_DEBUG, LOGD_CORE)) + return; + + if (!prefix) + prefix = ""; + +#define _LOG(...) _nm_log (LOGL_DEBUG, LOGD_CORE, 0, "%s"_NM_UTILS_MACRO_FIRST(__VA_ARGS__), prefix _NM_UTILS_MACRO_REST (__VA_ARGS__)) + + priv = NM_CONFIG_DATA_GET_PRIVATE (self); + + groups = g_key_file_get_groups (priv->keyfile, &groups_len); + + if (groups && groups[0]) { + g_qsort_with_data (groups, groups_len, + sizeof (char *), + (GCompareDataFunc) _nm_config_data_log_sort, + NULL); + } + + _LOG ("config-data[%p]: %lu groups", self, (unsigned long) groups_len); + + for (g = 0; groups[g]; g++) { + const char *group = groups[g]; + gs_strfreev char **keys = NULL; + + _LOG (""); + _LOG ("[%s]", group); + + keys = g_key_file_get_keys (priv->keyfile, group, NULL, NULL); + for (k = 0; keys && keys[k]; k++) { + const char *key = keys[k]; + gs_free char *value = NULL; + + value = g_key_file_get_value (priv->keyfile, group, key, NULL); + _LOG (" %s=%s", key, value); + } + } + +#undef _LOG +} + +/************************************************************************/ + char * nm_config_data_get_connection_default (const NMConfigData *self, const char *property, diff --git a/src/nm-config-data.h b/src/nm-config-data.h index 4639367766..c37db9e29c 100644 --- a/src/nm-config-data.h +++ b/src/nm-config-data.h @@ -81,6 +81,8 @@ NMConfigData *nm_config_data_new_update_no_auto_default (const NMConfigData *bas NMConfigChangeFlags nm_config_data_diff (NMConfigData *old_data, NMConfigData *new_data); +void nm_config_data_log (const NMConfigData *config_data, const char *prefix); + const char *nm_config_data_get_config_main_file (const NMConfigData *config_data); const char *nm_config_data_get_config_description (const NMConfigData *config_data); diff --git a/src/nm-config.c b/src/nm-config.c index e81f17be97..4438fdfa7a 100644 --- a/src/nm-config.c +++ b/src/nm-config.c @@ -1302,6 +1302,8 @@ _set_config_data (NMConfig *self, NMConfigData *new_data) nm_log_info (LOGD_CORE, "config: update %s (%s)", nm_config_data_get_config_description (new_data), (log_str = nm_config_change_flags_to_string (changes))); + if (NM_FLAGS_HAS (changes, NM_CONFIG_CHANGE_VALUES)) + nm_config_data_log (new_data, "CONFIG: "); priv->config_data = new_data; g_signal_emit (self, signals[SIGNAL_CONFIG_CHANGED], 0, new_data, changes, old_data); g_object_unref (old_data); |