diff options
author | Thomas Haller <thaller@redhat.com> | 2017-02-07 15:19:57 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-02-07 15:28:14 +0100 |
commit | ca5f915ac2bda6ecb2bce628f5f608a945a59cfd (patch) | |
tree | 20f0f296906f7d059c4f31b765b0d8fdfdf41276 | |
parent | 0cb85f161ea332dc400d7e33071ca1f3dfafd730 (diff) | |
download | NetworkManager-ca5f915ac2bda6ecb2bce628f5f608a945a59cfd.tar.gz |
platform: cleanup _log_dbg_sysctl_set_impl() and _log_dbg_sysctl_get_impl()
- use gs_free attribute
- move printing the logging cache warning inside the place
where we actuall add a new item to the cache.
It's really a minor cleanup of stuff that come to my mind reviewing the
function.
-rw-r--r-- | src/platform/nm-linux-platform.c | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 2c5f089710..5e3919ef18 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -2584,23 +2584,24 @@ static void _log_dbg_sysctl_set_impl (NMPlatform *platform, const char *pathid, int dirfd, const char *path, const char *value) { GError *error = NULL; - char *contents, *contents_escaped; - char *value_escaped = g_strescape (value, NULL); + char *contents; + gs_free char *value_escaped = g_strescape (value, NULL); if (nm_utils_file_get_contents (dirfd, path, 1*1024*1024, &contents, NULL, &error) < 0) { _LOGD ("sysctl: setting '%s' to '%s' (current value cannot be read: %s)", pathid, value_escaped, error->message); g_clear_error (&error); - } else { - g_strstrip (contents); - contents_escaped = g_strescape (contents, NULL); - if (strcmp (contents, value) == 0) - _LOGD ("sysctl: setting '%s' to '%s' (current value is identical)", pathid, value_escaped); - else - _LOGD ("sysctl: setting '%s' to '%s' (current value is '%s')", pathid, value_escaped, contents_escaped); - g_free (contents); - g_free (contents_escaped); + return; + } + + g_strstrip (contents); + if (nm_streq (contents, value)) + _LOGD ("sysctl: setting '%s' to '%s' (current value is identical)", pathid, value_escaped); + else { + gs_free char *contents_escaped = g_strescape (contents, NULL); + + _LOGD ("sysctl: setting '%s' to '%s' (current value is '%s')", pathid, value_escaped, contents_escaped); } - g_free (value_escaped); + g_free (contents); } #define _log_dbg_sysctl_set(platform, pathid, dirfd, path, value) \ @@ -2750,26 +2751,23 @@ _log_dbg_sysctl_get_impl (NMPlatform *platform, const char *pathid, const char * if (prev_value) { if (strcmp (prev_value, contents) != 0) { - char *contents_escaped = g_strescape (contents, NULL); - char *prev_value_escaped = g_strescape (prev_value, NULL); + gs_free char *contents_escaped = g_strescape (contents, NULL); + gs_free char *prev_value_escaped = g_strescape (prev_value, NULL); _LOGD ("sysctl: reading '%s': '%s' (changed from '%s' on last read)", pathid, contents_escaped, prev_value_escaped); - g_free (contents_escaped); - g_free (prev_value_escaped); g_hash_table_insert (priv->sysctl_get_prev_values, g_strdup (pathid), g_strdup (contents)); } } else { - char *contents_escaped = g_strescape (contents, NULL); + gs_free char *contents_escaped = g_strescape (contents, NULL); _LOGD ("sysctl: reading '%s': '%s'", pathid, contents_escaped); - g_free (contents_escaped); g_hash_table_insert (priv->sysctl_get_prev_values, g_strdup (pathid), g_strdup (contents)); - } - if ( !priv->sysctl_get_warned - && g_hash_table_size (priv->sysctl_get_prev_values) > 50000) { - _LOGW ("sysctl: the internal cache for debug-logging of sysctl values grew pretty large. You can clear it by disabling debug-logging: `nmcli general logging level KEEP domains PLATFORM:INFO`."); - priv->sysctl_get_warned = TRUE; + if ( !priv->sysctl_get_warned + && g_hash_table_size (priv->sysctl_get_prev_values) > 50000) { + _LOGW ("sysctl: the internal cache for debug-logging of sysctl values grew pretty large. You can clear it by disabling debug-logging: `nmcli general logging level KEEP domains PLATFORM:INFO`."); + priv->sysctl_get_warned = TRUE; + } } } |