From 0621b8b839946711f26d011d6a8944cb13164314 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 11 Aug 2015 13:18:57 +0200 Subject: [PATCH 1/9] active-connection: add logging macros _LOG*() (cherry picked from commit c6cbd652ba61812111de41506432002d70029dc7) --- src/nm-active-connection.c | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/nm-active-connection.c b/src/nm-active-connection.c index b0bdd77a81..134342335e 100644 --- a/src/nm-active-connection.c +++ b/src/nm-active-connection.c @@ -110,6 +110,46 @@ static void _device_cleanup (NMActiveConnection *self); /****************************************************************/ +#define _LOG_DOMAIN LOGD_DEVICE +#define _LOG_PREFIX_NAME "active-connection" + +#define _LOG(level, domain, self, ...) \ + G_STMT_START { \ + const NMLogLevel __level = (level); \ + const NMLogDomain __domain = (domain); \ + \ + if (nm_logging_enabled (__level, __domain)) { \ + char __prefix[128]; \ + const char *__p_prefix = _LOG_PREFIX_NAME; \ + const void *const __self = (self); \ + \ + if (__self) { \ + g_snprintf (__prefix, sizeof (__prefix), "%s[%p]", _LOG_PREFIX_NAME, __self); \ + __p_prefix = __prefix; \ + } \ + _nm_log (__level, __domain, 0, \ + "%s: " _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \ + __p_prefix _NM_UTILS_MACRO_REST (__VA_ARGS__)); \ + } \ + } G_STMT_END +#define _LOG_LEVEL_ENABLED(level, domain) \ + ( nm_logging_enabled ((level), (domain)) ) + +#ifdef NM_MORE_LOGGING +#define _LOGT_ENABLED() _LOG_LEVEL_ENABLED (LOGL_TRACE, _LOG_DOMAIN) +#define _LOGT(...) _LOG (LOGL_TRACE, _LOG_DOMAIN, self, __VA_ARGS__) +#else +#define _LOGT_ENABLED() FALSE +#define _LOGT(...) G_STMT_START { if (FALSE) { _LOG (LOGL_TRACE, _LOG_DOMAIN, self, __VA_ARGS__); } } G_STMT_END +#endif + +#define _LOGD(...) _LOG (LOGL_DEBUG, _LOG_DOMAIN, self, __VA_ARGS__) +#define _LOGI(...) _LOG (LOGL_INFO , _LOG_DOMAIN, self, __VA_ARGS__) +#define _LOGW(...) _LOG (LOGL_WARN , _LOG_DOMAIN, self, __VA_ARGS__) +#define _LOGE(...) _LOG (LOGL_ERR , _LOG_DOMAIN, self, __VA_ARGS__) + +/****************************************************************/ + static const char * state_to_string (NMActiveConnectionState state) { From 462b95551693096fd817dc463c4ae58a5c60c3f9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 11 Aug 2015 13:20:37 +0200 Subject: [PATCH 2/9] active-connection: make use of logging macro _LOGD() (cherry picked from commit 97c971b4e44b31ca0afdf547751d5d7ddc110e4c) --- src/nm-active-connection.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/nm-active-connection.c b/src/nm-active-connection.c index 134342335e..5e45bdf9e5 100644 --- a/src/nm-active-connection.c +++ b/src/nm-active-connection.c @@ -528,15 +528,15 @@ check_master_ready (NMActiveConnection *self) NMActiveConnectionState master_state = NM_ACTIVE_CONNECTION_STATE_UNKNOWN; if (priv->state != NM_ACTIVE_CONNECTION_STATE_ACTIVATING) { - nm_log_dbg (LOGD_DEVICE, "(%p): not signalling master-ready (not activating)", self); + _LOGD ("not signalling master-ready (not activating)"); return; } if (!priv->master) { - nm_log_dbg (LOGD_DEVICE, "(%p): not signalling master-ready (no master)", self); + _LOGD ("not signalling master-ready (no master)"); return; } if (priv->master_ready) { - nm_log_dbg (LOGD_DEVICE, "(%p): not signalling master-ready (already signaled)", self); + _LOGD ("not signalling master-ready (already signaled)"); return; } @@ -546,12 +546,12 @@ check_master_ready (NMActiveConnection *self) * or higher states. */ master_state = nm_active_connection_get_state (priv->master); - nm_log_dbg (LOGD_DEVICE, "(%p): master ActiveConnection [%p] state now '%s' (%d)", - self, priv->master, state_to_string (master_state), master_state); + _LOGD ("master ActiveConnection [%p] state now '%s' (%d)", + priv->master, state_to_string (master_state), master_state); if ( master_state == NM_ACTIVE_CONNECTION_STATE_ACTIVATING || master_state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { - nm_log_dbg (LOGD_DEVICE, "(%p): signalling master-ready", self); + _LOGD ("signalling master-ready"); priv->master_ready = TRUE; g_object_notify (G_OBJECT (self), NM_ACTIVE_CONNECTION_INT_MASTER_READY); @@ -575,8 +575,8 @@ master_state_cb (NMActiveConnection *master, check_master_ready (self); - nm_log_dbg (LOGD_DEVICE, "(%p): master ActiveConnection [%p] state now '%s' (%d)", - self, master, state_to_string (master_state), master_state); + _LOGD ("master ActiveConnection [%p] state now '%s' (%d)", + master, state_to_string (master_state), master_state); if ( master_state >= NM_ACTIVE_CONNECTION_STATE_DEACTIVATING && !priv->master_ready) { @@ -613,8 +613,8 @@ nm_active_connection_set_master (NMActiveConnection *self, NMActiveConnection *m g_return_if_fail (priv->device != nm_active_connection_get_device (master)); } - nm_log_dbg (LOGD_DEVICE, "(%p): master ActiveConnection is [%p] %s", - self, master, nm_active_connection_get_id (master)); + _LOGD ("master ActiveConnection is [%p] %s", + master, nm_active_connection_get_id (master)); priv->master = g_object_ref (master); g_signal_connect (priv->master, From 1b3bb295c53804543ce615ef1ce2e7813978cf9f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 3 Jul 2015 11:41:15 +0200 Subject: [PATCH 3/9] settings/trivial: consistently name @self argument in NMSettingsConnection (cherry picked from commit 0a160116d7a569573a44875325edf61c250467e7) --- src/settings/nm-settings-connection.c | 250 +++++++++++++------------- src/settings/nm-settings-connection.h | 68 +++---- 2 files changed, 159 insertions(+), 159 deletions(-) diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index 0f67a21629..9ffaf36a65 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -42,28 +42,28 @@ #define SETTINGS_TIMESTAMPS_FILE NMSTATEDIR "/timestamps" #define SETTINGS_SEEN_BSSIDS_FILE NMSTATEDIR "/seen-bssids" -static void impl_settings_connection_get_settings (NMSettingsConnection *connection, +static void impl_settings_connection_get_settings (NMSettingsConnection *self, DBusGMethodInvocation *context); -static void impl_settings_connection_update (NMSettingsConnection *connection, +static void impl_settings_connection_update (NMSettingsConnection *self, GHashTable *new_settings, DBusGMethodInvocation *context); -static void impl_settings_connection_update_unsaved (NMSettingsConnection *connection, +static void impl_settings_connection_update_unsaved (NMSettingsConnection *self, GHashTable *new_settings, DBusGMethodInvocation *context); -static void impl_settings_connection_save (NMSettingsConnection *connection, +static void impl_settings_connection_save (NMSettingsConnection *self, DBusGMethodInvocation *context); -static void impl_settings_connection_delete (NMSettingsConnection *connection, +static void impl_settings_connection_delete (NMSettingsConnection *self, DBusGMethodInvocation *context); -static void impl_settings_connection_get_secrets (NMSettingsConnection *connection, +static void impl_settings_connection_get_secrets (NMSettingsConnection *self, const gchar *setting_name, DBusGMethodInvocation *context); -static void impl_settings_connection_clear_secrets (NMSettingsConnection *connection, +static void impl_settings_connection_clear_secrets (NMSettingsConnection *self, DBusGMethodInvocation *context); #include "nm-settings-connection-glue.h" @@ -146,7 +146,7 @@ typedef gboolean (*ForEachSecretFunc) (GHashTableIter *iter, gpointer user_data); static void -for_each_secret (NMConnection *connection, +for_each_secret (NMConnection *self, GHashTable *secrets, gboolean remove_non_secrets, ForEachSecretFunc callback, @@ -189,7 +189,7 @@ for_each_secret (NMConnection *connection, * from the connection data, since flags aren't secrets. What we're * iterating here is just the secrets, not a whole connection. */ - setting = nm_connection_get_setting_by_name (connection, setting_name); + setting = nm_connection_get_setting_by_name (self, setting_name); if (setting == NULL) continue; @@ -526,7 +526,7 @@ nm_settings_connection_replace_settings (NMSettingsConnection *self, } static void -ignore_cb (NMSettingsConnection *connection, +ignore_cb (NMSettingsConnection *self, GError *error, gpointer user_data) { @@ -583,49 +583,49 @@ commit_changes (NMSettingsConnection *self, } void -nm_settings_connection_commit_changes (NMSettingsConnection *connection, +nm_settings_connection_commit_changes (NMSettingsConnection *self, NMSettingsConnectionCommitFunc callback, gpointer user_data) { - g_return_if_fail (NM_IS_SETTINGS_CONNECTION (connection)); + g_return_if_fail (NM_IS_SETTINGS_CONNECTION (self)); - if (NM_SETTINGS_CONNECTION_GET_CLASS (connection)->commit_changes) { - NM_SETTINGS_CONNECTION_GET_CLASS (connection)->commit_changes (connection, - callback ? callback : ignore_cb, - user_data); + if (NM_SETTINGS_CONNECTION_GET_CLASS (self)->commit_changes) { + NM_SETTINGS_CONNECTION_GET_CLASS (self)->commit_changes (self, + callback ? callback : ignore_cb, + user_data); } else { GError *error = g_error_new (NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "%s: %s:%d commit_changes() unimplemented", __func__, __FILE__, __LINE__); if (callback) - callback (connection, error, user_data); + callback (self, error, user_data); g_error_free (error); } } void -nm_settings_connection_delete (NMSettingsConnection *connection, +nm_settings_connection_delete (NMSettingsConnection *self, NMSettingsConnectionDeleteFunc callback, gpointer user_data) { - g_return_if_fail (NM_IS_SETTINGS_CONNECTION (connection)); + g_return_if_fail (NM_IS_SETTINGS_CONNECTION (self)); - if (NM_SETTINGS_CONNECTION_GET_CLASS (connection)->delete) { - NM_SETTINGS_CONNECTION_GET_CLASS (connection)->delete (connection, - callback ? callback : ignore_cb, - user_data); + if (NM_SETTINGS_CONNECTION_GET_CLASS (self)->delete) { + NM_SETTINGS_CONNECTION_GET_CLASS (self)->delete (self, + callback ? callback : ignore_cb, + user_data); } else { GError *error = g_error_new (NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "%s: %s:%d delete() unimplemented", __func__, __FILE__, __LINE__); if (callback) - callback (connection, error, user_data); + callback (self, error, user_data); g_error_free (error); } } static void -remove_entry_from_db (NMSettingsConnection *connection, const char* db_name) +remove_entry_from_db (NMSettingsConnection *self, const char* db_name) { GKeyFile *key_file; const char *db_file; @@ -644,7 +644,7 @@ remove_entry_from_db (NMSettingsConnection *connection, const char* db_name) gsize len; GError *error = NULL; - connection_uuid = nm_connection_get_uuid (NM_CONNECTION (connection)); + connection_uuid = nm_connection_get_uuid (NM_CONNECTION (self)); g_key_file_remove_key (key_file, db_name, connection_uuid, NULL); data = g_key_file_to_data (key_file, &len, &error); @@ -661,39 +661,39 @@ remove_entry_from_db (NMSettingsConnection *connection, const char* db_name) } static void -do_delete (NMSettingsConnection *connection, +do_delete (NMSettingsConnection *self, NMSettingsConnectionDeleteFunc callback, gpointer user_data) { - NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (connection); + NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); NMConnection *for_agents; - g_object_ref (connection); - set_visible (connection, FALSE); + g_object_ref (self); + set_visible (self, FALSE); /* Tell agents to remove secrets for this connection */ - for_agents = nm_simple_connection_new_clone (NM_CONNECTION (connection)); + for_agents = nm_simple_connection_new_clone (NM_CONNECTION (self)); nm_connection_clear_secrets (for_agents); nm_agent_manager_delete_secrets (priv->agent_mgr, for_agents); g_object_unref (for_agents); /* Remove timestamp from timestamps database file */ - remove_entry_from_db (connection, "timestamps"); + remove_entry_from_db (self, "timestamps"); /* Remove connection from seen-bssids database file */ - remove_entry_from_db (connection, "seen-bssids"); + remove_entry_from_db (self, "seen-bssids"); - nm_settings_connection_signal_remove (connection); + nm_settings_connection_signal_remove (self); - callback (connection, NULL, user_data); + callback (self, NULL, user_data); - g_object_unref (connection); + g_object_unref (self); } /**************************************************************/ static gboolean -supports_secrets (NMSettingsConnection *connection, const char *setting_name) +supports_secrets (NMSettingsConnection *self, const char *setting_name) { /* All secrets supported */ return TRUE; @@ -734,7 +734,7 @@ has_system_owned_secrets (GHashTableIter *iter, } static void -new_secrets_commit_cb (NMSettingsConnection *connection, +new_secrets_commit_cb (NMSettingsConnection *self, GError *error, gpointer user_data) { @@ -907,7 +907,7 @@ agent_secrets_done_cb (NMAgentManager *manager, /** * nm_settings_connection_get_secrets: - * @connection: the #NMSettingsConnection + * @self: the #NMSettingsConnection * @subject: the #NMAuthSubject originating the request * @setting_name: the setting to return secrets for * @flags: flags to modify the secrets request @@ -1004,7 +1004,7 @@ nm_settings_connection_cancel_secrets (NMSettingsConnection *self, /**** User authorization **************************************/ -typedef void (*AuthCallback) (NMSettingsConnection *connection, +typedef void (*AuthCallback) (NMSettingsConnection *self, DBusGMethodInvocation *context, NMAuthSubject *subject, GError *error, @@ -1136,13 +1136,13 @@ auth_start (NMSettingsConnection *self, /**** DBus method handlers ************************************/ static gboolean -check_writable (NMConnection *connection, GError **error) +check_writable (NMConnection *self, GError **error) { NMSettingConnection *s_con; - g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE); + g_return_val_if_fail (NM_IS_CONNECTION (self), FALSE); - s_con = nm_connection_get_setting_connection (connection); + s_con = nm_connection_get_setting_connection (self); if (!s_con) { g_set_error_literal (error, NM_SETTINGS_ERROR, @@ -1272,11 +1272,11 @@ has_some_secrets_cb (NMSetting *setting, } static gboolean -any_secrets_present (NMConnection *connection) +any_secrets_present (NMConnection *self) { gboolean has_secrets = FALSE; - nm_connection_for_each_setting_value (connection, has_some_secrets_cb, &has_secrets); + nm_connection_for_each_setting_value (self, has_some_secrets_cb, &has_secrets); return has_secrets; } @@ -1515,7 +1515,7 @@ impl_settings_connection_save (NMSettingsConnection *self, } static void -con_delete_cb (NMSettingsConnection *connection, +con_delete_cb (NMSettingsConnection *self, GError *error, gpointer user_data) { @@ -1528,7 +1528,7 @@ con_delete_cb (NMSettingsConnection *connection, } static void -delete_auth_cb (NMSettingsConnection *self, +delete_auth_cb (NMSettingsConnection *self, DBusGMethodInvocation *context, NMAuthSubject *subject, GError *error, @@ -1543,7 +1543,7 @@ delete_auth_cb (NMSettingsConnection *self, } static const char * -get_modify_permission_basic (NMSettingsConnection *connection) +get_modify_permission_basic (NMSettingsConnection *self) { NMSettingConnection *s_con; @@ -1551,7 +1551,7 @@ get_modify_permission_basic (NMSettingsConnection *connection) * we use the 'modify.own' permission instead of 'modify.system'. If the * request affects more than just the caller, require 'modify.system'. */ - s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection)); + s_con = nm_connection_get_setting_connection (NM_CONNECTION (self)); g_assert (s_con); if (nm_setting_connection_get_num_permissions (s_con) == 1) return NM_AUTH_PERMISSION_SETTINGS_MODIFY_OWN; @@ -1692,7 +1692,7 @@ clear_secrets_cb (NMSettingsConnection *self, } static void -dbus_clear_secrets_auth_cb (NMSettingsConnection *self, +dbus_clear_secrets_auth_cb (NMSettingsConnection *self, DBusGMethodInvocation *context, NMAuthSubject *subject, GError *error, @@ -1815,7 +1815,7 @@ nm_settings_connection_set_flags_all (NMSettingsConnection *self, NMSettingsConn /** * nm_settings_connection_get_timestamp: - * @connection: the #NMSettingsConnection + * @self: the #NMSettingsConnection * @out_timestamp: the connection's timestamp * * Returns the time (in seconds since the Unix epoch) when the connection @@ -1824,19 +1824,19 @@ nm_settings_connection_set_flags_all (NMSettingsConnection *self, NMSettingsConn * Returns: %TRUE if the timestamp has ever been set, otherwise %FALSE. **/ gboolean -nm_settings_connection_get_timestamp (NMSettingsConnection *connection, +nm_settings_connection_get_timestamp (NMSettingsConnection *self, guint64 *out_timestamp) { - g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (connection), FALSE); + g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (self), FALSE); if (out_timestamp) - *out_timestamp = NM_SETTINGS_CONNECTION_GET_PRIVATE (connection)->timestamp; - return NM_SETTINGS_CONNECTION_GET_PRIVATE (connection)->timestamp_set; + *out_timestamp = NM_SETTINGS_CONNECTION_GET_PRIVATE (self)->timestamp; + return NM_SETTINGS_CONNECTION_GET_PRIVATE (self)->timestamp_set; } /** * nm_settings_connection_update_timestamp: - * @connection: the #NMSettingsConnection + * @self: the #NMSettingsConnection * @timestamp: timestamp to set into the connection and to store into * the timestamps database * @flush_to_disk: if %TRUE, commit timestamp update to persistent storage @@ -1844,18 +1844,18 @@ nm_settings_connection_get_timestamp (NMSettingsConnection *connection, * Updates the connection and timestamps database with the provided timestamp. **/ void -nm_settings_connection_update_timestamp (NMSettingsConnection *connection, +nm_settings_connection_update_timestamp (NMSettingsConnection *self, guint64 timestamp, gboolean flush_to_disk) { - NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (connection); + NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); const char *connection_uuid; GKeyFile *timestamps_file; char *data, *tmp; gsize len; GError *error = NULL; - g_return_if_fail (NM_IS_SETTINGS_CONNECTION (connection)); + g_return_if_fail (NM_IS_SETTINGS_CONNECTION (self)); /* Update timestamp in private storage */ priv->timestamp = timestamp; @@ -1872,7 +1872,7 @@ nm_settings_connection_update_timestamp (NMSettingsConnection *connection, g_clear_error (&error); } - connection_uuid = nm_connection_get_uuid (NM_CONNECTION (connection)); + connection_uuid = nm_connection_get_uuid (NM_CONNECTION (self)); tmp = g_strdup_printf ("%" G_GUINT64_FORMAT, timestamp); g_key_file_set_value (timestamps_file, "timestamps", connection_uuid, tmp); g_free (tmp); @@ -1891,27 +1891,27 @@ nm_settings_connection_update_timestamp (NMSettingsConnection *connection, /** * nm_settings_connection_read_and_fill_timestamp: - * @connection: the #NMSettingsConnection + * @self: the #NMSettingsConnection * * Retrieves timestamp of the connection's last usage from database file and * stores it into the connection private data. **/ void -nm_settings_connection_read_and_fill_timestamp (NMSettingsConnection *connection) +nm_settings_connection_read_and_fill_timestamp (NMSettingsConnection *self) { - NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (connection); + NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); const char *connection_uuid; guint64 timestamp = 0; GKeyFile *timestamps_file; GError *err = NULL; char *tmp_str; - g_return_if_fail (NM_IS_SETTINGS_CONNECTION (connection)); + g_return_if_fail (NM_IS_SETTINGS_CONNECTION (self)); /* Get timestamp from database file */ timestamps_file = g_key_file_new (); g_key_file_load_from_file (timestamps_file, SETTINGS_TIMESTAMPS_FILE, G_KEY_FILE_KEEP_COMMENTS, NULL); - connection_uuid = nm_connection_get_uuid (NM_CONNECTION (connection)); + connection_uuid = nm_connection_get_uuid (NM_CONNECTION (self)); tmp_str = g_key_file_get_value (timestamps_file, "timestamps", connection_uuid, &err); if (tmp_str) { timestamp = g_ascii_strtoull (tmp_str, NULL, 10); @@ -1932,7 +1932,7 @@ nm_settings_connection_read_and_fill_timestamp (NMSettingsConnection *connection /** * nm_settings_connection_get_seen_bssids: - * @connection: the #NMSettingsConnection + * @self: the #NMSettingsConnection * * Returns current list of seen BSSIDs for the connection. * @@ -1940,14 +1940,14 @@ nm_settings_connection_read_and_fill_timestamp (NMSettingsConnection *connection * The caller is responsible for freeing the list, but not the content. **/ char ** -nm_settings_connection_get_seen_bssids (NMSettingsConnection *connection) +nm_settings_connection_get_seen_bssids (NMSettingsConnection *self) { - NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (connection); + NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); GHashTableIter iter; char **bssids, *bssid; int i; - g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (connection), NULL); + g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (self), NULL); bssids = g_new (char *, g_hash_table_size (priv->seen_bssids) + 1); @@ -1962,34 +1962,34 @@ nm_settings_connection_get_seen_bssids (NMSettingsConnection *connection) /** * nm_settings_connection_has_seen_bssid: - * @connection: the #NMSettingsConnection + * @self: the #NMSettingsConnection * @bssid: the BSSID to check the seen BSSID list for * * Returns: %TRUE if the given @bssid is in the seen BSSIDs list **/ gboolean -nm_settings_connection_has_seen_bssid (NMSettingsConnection *connection, +nm_settings_connection_has_seen_bssid (NMSettingsConnection *self, const char *bssid) { - g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (connection), FALSE); + g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (self), FALSE); g_return_val_if_fail (bssid != NULL, FALSE); - return !!g_hash_table_lookup (NM_SETTINGS_CONNECTION_GET_PRIVATE (connection)->seen_bssids, bssid); + return !!g_hash_table_lookup (NM_SETTINGS_CONNECTION_GET_PRIVATE (self)->seen_bssids, bssid); } /** * nm_settings_connection_add_seen_bssid: - * @connection: the #NMSettingsConnection + * @self: the #NMSettingsConnection * @seen_bssid: BSSID to set into the connection and to store into * the seen-bssids database * * Updates the connection and seen-bssids database with the provided BSSID. **/ void -nm_settings_connection_add_seen_bssid (NMSettingsConnection *connection, +nm_settings_connection_add_seen_bssid (NMSettingsConnection *self, const char *seen_bssid) { - NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (connection); + NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); const char *connection_uuid; GKeyFile *seen_bssids_file; char *data, *bssid_str; @@ -2026,7 +2026,7 @@ nm_settings_connection_add_seen_bssid (NMSettingsConnection *connection, g_clear_error (&error); } - connection_uuid = nm_connection_get_uuid (NM_CONNECTION (connection)); + connection_uuid = nm_connection_get_uuid (NM_CONNECTION (self)); g_key_file_set_string_list (seen_bssids_file, "seen-bssids", connection_uuid, list, n); g_free (list); @@ -2046,15 +2046,15 @@ nm_settings_connection_add_seen_bssid (NMSettingsConnection *connection, /** * nm_settings_connection_read_and_fill_seen_bssids: - * @connection: the #NMSettingsConnection + * @self: the #NMSettingsConnection * * Retrieves seen BSSIDs of the connection from database file and stores then into the * connection private data. **/ void -nm_settings_connection_read_and_fill_seen_bssids (NMSettingsConnection *connection) +nm_settings_connection_read_and_fill_seen_bssids (NMSettingsConnection *self) { - NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (connection); + NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); const char *connection_uuid; GKeyFile *seen_bssids_file; char **tmp_strv = NULL; @@ -2065,7 +2065,7 @@ nm_settings_connection_read_and_fill_seen_bssids (NMSettingsConnection *connecti seen_bssids_file = g_key_file_new (); g_key_file_set_list_separator (seen_bssids_file, ','); if (g_key_file_load_from_file (seen_bssids_file, SETTINGS_SEEN_BSSIDS_FILE, G_KEY_FILE_KEEP_COMMENTS, NULL)) { - connection_uuid = nm_connection_get_uuid (NM_CONNECTION (connection)); + connection_uuid = nm_connection_get_uuid (NM_CONNECTION (self)); tmp_strv = g_key_file_get_string_list (seen_bssids_file, "seen-bssids", connection_uuid, &len, NULL); } g_key_file_free (seen_bssids_file); @@ -2082,7 +2082,7 @@ nm_settings_connection_read_and_fill_seen_bssids (NMSettingsConnection *connecti * seen-bssids list from the deprecated seen-bssids property of the * wifi setting. */ - s_wifi = nm_connection_get_setting_wireless (NM_CONNECTION (connection)); + s_wifi = nm_connection_get_setting_wireless (NM_CONNECTION (self)); if (s_wifi) { len = nm_setting_wireless_get_num_seen_bssids (s_wifi); for (i = 0; i < len; i++) { @@ -2098,16 +2098,16 @@ nm_settings_connection_read_and_fill_seen_bssids (NMSettingsConnection *connecti #define AUTOCONNECT_RESET_RETRIES_TIMER 300 int -nm_settings_connection_get_autoconnect_retries (NMSettingsConnection *connection) +nm_settings_connection_get_autoconnect_retries (NMSettingsConnection *self) { - return NM_SETTINGS_CONNECTION_GET_PRIVATE (connection)->autoconnect_retries; + return NM_SETTINGS_CONNECTION_GET_PRIVATE (self)->autoconnect_retries; } void -nm_settings_connection_set_autoconnect_retries (NMSettingsConnection *connection, +nm_settings_connection_set_autoconnect_retries (NMSettingsConnection *self, int retries) { - NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (connection); + NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); priv->autoconnect_retries = retries; if (retries) @@ -2117,34 +2117,34 @@ nm_settings_connection_set_autoconnect_retries (NMSettingsConnection *connection } void -nm_settings_connection_reset_autoconnect_retries (NMSettingsConnection *connection) +nm_settings_connection_reset_autoconnect_retries (NMSettingsConnection *self) { - nm_settings_connection_set_autoconnect_retries (connection, AUTOCONNECT_RETRIES_DEFAULT); + nm_settings_connection_set_autoconnect_retries (self, AUTOCONNECT_RETRIES_DEFAULT); } gint32 -nm_settings_connection_get_autoconnect_retry_time (NMSettingsConnection *connection) +nm_settings_connection_get_autoconnect_retry_time (NMSettingsConnection *self) { - return NM_SETTINGS_CONNECTION_GET_PRIVATE (connection)->autoconnect_retry_time; + return NM_SETTINGS_CONNECTION_GET_PRIVATE (self)->autoconnect_retry_time; } NMDeviceStateReason -nm_settings_connection_get_autoconnect_blocked_reason (NMSettingsConnection *connection) +nm_settings_connection_get_autoconnect_blocked_reason (NMSettingsConnection *self) { - return NM_SETTINGS_CONNECTION_GET_PRIVATE (connection)->autoconnect_blocked_reason; + return NM_SETTINGS_CONNECTION_GET_PRIVATE (self)->autoconnect_blocked_reason; } void -nm_settings_connection_set_autoconnect_blocked_reason (NMSettingsConnection *connection, +nm_settings_connection_set_autoconnect_blocked_reason (NMSettingsConnection *self, NMDeviceStateReason reason) { - NM_SETTINGS_CONNECTION_GET_PRIVATE (connection)->autoconnect_blocked_reason = reason; + NM_SETTINGS_CONNECTION_GET_PRIVATE (self)->autoconnect_blocked_reason = reason; } gboolean -nm_settings_connection_can_autoconnect (NMSettingsConnection *connection) +nm_settings_connection_can_autoconnect (NMSettingsConnection *self) { - NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (connection); + NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); NMSettingConnection *s_con; const char *permission; @@ -2153,13 +2153,13 @@ nm_settings_connection_can_autoconnect (NMSettingsConnection *connection) || priv->autoconnect_blocked_reason != NM_DEVICE_STATE_REASON_NONE) return FALSE; - s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection)); + s_con = nm_connection_get_setting_connection (NM_CONNECTION (self)); if (!nm_setting_connection_get_autoconnect (s_con)) return FALSE; - permission = nm_utils_get_shared_wifi_permission (NM_CONNECTION (connection)); + permission = nm_utils_get_shared_wifi_permission (NM_CONNECTION (self)); if (permission) { - if (nm_settings_connection_check_permission (connection, permission) == FALSE) + if (nm_settings_connection_check_permission (self, permission) == FALSE) return FALSE; } @@ -2168,89 +2168,89 @@ nm_settings_connection_can_autoconnect (NMSettingsConnection *connection) /** * nm_settings_connection_get_nm_generated: - * @connection: an #NMSettingsConnection + * @self: an #NMSettingsConnection * - * Gets the "nm-generated" flag on @connection. + * Gets the "nm-generated" flag on @self. * * A connection is "nm-generated" if it was generated by * nm_device_generate_connection() and has not been modified or * saved by the user since then. */ gboolean -nm_settings_connection_get_nm_generated (NMSettingsConnection *connection) +nm_settings_connection_get_nm_generated (NMSettingsConnection *self) { - return NM_FLAGS_HAS (nm_settings_connection_get_flags (connection), NM_SETTINGS_CONNECTION_FLAGS_NM_GENERATED); + return NM_FLAGS_HAS (nm_settings_connection_get_flags (self), NM_SETTINGS_CONNECTION_FLAGS_NM_GENERATED); } /** * nm_settings_connection_get_nm_generated_assumed: - * @connection: an #NMSettingsConnection + * @self: an #NMSettingsConnection * - * Gets the "nm-generated-assumed" flag on @connection. + * Gets the "nm-generated-assumed" flag on @self. * * The connection is a generated connection especially * generated for connection assumption. */ gboolean -nm_settings_connection_get_nm_generated_assumed (NMSettingsConnection *connection) +nm_settings_connection_get_nm_generated_assumed (NMSettingsConnection *self) { - return NM_FLAGS_HAS (nm_settings_connection_get_flags (connection), NM_SETTINGS_CONNECTION_FLAGS_NM_GENERATED_ASSUMED); + return NM_FLAGS_HAS (nm_settings_connection_get_flags (self), NM_SETTINGS_CONNECTION_FLAGS_NM_GENERATED_ASSUMED); } gboolean -nm_settings_connection_get_ready (NMSettingsConnection *connection) +nm_settings_connection_get_ready (NMSettingsConnection *self) { - return NM_SETTINGS_CONNECTION_GET_PRIVATE (connection)->ready; + return NM_SETTINGS_CONNECTION_GET_PRIVATE (self)->ready; } void -nm_settings_connection_set_ready (NMSettingsConnection *connection, +nm_settings_connection_set_ready (NMSettingsConnection *self, gboolean ready) { - NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (connection); + NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); ready = !!ready; if (priv->ready != ready) { priv->ready = ready; - g_object_notify (G_OBJECT (connection), NM_SETTINGS_CONNECTION_READY); + g_object_notify (G_OBJECT (self), NM_SETTINGS_CONNECTION_READY); } } /** * nm_settings_connection_set_filename: - * @connection: an #NMSettingsConnection - * @filename: @connection's filename + * @self: an #NMSettingsConnection + * @filename: @self's filename * - * Called by a backend to sets the filename that @connection is read + * Called by a backend to sets the filename that @self is read * from/written to. */ void -nm_settings_connection_set_filename (NMSettingsConnection *connection, +nm_settings_connection_set_filename (NMSettingsConnection *self, const char *filename) { - NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (connection); + NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); if (g_strcmp0 (filename, priv->filename) != 0) { g_free (priv->filename); priv->filename = g_strdup (filename); - g_object_notify (G_OBJECT (connection), NM_SETTINGS_CONNECTION_FILENAME); + g_object_notify (G_OBJECT (self), NM_SETTINGS_CONNECTION_FILENAME); } } /** * nm_settings_connection_get_filename: - * @connection: an #NMSettingsConnection + * @self: an #NMSettingsConnection * - * Gets the filename that @connection was read from/written to. This may be - * %NULL if @connection is unsaved, or if it is associated with a backend that + * Gets the filename that @self was read from/written to. This may be + * %NULL if @self is unsaved, or if it is associated with a backend that * does not store each connection in a separate file. * - * Returns: @connection's filename. + * Returns: @self's filename. */ const char * -nm_settings_connection_get_filename (NMSettingsConnection *connection) +nm_settings_connection_get_filename (NMSettingsConnection *self) { - NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (connection); + NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); return priv->filename; } @@ -2439,7 +2439,7 @@ nm_settings_connection_class_init (NMSettingsConnectionClass *class) /* Signals */ /* Emitted when the connection is changed for any reason */ - signals[UPDATED] = + signals[UPDATED] = g_signal_new (NM_SETTINGS_CONNECTION_UPDATED, G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_FIRST, diff --git a/src/settings/nm-settings-connection.h b/src/settings/nm-settings-connection.h index 49661f38c6..512112f032 100644 --- a/src/settings/nm-settings-connection.h +++ b/src/settings/nm-settings-connection.h @@ -81,11 +81,11 @@ typedef enum typedef struct _NMSettingsConnectionClass NMSettingsConnectionClass; -typedef void (*NMSettingsConnectionCommitFunc) (NMSettingsConnection *connection, +typedef void (*NMSettingsConnectionCommitFunc) (NMSettingsConnection *self, GError *error, gpointer user_data); -typedef void (*NMSettingsConnectionDeleteFunc) (NMSettingsConnection *connection, +typedef void (*NMSettingsConnectionDeleteFunc) (NMSettingsConnection *self, GError *error, gpointer user_data); @@ -97,26 +97,26 @@ struct _NMSettingsConnectionClass { GObjectClass parent; /* virtual methods */ - void (*replace_and_commit) (NMSettingsConnection *connection, + void (*replace_and_commit) (NMSettingsConnection *self, NMConnection *new_connection, NMSettingsConnectionCommitFunc callback, gpointer user_data); - void (*commit_changes) (NMSettingsConnection *connection, + void (*commit_changes) (NMSettingsConnection *self, NMSettingsConnectionCommitFunc callback, gpointer user_data); - void (*delete) (NMSettingsConnection *connection, + void (*delete) (NMSettingsConnection *self, NMSettingsConnectionDeleteFunc callback, gpointer user_data); - gboolean (*supports_secrets) (NMSettingsConnection *connection, + gboolean (*supports_secrets) (NMSettingsConnection *self, const char *setting_name); }; GType nm_settings_connection_get_type (void); -void nm_settings_connection_commit_changes (NMSettingsConnection *connection, +void nm_settings_connection_commit_changes (NMSettingsConnection *self, NMSettingsConnectionCommitFunc callback, gpointer user_data); @@ -131,18 +131,18 @@ void nm_settings_connection_replace_and_commit (NMSettingsConnection *self, NMSettingsConnectionCommitFunc callback, gpointer user_data); -void nm_settings_connection_delete (NMSettingsConnection *connection, +void nm_settings_connection_delete (NMSettingsConnection *self, NMSettingsConnectionDeleteFunc callback, gpointer user_data); -typedef void (*NMSettingsConnectionSecretsFunc) (NMSettingsConnection *connection, +typedef void (*NMSettingsConnectionSecretsFunc) (NMSettingsConnection *self, guint32 call_id, const char *agent_username, const char *setting_name, GError *error, gpointer user_data); -guint32 nm_settings_connection_get_secrets (NMSettingsConnection *connection, +guint32 nm_settings_connection_get_secrets (NMSettingsConnection *self, NMAuthSubject *subject, const char *setting_name, NMSecretAgentGetSecretsFlags flags, @@ -151,7 +151,7 @@ guint32 nm_settings_connection_get_secrets (NMSettingsConnection *connection, gpointer callback_data, GError **error); -void nm_settings_connection_cancel_secrets (NMSettingsConnection *connection, +void nm_settings_connection_cancel_secrets (NMSettingsConnection *self, guint32 call_id); gboolean nm_settings_connection_is_visible (NMSettingsConnection *self); @@ -165,52 +165,52 @@ void nm_settings_connection_signal_remove (NMSettingsConnection *self); gboolean nm_settings_connection_get_unsaved (NMSettingsConnection *self); -NMSettingsConnectionFlags nm_settings_connection_get_flags (NMSettingsConnection *connection); -NMSettingsConnectionFlags nm_settings_connection_set_flags (NMSettingsConnection *connection, NMSettingsConnectionFlags flags, gboolean set); -NMSettingsConnectionFlags nm_settings_connection_set_flags_all (NMSettingsConnection *connection, NMSettingsConnectionFlags flags); +NMSettingsConnectionFlags nm_settings_connection_get_flags (NMSettingsConnection *self); +NMSettingsConnectionFlags nm_settings_connection_set_flags (NMSettingsConnection *self, NMSettingsConnectionFlags flags, gboolean set); +NMSettingsConnectionFlags nm_settings_connection_set_flags_all (NMSettingsConnection *self, NMSettingsConnectionFlags flags); -gboolean nm_settings_connection_get_timestamp (NMSettingsConnection *connection, +gboolean nm_settings_connection_get_timestamp (NMSettingsConnection *self, guint64 *out_timestamp); -void nm_settings_connection_update_timestamp (NMSettingsConnection *connection, +void nm_settings_connection_update_timestamp (NMSettingsConnection *self, guint64 timestamp, gboolean flush_to_disk); -void nm_settings_connection_read_and_fill_timestamp (NMSettingsConnection *connection); +void nm_settings_connection_read_and_fill_timestamp (NMSettingsConnection *self); -char **nm_settings_connection_get_seen_bssids (NMSettingsConnection *connection); +char **nm_settings_connection_get_seen_bssids (NMSettingsConnection *self); -gboolean nm_settings_connection_has_seen_bssid (NMSettingsConnection *connection, +gboolean nm_settings_connection_has_seen_bssid (NMSettingsConnection *self, const char *bssid); -void nm_settings_connection_add_seen_bssid (NMSettingsConnection *connection, +void nm_settings_connection_add_seen_bssid (NMSettingsConnection *self, const char *seen_bssid); -void nm_settings_connection_read_and_fill_seen_bssids (NMSettingsConnection *connection); +void nm_settings_connection_read_and_fill_seen_bssids (NMSettingsConnection *self); -int nm_settings_connection_get_autoconnect_retries (NMSettingsConnection *connection); -void nm_settings_connection_set_autoconnect_retries (NMSettingsConnection *connection, +int nm_settings_connection_get_autoconnect_retries (NMSettingsConnection *self); +void nm_settings_connection_set_autoconnect_retries (NMSettingsConnection *self, int retries); -void nm_settings_connection_reset_autoconnect_retries (NMSettingsConnection *connection); +void nm_settings_connection_reset_autoconnect_retries (NMSettingsConnection *self); -gint32 nm_settings_connection_get_autoconnect_retry_time (NMSettingsConnection *connection); +gint32 nm_settings_connection_get_autoconnect_retry_time (NMSettingsConnection *self); -NMDeviceStateReason nm_settings_connection_get_autoconnect_blocked_reason (NMSettingsConnection *connection); -void nm_settings_connection_set_autoconnect_blocked_reason (NMSettingsConnection *connection, +NMDeviceStateReason nm_settings_connection_get_autoconnect_blocked_reason (NMSettingsConnection *self); +void nm_settings_connection_set_autoconnect_blocked_reason (NMSettingsConnection *self, NMDeviceStateReason reason); -gboolean nm_settings_connection_can_autoconnect (NMSettingsConnection *connection); +gboolean nm_settings_connection_can_autoconnect (NMSettingsConnection *self); -gboolean nm_settings_connection_get_nm_generated (NMSettingsConnection *connection); -gboolean nm_settings_connection_get_nm_generated_assumed (NMSettingsConnection *connection); +gboolean nm_settings_connection_get_nm_generated (NMSettingsConnection *self); +gboolean nm_settings_connection_get_nm_generated_assumed (NMSettingsConnection *self); -gboolean nm_settings_connection_get_ready (NMSettingsConnection *connection); -void nm_settings_connection_set_ready (NMSettingsConnection *connection, +gboolean nm_settings_connection_get_ready (NMSettingsConnection *self); +void nm_settings_connection_set_ready (NMSettingsConnection *self, gboolean ready); -void nm_settings_connection_set_filename (NMSettingsConnection *connection, +void nm_settings_connection_set_filename (NMSettingsConnection *self, const char *filename); -const char *nm_settings_connection_get_filename (NMSettingsConnection *connection); +const char *nm_settings_connection_get_filename (NMSettingsConnection *self); G_END_DECLS From 494b52a832db25802e12e700491bf7d321156c9c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 3 Jul 2015 11:47:53 +0200 Subject: [PATCH 4/9] settings: add _LOG() macros to "nm-settings-connection.h" (cherry picked from commit 5fb56a1df965ae2b22c4404904f8b73fea12102b) --- src/settings/nm-settings-connection.c | 42 +++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index 9ffaf36a65..5ecf3c707b 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -42,6 +42,48 @@ #define SETTINGS_TIMESTAMPS_FILE NMSTATEDIR "/timestamps" #define SETTINGS_SEEN_BSSIDS_FILE NMSTATEDIR "/seen-bssids" + +#define _LOG_DOMAIN LOGD_SETTINGS +#define _LOG_PREFIX_NAME "settings-connection" + +#define _LOG(level, domain, self, ...) \ + G_STMT_START { \ + const NMLogLevel __level = (level); \ + const NMLogDomain __domain = (domain); \ + \ + if (nm_logging_enabled (__level, __domain)) { \ + char __prefix[128]; \ + const char *__p_prefix = _LOG_PREFIX_NAME; \ + const void *const __self = (self); \ + \ + if (__self) { \ + const char *__uuid = nm_connection_get_uuid ((NMConnection *) __self); \ + \ + g_snprintf (__prefix, sizeof (__prefix), "%s[%p%s%s]", _LOG_PREFIX_NAME, __self, __uuid ? "," : "", __uuid ? __uuid : ""); \ + __p_prefix = __prefix; \ + } \ + _nm_log (__level, __domain, 0, \ + "%s: " _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \ + __p_prefix _NM_UTILS_MACRO_REST (__VA_ARGS__)); \ + } \ + } G_STMT_END +#define _LOG_LEVEL_ENABLED(level, domain) \ + ( nm_logging_enabled ((level), (domain)) ) + +#ifdef NM_MORE_LOGGING +#define _LOGT_ENABLED() _LOG_LEVEL_ENABLED (LOGL_TRACE, _LOG_DOMAIN) +#define _LOGT(...) _LOG (LOGL_TRACE, _LOG_DOMAIN, self, __VA_ARGS__) +#else +#define _LOGT_ENABLED() FALSE +#define _LOGT(...) G_STMT_START { if (FALSE) { _LOG (LOGL_TRACE, _LOG_DOMAIN, self, __VA_ARGS__); } } G_STMT_END +#endif + +#define _LOGD(...) _LOG (LOGL_DEBUG, _LOG_DOMAIN, self, __VA_ARGS__) +#define _LOGI(...) _LOG (LOGL_INFO , _LOG_DOMAIN, self, __VA_ARGS__) +#define _LOGW(...) _LOG (LOGL_WARN , _LOG_DOMAIN, self, __VA_ARGS__) +#define _LOGE(...) _LOG (LOGL_ERR , _LOG_DOMAIN, self, __VA_ARGS__) + + static void impl_settings_connection_get_settings (NMSettingsConnection *self, DBusGMethodInvocation *context); From e125603450b5ef104f0ae6951c86d36282be141d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 3 Jul 2015 12:11:57 +0200 Subject: [PATCH 5/9] libnm-core: don't assert in nm_connection_get_uuid() for valid connection We want to call nm_connection_get_uuid() also on connections that don't verify. Otherwise it is chumbersome to check first for verified connection. (cherry picked from commit 61eed191a93d26af278fc35862d8aa547037f0fa) --- libnm-core/nm-connection.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c index acdc8b89c7..8f226582cd 100644 --- a/libnm-core/nm-connection.c +++ b/libnm-core/nm-connection.c @@ -1498,7 +1498,8 @@ nm_connection_get_uuid (NMConnection *connection) g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); s_con = nm_connection_get_setting_connection (connection); - g_return_val_if_fail (s_con != NULL, NULL); + if (!s_con) + return NULL; return nm_setting_connection_get_uuid (s_con); } From 6a2c021559adaef92f241acb6719afe09ec9ad54 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 3 Jul 2015 11:30:26 +0200 Subject: [PATCH 6/9] settings: refactor logging statement in nm_settings_connection_get_secrets() (cherry picked from commit 0dcd7b2208b8b1a5ac0ddf08e18df8c2c35309dd) --- src/settings/nm-settings-connection.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index 5ecf3c707b..0e8aabb1d1 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -38,6 +38,7 @@ #include "nm-properties-changed-signal.h" #include "nm-core-internal.h" #include "nm-glib-compat.h" +#include "gsystem-local-alloc.h" #define SETTINGS_TIMESTAMPS_FILE NMSTATEDIR "/timestamps" #define SETTINGS_SEEN_BSSIDS_FILE NMSTATEDIR "/seen-bssids" @@ -977,7 +978,7 @@ nm_settings_connection_get_secrets (NMSettingsConnection *self, GVariant *existing_secrets; GHashTable *existing_secrets_hash; guint32 call_id = 0; - char *joined_hints = NULL; + gs_free char *joined_hints = NULL; /* Use priv->secrets to work around the fact that nm_connection_clear_secrets() * will clear secrets on this object's settings. @@ -1015,17 +1016,12 @@ nm_settings_connection_get_secrets (NMSettingsConnection *self, if (existing_secrets) g_variant_unref (existing_secrets); - if (nm_logging_enabled (LOGL_DEBUG, LOGD_SETTINGS)) { - if (hints) - joined_hints = g_strjoinv (",", (char **) hints); - nm_log_dbg (LOGD_SETTINGS, "(%s/%s:%u) secrets requested flags 0x%X hints '%s'", - nm_connection_get_uuid (NM_CONNECTION (self)), - setting_name, - call_id, - flags, - joined_hints ? joined_hints : "(none)"); - g_free (joined_hints); - } + nm_log_dbg (LOGD_SETTINGS, "(%s/%s:%u) secrets requested flags 0x%X hints '%s'", + nm_connection_get_uuid (NM_CONNECTION (self)), + setting_name, + call_id, + flags, + (hints && hints[0]) ? (joined_hints = g_strjoinv (",", (char **) hints)) : "(none)"); return call_id; } From f202a16026e14de47ee0911220fcd3aa74ded17d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 3 Jul 2015 11:49:43 +0200 Subject: [PATCH 7/9] settings: use _LOG() macros in "nm-settings-connection.c" (cherry picked from commit a6e7b96963a72c1f1648cd1c198ed3642313960c) --- src/settings/nm-settings-connection.c | 140 +++++++++++++------------- 1 file changed, 72 insertions(+), 68 deletions(-) diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index 0e8aabb1d1..134249b0e3 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -531,6 +531,9 @@ nm_settings_connection_replace_settings (NMSettingsConnection *self, nm_utils_log_connection_diff (new_connection, NM_CONNECTION (self), LOGL_DEBUG, LOGD_CORE, log_diff_name, "++ "); nm_connection_replace_settings_from_connection (NM_CONNECTION (self), new_connection); + + _LOGD ("replace settings from connection %p (%s)", new_connection, nm_connection_get_id (NM_CONNECTION (self))); + nm_settings_connection_set_flags (self, NM_SETTINGS_CONNECTION_FLAGS_NM_GENERATED | NM_SETTINGS_CONNECTION_FLAGS_NM_GENERATED_ASSUMED, FALSE); @@ -696,7 +699,7 @@ remove_entry_from_db (NMSettingsConnection *self, const char* db_name) g_free (data); } if (error) { - nm_log_warn (LOGD_SETTINGS, "error writing %s file '%s': %s", db_name, db_file, error->message); + _LOGW ("error writing %s file '%s': %s", db_name, db_file, error->message); g_error_free (error); } } @@ -782,8 +785,8 @@ new_secrets_commit_cb (NMSettingsConnection *self, gpointer user_data) { if (error) { - nm_log_warn (LOGD_SETTINGS, "Error saving new secrets to backing storage: (%d) %s", - error->code, error->message ? error->message : "(unknown)"); + _LOGW ("Error saving new secrets to backing storage: (%d) %s", + error->code, error->message ? error->message : "(unknown)"); } } @@ -810,12 +813,11 @@ agent_secrets_done_cb (NMAgentManager *manager, gboolean agent_had_system = FALSE; if (error) { - nm_log_dbg (LOGD_SETTINGS, "(%s/%s:%u) secrets request error: (%d) %s", - nm_connection_get_uuid (NM_CONNECTION (self)), - setting_name, - call_id, - error->code, - error->message ? error->message : "(unknown)"); + _LOGD ("(%s:%u) secrets request error: (%d) %s", + setting_name, + call_id, + error->code, + error->message ? error->message : "(unknown)"); callback (self, call_id, NULL, setting_name, error, callback_data); return; @@ -832,11 +834,10 @@ agent_secrets_done_cb (NMAgentManager *manager, g_assert (secrets); if (agent_dbus_owner) { - nm_log_dbg (LOGD_SETTINGS, "(%s/%s:%u) secrets returned from agent %s", - nm_connection_get_uuid (NM_CONNECTION (self)), - setting_name, - call_id, - agent_dbus_owner); + _LOGD ("(%s:%u) secrets returned from agent %s", + setting_name, + call_id, + agent_dbus_owner); /* If the agent returned any system-owned secrets (initial connect and no * secrets given when the connection was created, or something like that) @@ -850,36 +851,32 @@ agent_secrets_done_cb (NMAgentManager *manager, /* No user interaction was allowed when requesting secrets; the * agent is being bad. Remove system-owned secrets. */ - nm_log_dbg (LOGD_SETTINGS, "(%s/%s:%u) interaction forbidden but agent %s returned system secrets", - nm_connection_get_uuid (NM_CONNECTION (self)), - setting_name, - call_id, - agent_dbus_owner); + _LOGD ("(%s:%u) interaction forbidden but agent %s returned system secrets", + setting_name, + call_id, + agent_dbus_owner); for_each_secret (NM_CONNECTION (self), secrets, FALSE, clear_nonagent_secrets, NULL); } else if (agent_has_modify == FALSE) { /* Agent didn't successfully authenticate; clear system-owned secrets * from the secrets the agent returned. */ - nm_log_dbg (LOGD_SETTINGS, "(%s/%s:%u) agent failed to authenticate but provided system secrets", - nm_connection_get_uuid (NM_CONNECTION (self)), - setting_name, - call_id); + _LOGD ("(%s:%u) agent failed to authenticate but provided system secrets", + setting_name, + call_id); for_each_secret (NM_CONNECTION (self), secrets, FALSE, clear_nonagent_secrets, NULL); } } } else { - nm_log_dbg (LOGD_SETTINGS, "(%s/%s:%u) existing secrets returned", - nm_connection_get_uuid (NM_CONNECTION (self)), - setting_name, - call_id); + _LOGD ("(%s:%u) existing secrets returned", + setting_name, + call_id); } - nm_log_dbg (LOGD_SETTINGS, "(%s/%s:%u) secrets request completed", - nm_connection_get_uuid (NM_CONNECTION (self)), - setting_name, - call_id); + _LOGD ("(%s:%u) secrets request completed", + setting_name, + call_id); /* If no user interaction was allowed, make sure that no "unsaved" secrets * came back. Unsaved secrets by definition require user interaction. @@ -912,34 +909,30 @@ agent_secrets_done_cb (NMAgentManager *manager, * nothing has changed, since agent-owned secrets don't get saved here. */ if (agent_had_system) { - nm_log_dbg (LOGD_SETTINGS, "(%s/%s:%u) saving new secrets to backing storage", - nm_connection_get_uuid (NM_CONNECTION (self)), - setting_name, - call_id); + _LOGD ("(%s:%u) saving new secrets to backing storage", + setting_name, + call_id); nm_settings_connection_commit_changes (self, new_secrets_commit_cb, NULL); } else { - nm_log_dbg (LOGD_SETTINGS, "(%s/%s:%u) new agent secrets processed", - nm_connection_get_uuid (NM_CONNECTION (self)), - setting_name, - call_id); + _LOGD ("(%s:%u) new agent secrets processed", + setting_name, + call_id); } } else { - nm_log_dbg (LOGD_SETTINGS, "(%s/%s:%u) failed to update with agent secrets: (%d) %s", - nm_connection_get_uuid (NM_CONNECTION (self)), - setting_name, - call_id, - local ? local->code : -1, - (local && local->message) ? local->message : "(unknown)"); + _LOGD ("(%s:%u) failed to update with agent secrets: (%d) %s", + setting_name, + call_id, + local ? local->code : -1, + (local && local->message) ? local->message : "(unknown)"); } g_variant_unref (secrets_dict); } else { - nm_log_dbg (LOGD_SETTINGS, "(%s/%s:%u) failed to update with existing secrets: (%d) %s", - nm_connection_get_uuid (NM_CONNECTION (self)), - setting_name, - call_id, - local ? local->code : -1, - (local && local->message) ? local->message : "(unknown)"); + _LOGD ("(%s:%u) failed to update with existing secrets: (%d) %s", + setting_name, + call_id, + local ? local->code : -1, + (local && local->message) ? local->message : "(unknown)"); } callback (self, call_id, agent_username, setting_name, local, callback_data); @@ -1016,12 +1009,11 @@ nm_settings_connection_get_secrets (NMSettingsConnection *self, if (existing_secrets) g_variant_unref (existing_secrets); - nm_log_dbg (LOGD_SETTINGS, "(%s/%s:%u) secrets requested flags 0x%X hints '%s'", - nm_connection_get_uuid (NM_CONNECTION (self)), - setting_name, - call_id, - flags, - (hints && hints[0]) ? (joined_hints = g_strjoinv (",", (char **) hints)) : "(none)"); + _LOGD ("(%s:%u) secrets requested flags 0x%X hints '%s'", + setting_name, + call_id, + flags, + (hints && hints[0]) ? (joined_hints = g_strjoinv (",", (char **) hints)) : "(none)"); return call_id; } @@ -1032,9 +1024,8 @@ nm_settings_connection_cancel_secrets (NMSettingsConnection *self, { NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); - nm_log_dbg (LOGD_SETTINGS, "(%s:%u) secrets canceled", - nm_connection_get_uuid (NM_CONNECTION (self)), - call_id); + _LOGD ("(%u) secrets canceled", + call_id); priv->reqs = g_slist_remove (priv->reqs, GUINT_TO_POINTER (call_id)); nm_agent_manager_cancel_secrets (priv->agent_mgr, call_id); @@ -1906,7 +1897,7 @@ nm_settings_connection_update_timestamp (NMSettingsConnection *self, timestamps_file = g_key_file_new (); if (!g_key_file_load_from_file (timestamps_file, SETTINGS_TIMESTAMPS_FILE, G_KEY_FILE_KEEP_COMMENTS, &error)) { if (!(error->domain == G_FILE_ERROR && error->code == G_FILE_ERROR_NOENT)) - nm_log_warn (LOGD_SETTINGS, "error parsing timestamps file '%s': %s", SETTINGS_TIMESTAMPS_FILE, error->message); + _LOGW ("error parsing timestamps file '%s': %s", SETTINGS_TIMESTAMPS_FILE, error->message); g_clear_error (&error); } @@ -1921,7 +1912,7 @@ nm_settings_connection_update_timestamp (NMSettingsConnection *self, g_free (data); } if (error) { - nm_log_warn (LOGD_SETTINGS, "error saving timestamp to file '%s': %s", SETTINGS_TIMESTAMPS_FILE, error->message); + _LOGW ("error saving timestamp to file '%s': %s", SETTINGS_TIMESTAMPS_FILE, error->message); g_error_free (error); } g_key_file_free (timestamps_file); @@ -1961,8 +1952,8 @@ nm_settings_connection_read_and_fill_timestamp (NMSettingsConnection *self) priv->timestamp = timestamp; priv->timestamp_set = TRUE; } else { - nm_log_dbg (LOGD_SETTINGS, "failed to read connection timestamp for '%s': (%d) %s", - connection_uuid, err->code, err->message); + _LOGD ("failed to read connection timestamp: (%d) %s", + err->code, err->message); g_clear_error (&err); } g_key_file_free (timestamps_file); @@ -2058,8 +2049,8 @@ nm_settings_connection_add_seen_bssid (NMSettingsConnection *self, g_key_file_set_list_separator (seen_bssids_file, ','); if (!g_key_file_load_from_file (seen_bssids_file, SETTINGS_SEEN_BSSIDS_FILE, G_KEY_FILE_KEEP_COMMENTS, &error)) { if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) { - nm_log_warn (LOGD_SETTINGS, "error parsing seen-bssids file '%s': %s", - SETTINGS_SEEN_BSSIDS_FILE, error->message); + _LOGW ("error parsing seen-bssids file '%s': %s", + SETTINGS_SEEN_BSSIDS_FILE, error->message); } g_clear_error (&error); } @@ -2076,8 +2067,8 @@ nm_settings_connection_add_seen_bssid (NMSettingsConnection *self, g_key_file_free (seen_bssids_file); if (error) { - nm_log_warn (LOGD_SETTINGS, "error saving seen-bssids to file '%s': %s", - SETTINGS_SEEN_BSSIDS_FILE, error->message); + _LOGW ("error saving seen-bssids to file '%s': %s", + SETTINGS_SEEN_BSSIDS_FILE, error->message); g_error_free (error); } } @@ -2320,6 +2311,16 @@ nm_settings_connection_init (NMSettingsConnection *self) g_signal_connect (self, NM_CONNECTION_CHANGED, G_CALLBACK (changed_cb), GUINT_TO_POINTER (TRUE)); } +static void +constructed (GObject *object) +{ + NMSettingsConnection *self = NM_SETTINGS_CONNECTION (object); + + _LOGD ("constructed (%s)", G_OBJECT_TYPE_NAME (self)); + + G_OBJECT_CLASS (nm_settings_connection_parent_class)->constructed (object); +} + static void dispose (GObject *object) { @@ -2327,6 +2328,8 @@ dispose (GObject *object) NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); GSList *iter; + _LOGD ("disposing"); + if (priv->updated_idle_id) { g_source_remove (priv->updated_idle_id); priv->updated_idle_id = 0; @@ -2427,6 +2430,7 @@ nm_settings_connection_class_init (NMSettingsConnectionClass *class) g_type_class_add_private (class, sizeof (NMSettingsConnectionPrivate)); /* Virtual methods */ + object_class->constructed = constructed; object_class->dispose = dispose; object_class->get_property = get_property; object_class->set_property = set_property; From d7e36972c7b15ad09584f29cf4b44aaa5640df17 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 3 Jul 2015 12:23:57 +0200 Subject: [PATCH 8/9] core: print connection path in nm_utils_log_connection_diff() (cherry picked from commit 4c48f66d3dd01e521453bd464639ac1d4db3da59) --- src/NetworkManagerUtils.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c index 1e11f063c0..63741dc3dc 100644 --- a/src/NetworkManagerUtils.c +++ b/src/NetworkManagerUtils.c @@ -2532,11 +2532,15 @@ nm_utils_log_connection_diff (NMConnection *connection, NMConnection *diff_base, if (print_header) { GError *err_verify = NULL; + const char *path = nm_connection_get_path (connection); - if (diff_base) - nm_log (level, domain, "%sconnection '%s' (%p/%s < %p/%s):", prefix, name, connection, G_OBJECT_TYPE_NAME (connection), diff_base, G_OBJECT_TYPE_NAME (diff_base)); - else - nm_log (level, domain, "%sconnection '%s' (%p/%s):", prefix, name, connection, G_OBJECT_TYPE_NAME (connection)); + if (diff_base) { + nm_log (level, domain, "%sconnection '%s' (%p/%s < %p/%s)%s%s%s:", prefix, name, connection, G_OBJECT_TYPE_NAME (connection), diff_base, G_OBJECT_TYPE_NAME (diff_base), + NM_PRINT_FMT_QUOTED (path, " [", path, "]", "")); + } else { + nm_log (level, domain, "%sconnection '%s' (%p/%s):%s%s%s", prefix, name, connection, G_OBJECT_TYPE_NAME (connection), + NM_PRINT_FMT_QUOTED (path, " [", path, "]", "")); + } print_header = FALSE; if (!nm_connection_verify (connection, &err_verify)) { From 45c85a0d6b24df3e9d6847ee1b760ff2281b2fe2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 20 Aug 2015 00:07:14 +0200 Subject: [PATCH 9/9] logging: declare default logging macros in "nm-logging.h" The logging macros _LOGD(), etc. are specific to each file as they format the message according to their context. Still, they were cumbersome to define and their implementation was repeated over and over (slightly different at times). Move the declaration of these macros to "nm-logging.h". The source file now only needs to define _NMLOG(), and either _NMLOG_ENABLED() or _NMLOG_DOMAIN. This reduces code duplication and encourages a common implementation and usage of these macros. (cherry picked from commit ad7cdfc76678512988869607b0b614217f32903a) --- src/devices/nm-device-logging.h | 10 ++--- src/nm-active-connection.c | 31 +++---------- src/nm-auth-manager.c | 20 +++------ src/nm-connectivity.c | 15 ++----- src/nm-default-route-manager.c | 28 +++++++----- src/nm-logging.h | 31 +++++++++++++ src/nm-route-manager.c | 61 ++++++++++---------------- src/platform/nm-linux-platform.c | 30 ++++--------- src/platform/nm-platform.c | 39 +++++----------- src/platform/nmp-object.c | 28 +++--------- src/settings/nm-settings-connection.c | 32 +++----------- src/settings/plugins/ifcfg-rh/plugin.c | 15 ++----- 12 files changed, 127 insertions(+), 213 deletions(-) diff --git a/src/devices/nm-device-logging.h b/src/devices/nm-device-logging.h index acca32e556..f3b76ee8f5 100644 --- a/src/devices/nm-device-logging.h +++ b/src/devices/nm-device-logging.h @@ -31,16 +31,12 @@ _nm_device_log_self_to_device (t *self) \ return (NMDevice *) self; \ } -#define _LOG(level, domain, ...) \ +#undef _NMLOG_ENABLED +#define _NMLOG_ENABLED(level, domain) ( nm_logging_enabled ((level), (domain)) ) +#define _NMLOG(level, domain, ...) \ nm_log_obj ((level), (domain), (self), \ "(%s): " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ (self) ? str_if_set (nm_device_get_iface (_nm_device_log_self_to_device (self)), "(null)") : "(none)" \ _NM_UTILS_MACRO_REST(__VA_ARGS__)) -#define _LOGT(domain, ...) _LOG (LOGL_TRACE, domain, __VA_ARGS__) -#define _LOGD(domain, ...) _LOG (LOGL_DEBUG, domain, __VA_ARGS__) -#define _LOGI(domain, ...) _LOG (LOGL_INFO, domain, __VA_ARGS__) -#define _LOGW(domain, ...) _LOG (LOGL_WARN, domain, __VA_ARGS__) -#define _LOGE(domain, ...) _LOG (LOGL_ERR, domain, __VA_ARGS__) - #endif /* __NETWORKMANAGER_DEVICE_LOGGING_H__ */ diff --git a/src/nm-active-connection.c b/src/nm-active-connection.c index 5e45bdf9e5..3a8e6cf588 100644 --- a/src/nm-active-connection.c +++ b/src/nm-active-connection.c @@ -110,43 +110,26 @@ static void _device_cleanup (NMActiveConnection *self); /****************************************************************/ -#define _LOG_DOMAIN LOGD_DEVICE -#define _LOG_PREFIX_NAME "active-connection" - -#define _LOG(level, domain, self, ...) \ +#define _NMLOG_DOMAIN LOGD_DEVICE +#define _NMLOG_PREFIX_NAME "active-connection" +#define _NMLOG(level, ...) \ G_STMT_START { \ const NMLogLevel __level = (level); \ - const NMLogDomain __domain = (domain); \ \ - if (nm_logging_enabled (__level, __domain)) { \ + if (nm_logging_enabled (__level, _NMLOG_DOMAIN)) { \ char __prefix[128]; \ - const char *__p_prefix = _LOG_PREFIX_NAME; \ + const char *__p_prefix = _NMLOG_PREFIX_NAME; \ const void *const __self = (self); \ \ if (__self) { \ - g_snprintf (__prefix, sizeof (__prefix), "%s[%p]", _LOG_PREFIX_NAME, __self); \ + g_snprintf (__prefix, sizeof (__prefix), "%s[%p]", _NMLOG_PREFIX_NAME, __self); \ __p_prefix = __prefix; \ } \ - _nm_log (__level, __domain, 0, \ + _nm_log (__level, _NMLOG_DOMAIN, 0, \ "%s: " _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \ __p_prefix _NM_UTILS_MACRO_REST (__VA_ARGS__)); \ } \ } G_STMT_END -#define _LOG_LEVEL_ENABLED(level, domain) \ - ( nm_logging_enabled ((level), (domain)) ) - -#ifdef NM_MORE_LOGGING -#define _LOGT_ENABLED() _LOG_LEVEL_ENABLED (LOGL_TRACE, _LOG_DOMAIN) -#define _LOGT(...) _LOG (LOGL_TRACE, _LOG_DOMAIN, self, __VA_ARGS__) -#else -#define _LOGT_ENABLED() FALSE -#define _LOGT(...) G_STMT_START { if (FALSE) { _LOG (LOGL_TRACE, _LOG_DOMAIN, self, __VA_ARGS__); } } G_STMT_END -#endif - -#define _LOGD(...) _LOG (LOGL_DEBUG, _LOG_DOMAIN, self, __VA_ARGS__) -#define _LOGI(...) _LOG (LOGL_INFO , _LOG_DOMAIN, self, __VA_ARGS__) -#define _LOGW(...) _LOG (LOGL_WARN , _LOG_DOMAIN, self, __VA_ARGS__) -#define _LOGE(...) _LOG (LOGL_ERR , _LOG_DOMAIN, self, __VA_ARGS__) /****************************************************************/ diff --git a/src/nm-auth-manager.c b/src/nm-auth-manager.c index 8bd167eff9..09a5791f01 100644 --- a/src/nm-auth-manager.c +++ b/src/nm-auth-manager.c @@ -30,27 +30,21 @@ #define POLKIT_INTERFACE "org.freedesktop.PolicyKit1.Authority" -#define _LOG_DEFAULT_DOMAIN LOGD_CORE - -#define _LOG(level, domain, ...) \ +#define _NMLOG_PREFIX_NAME "auth" +#define _NMLOG_DOMAIN LOGD_CORE +#define _NMLOG(level, ...) \ G_STMT_START { \ - if (nm_logging_enabled ((level), (domain))) { \ - char __prefix[30] = "auth"; \ + if (nm_logging_enabled ((level), (_NMLOG_DOMAIN))) { \ + char __prefix[30] = _NMLOG_PREFIX_NAME; \ \ if ((self) != singleton_instance) \ - g_snprintf (__prefix, sizeof (__prefix), "auth[%p]", (self)); \ - _nm_log ((level), (domain), 0, \ + g_snprintf (__prefix, sizeof (__prefix), ""_NMLOG_PREFIX_NAME"[%p]", (self)); \ + _nm_log ((level), (_NMLOG_DOMAIN), 0, \ "%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ __prefix _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ } \ } G_STMT_END -#define _LOGD(...) _LOG (LOGL_DEBUG, _LOG_DEFAULT_DOMAIN, __VA_ARGS__) -#define _LOGI(...) _LOG (LOGL_INFO, _LOG_DEFAULT_DOMAIN, __VA_ARGS__) -#define _LOGW(...) _LOG (LOGL_WARN, _LOG_DEFAULT_DOMAIN, __VA_ARGS__) -#define _LOGE(...) _LOG (LOGL_ERR, _LOG_DEFAULT_DOMAIN, __VA_ARGS__) - - enum { PROP_0, PROP_POLKIT_ENABLED, diff --git a/src/nm-connectivity.c b/src/nm-connectivity.c index d3f9f25e75..e7e52caec0 100644 --- a/src/nm-connectivity.c +++ b/src/nm-connectivity.c @@ -36,24 +36,15 @@ G_DEFINE_TYPE (NMConnectivity, nm_connectivity, G_TYPE_OBJECT) #define NM_CONNECTIVITY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_CONNECTIVITY, NMConnectivityPrivate)) - -#define _LOG_DEFAULT_DOMAIN LOGD_CONCHECK - -#define _LOG(level, domain, ...) \ +#define _NMLOG_DOMAIN LOGD_CONCHECK +#define _NMLOG(level, ...) \ G_STMT_START { \ - nm_log ((level), (domain), \ + nm_log ((level), (_NMLOG_DOMAIN), \ "%s" _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ "connectivity: " \ _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ } G_STMT_END -#define _LOGT(...) _LOG (LOGL_TRACE, _LOG_DEFAULT_DOMAIN, __VA_ARGS__) -#define _LOGD(...) _LOG (LOGL_DEBUG, _LOG_DEFAULT_DOMAIN, __VA_ARGS__) -#define _LOGI(...) _LOG (LOGL_INFO, _LOG_DEFAULT_DOMAIN, __VA_ARGS__) -#define _LOGW(...) _LOG (LOGL_WARN, _LOG_DEFAULT_DOMAIN, __VA_ARGS__) -#define _LOGE(...) _LOG (LOGL_ERR, _LOG_DEFAULT_DOMAIN, __VA_ARGS__) - - typedef struct { char *uri; char *response; diff --git a/src/nm-default-route-manager.c b/src/nm-default-route-manager.c index b36dd44f3a..96a8c85562 100644 --- a/src/nm-default-route-manager.c +++ b/src/nm-default-route-manager.c @@ -21,10 +21,9 @@ #include "config.h" +#include + #include "nm-default-route-manager.h" - -#include "string.h" - #include "nm-logging.h" #include "nm-device.h" #include "nm-vpn-connection.h" @@ -62,7 +61,17 @@ G_DEFINE_TYPE (NMDefaultRouteManager, nm_default_route_manager, G_TYPE_OBJECT) NM_DEFINE_SINGLETON_GETTER (NMDefaultRouteManager, nm_default_route_manager_get, NM_TYPE_DEFAULT_ROUTE_MANAGER); -#define _LOG(level, addr_family, ...) \ +#define _NMLOG_PREFIX_NAME "default-route" +#undef _NMLOG_ENABLED +#define _NMLOG_ENABLED(level, addr_family) \ + ({ \ + const int __addr_family = (addr_family); \ + const NMLogLevel __level = (level); \ + const NMLogDomain __domain = __addr_family == AF_INET ? LOGD_IP4 : (__addr_family == AF_INET6 ? LOGD_IP6 : LOGD_IP); \ + \ + nm_logging_enabled (__level, __domain); \ + }) +#define _NMLOG(level, addr_family, ...) \ G_STMT_START { \ const int __addr_family = (addr_family); \ const NMLogLevel __level = (level); \ @@ -70,23 +79,18 @@ NM_DEFINE_SINGLETON_GETTER (NMDefaultRouteManager, nm_default_route_manager_get, \ if (nm_logging_enabled (__level, __domain)) { \ char __ch = __addr_family == AF_INET ? '4' : (__addr_family == AF_INET6 ? '6' : '-'); \ - char __prefix[30] = "default-route"; \ + char __prefix[30] = _NMLOG_PREFIX_NAME; \ \ if ((self) != singleton_instance) \ - g_snprintf (__prefix, sizeof (__prefix), "default-route%c[%p]", __ch, (self)); \ + g_snprintf (__prefix, sizeof (__prefix), ""_NMLOG_PREFIX_NAME"%c[%p]", __ch, (self)); \ else \ - __prefix[STRLEN ("default-route")] = __ch; \ + __prefix[STRLEN (_NMLOG_PREFIX_NAME)] = __ch; \ _nm_log (__level, __domain, 0, \ "%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ __prefix _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ } \ } G_STMT_END -#define _LOGD(addr_family, ...) _LOG (LOGL_DEBUG, addr_family, __VA_ARGS__) -#define _LOGI(addr_family, ...) _LOG (LOGL_INFO , addr_family, __VA_ARGS__) -#define _LOGW(addr_family, ...) _LOG (LOGL_WARN , addr_family, __VA_ARGS__) -#define _LOGE(addr_family, ...) _LOG (LOGL_ERR , addr_family, __VA_ARGS__) - #define LOG_ENTRY_FMT "entry[%u/%s:%p:%s:%c:%csync]" #define LOG_ENTRY_ARGS(entry_idx, entry) \ (entry_idx), \ diff --git a/src/nm-logging.h b/src/nm-logging.h index 82a4e71f4e..4021806266 100644 --- a/src/nm-logging.h +++ b/src/nm-logging.h @@ -167,4 +167,35 @@ gboolean nm_logging_setup (const char *level, void nm_logging_syslog_openlog (gboolean debug); void nm_logging_syslog_closelog (void); +/*****************************************************************************/ + +/* This is the default definition of _NMLOG_ENABLED(). Special implementations + * might want to undef this and redefine it. */ +#define _NMLOG_ENABLED(level) ( nm_logging_enabled ((level), (_NMLOG_DOMAIN)) ) + +#define _LOGt(...) _NMLOG (LOGL_TRACE, __VA_ARGS__) +#define _LOGD(...) _NMLOG (LOGL_DEBUG, __VA_ARGS__) +#define _LOGI(...) _NMLOG (LOGL_INFO , __VA_ARGS__) +#define _LOGW(...) _NMLOG (LOGL_WARN , __VA_ARGS__) +#define _LOGE(...) _NMLOG (LOGL_ERR , __VA_ARGS__) + +#define _LOGt_ENABLED(...) _NMLOG_ENABLED (LOGL_TRACE, ##__VA_ARGS__) +#define _LOGD_ENABLED(...) _NMLOG_ENABLED (LOGL_DEBUG, ##__VA_ARGS__) +#define _LOGI_ENABLED(...) _NMLOG_ENABLED (LOGL_INFO , ##__VA_ARGS__) +#define _LOGW_ENABLED(...) _NMLOG_ENABLED (LOGL_WARN , ##__VA_ARGS__) +#define _LOGE_ENABLED(...) _NMLOG_ENABLED (LOGL_ERR , ##__VA_ARGS__) + +/* _LOGt() and _LOGT() both log with level TRACE, but the latter is disabled by default, + * unless building with --with-more-logging. */ +#ifdef NM_MORE_LOGGING +#define _LOGT_ENABLED(...) _NMLOG_ENABLED (LOGL_TRACE, ##__VA_ARGS__) +#define _LOGT(...) _NMLOG (LOGL_TRACE, __VA_ARGS__) +#else +/* still call the logging macros to get compile time checks, but they will be optimize out. */ +#define _LOGT_ENABLED(...) ( FALSE && (_NMLOG_ENABLED (LOGL_TRACE, ##__VA_ARGS__)) ) +#define _LOGT(...) G_STMT_START { if (FALSE) { _NMLOG (LOGL_TRACE, __VA_ARGS__); } } G_STMT_END +#endif + +/*****************************************************************************/ + #endif /* __NETWORKMANAGER_LOGGING_H__ */ diff --git a/src/nm-route-manager.c b/src/nm-route-manager.c index 5ee6c8654f..b392fc1767 100644 --- a/src/nm-route-manager.c +++ b/src/nm-route-manager.c @@ -18,10 +18,10 @@ * Copyright (C) 2015 Red Hat, Inc. */ -#include - #include "config.h" +#include + #include "nm-route-manager.h" #include "nm-platform.h" #include "nmp-object.h" @@ -112,28 +112,9 @@ static const VTableIP vtable_v4, vtable_v6; /*********************************************************************************************/ -#define _LOG_PREFIX_NAME "route-mgr" - -#define _LOG(level, addr_family, ...) \ - G_STMT_START { \ - const int __addr_family = (addr_family); \ - const NMLogLevel __level = (level); \ - const NMLogDomain __domain = __addr_family == AF_INET ? LOGD_IP4 : (__addr_family == AF_INET6 ? LOGD_IP6 : LOGD_IP); \ - \ - if (nm_logging_enabled (__level, __domain)) { \ - char __ch = __addr_family == AF_INET ? '4' : (__addr_family == AF_INET6 ? '6' : '-'); \ - char __prefix[30] = _LOG_PREFIX_NAME; \ - \ - if ((self) != singleton_instance) \ - g_snprintf (__prefix, sizeof (__prefix), "%s%c[%p]", _LOG_PREFIX_NAME, __ch, (self)); \ - else \ - __prefix[STRLEN (_LOG_PREFIX_NAME)] = __ch; \ - _nm_log ((level), (__domain), 0, \ - "%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ - __prefix _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ - } \ - } G_STMT_END -#define _LOG_LEVEL_ENABLED(level, addr_family) \ +#define _NMLOG_PREFIX_NAME "route-mgr" +#undef _NMLOG_ENABLED +#define _NMLOG_ENABLED(level, addr_family) \ ({ \ const int __addr_family = (addr_family); \ const NMLogLevel __level = (level); \ @@ -141,19 +122,25 @@ static const VTableIP vtable_v4, vtable_v6; \ nm_logging_enabled (__level, __domain); \ }) - -#ifdef NM_MORE_LOGGING -#define _LOGT_ENABLED(addr_family) _LOG_LEVEL_ENABLED (LOGL_TRACE, addr_family) -#define _LOGT(addr_family, ...) _LOG (LOGL_TRACE, addr_family, __VA_ARGS__) -#else -#define _LOGT_ENABLED(addr_family) (FALSE && _LOG_LEVEL_ENABLED (LOGL_TRACE, addr_family)) -#define _LOGT(addr_family, ...) G_STMT_START { if (FALSE) { _LOG (LOGL_TRACE, addr_family, __VA_ARGS__); } } G_STMT_END -#endif - -#define _LOGD(addr_family, ...) _LOG (LOGL_DEBUG, addr_family, __VA_ARGS__) -#define _LOGI(addr_family, ...) _LOG (LOGL_INFO , addr_family, __VA_ARGS__) -#define _LOGW(addr_family, ...) _LOG (LOGL_WARN , addr_family, __VA_ARGS__) -#define _LOGE(addr_family, ...) _LOG (LOGL_ERR , addr_family, __VA_ARGS__) +#define _NMLOG(level, addr_family, ...) \ + G_STMT_START { \ + const int __addr_family = (addr_family); \ + const NMLogLevel __level = (level); \ + const NMLogDomain __domain = __addr_family == AF_INET ? LOGD_IP4 : (__addr_family == AF_INET6 ? LOGD_IP6 : LOGD_IP); \ + \ + if (nm_logging_enabled (__level, __domain)) { \ + char __ch = __addr_family == AF_INET ? '4' : (__addr_family == AF_INET6 ? '6' : '-'); \ + char __prefix[30] = _NMLOG_PREFIX_NAME; \ + \ + if ((self) != singleton_instance) \ + g_snprintf (__prefix, sizeof (__prefix), "%s%c[%p]", _NMLOG_PREFIX_NAME, __ch, (self)); \ + else \ + __prefix[STRLEN (_NMLOG_PREFIX_NAME)] = __ch; \ + _nm_log ((level), (__domain), 0, \ + "%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ + __prefix _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ + } \ + } G_STMT_END /*********************************************************************************************/ diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 785ac6e274..e922a23b54 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -67,8 +67,9 @@ /*********************************************************************************************/ -#define _LOG_DOMAIN LOGD_PLATFORM -#define _LOG_PREFIX_NAME "platform-linux" +#define _NMLOG_DOMAIN LOGD_PLATFORM +#define _NMLOG_PREFIX_NAME "platform-linux" +#define _NMLOG(level, ...) _LOG(level, _NMLOG_DOMAIN, platform, __VA_ARGS__) #define _LOG(level, domain, self, ...) \ G_STMT_START { \ @@ -77,11 +78,11 @@ \ if (nm_logging_enabled (__level, __domain)) { \ char __prefix[32]; \ - const char *__p_prefix = _LOG_PREFIX_NAME; \ + const char *__p_prefix = _NMLOG_PREFIX_NAME; \ const void *const __self = (self); \ \ if (__self && __self != nm_platform_try_get ()) { \ - g_snprintf (__prefix, sizeof (__prefix), "%s[%p]", _LOG_PREFIX_NAME, __self); \ + g_snprintf (__prefix, sizeof (__prefix), "%s[%p]", _NMLOG_PREFIX_NAME, __self); \ __p_prefix = __prefix; \ } \ _nm_log (__level, __domain, 0, \ @@ -89,25 +90,10 @@ __p_prefix _NM_UTILS_MACRO_REST (__VA_ARGS__)); \ } \ } G_STMT_END -#define _LOG_LEVEL_ENABLED(level, domain) \ - ( nm_logging_enabled ((level), (domain)) ) -#ifdef NM_MORE_LOGGING -#define _LOGT_ENABLED() _LOG_LEVEL_ENABLED (LOGL_TRACE, _LOG_DOMAIN) -#define _LOGT(...) _LOG (LOGL_TRACE, _LOG_DOMAIN, platform, __VA_ARGS__) -#else -#define _LOGT_ENABLED() FALSE -#define _LOGT(...) G_STMT_START { if (FALSE) { _LOG (LOGL_TRACE, _LOG_DOMAIN, platform, __VA_ARGS__); } } G_STMT_END -#endif - -#define _LOGD(...) _LOG (LOGL_DEBUG, _LOG_DOMAIN, platform, __VA_ARGS__) -#define _LOGI(...) _LOG (LOGL_INFO , _LOG_DOMAIN, platform, __VA_ARGS__) -#define _LOGW(...) _LOG (LOGL_WARN , _LOG_DOMAIN, platform, __VA_ARGS__) -#define _LOGE(...) _LOG (LOGL_ERR , _LOG_DOMAIN, platform, __VA_ARGS__) - -#define debug(...) _LOG (LOGL_DEBUG, _LOG_DOMAIN, NULL, __VA_ARGS__) -#define warning(...) _LOG (LOGL_WARN , _LOG_DOMAIN, NULL, __VA_ARGS__) -#define error(...) _LOG (LOGL_ERR , _LOG_DOMAIN, NULL, __VA_ARGS__) +#define debug(...) _LOG (LOGL_DEBUG, _NMLOG_DOMAIN, NULL, __VA_ARGS__) +#define warning(...) _LOG (LOGL_WARN , _NMLOG_DOMAIN, NULL, __VA_ARGS__) +#define error(...) _LOG (LOGL_ERR , _NMLOG_DOMAIN, NULL, __VA_ARGS__) /****************************************************************** * Forward declarations and enums diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index b6d87ff959..f4b2ca9016 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -43,43 +43,26 @@ G_STATIC_ASSERT (sizeof ( ((NMPlatformLink *) NULL)->addr.data ) == NM_UTILS_HWADDR_LEN_MAX); -#define _LOG_DOMAIN LOGD_PLATFORM -#define _LOG_PREFIX_NAME "platform" - -#define _LOG(level, domain, self, ...) \ +#define _NMLOG_DOMAIN LOGD_PLATFORM +#define _NMLOG_PREFIX_NAME "platform" +#define _NMLOG(level, ...) \ G_STMT_START { \ const NMLogLevel __level = (level); \ - const NMLogDomain __domain = (domain); \ \ - if (nm_logging_enabled (__level, __domain)) { \ + if (nm_logging_enabled (__level, _NMLOG_DOMAIN)) { \ char __prefix[32]; \ - const char *__p_prefix = _LOG_PREFIX_NAME; \ + const char *__p_prefix = _NMLOG_PREFIX_NAME; \ const void *const __self = (self); \ \ if (__self && __self != nm_platform_try_get ()) { \ - g_snprintf (__prefix, sizeof (__prefix), "%s[%p]", _LOG_PREFIX_NAME, __self); \ + g_snprintf (__prefix, sizeof (__prefix), "%s[%p]", _NMLOG_PREFIX_NAME, __self); \ __p_prefix = __prefix; \ } \ - _nm_log (__level, __domain, 0, \ + _nm_log (__level, _NMLOG_DOMAIN, 0, \ "%s: " _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \ __p_prefix _NM_UTILS_MACRO_REST (__VA_ARGS__)); \ } \ } G_STMT_END -#define _LOG_LEVEL_ENABLED(level, domain) \ - ( nm_logging_enabled ((level), (domain)) ) - -#ifdef NM_MORE_LOGGING -#define _LOGT_ENABLED() _LOG_LEVEL_ENABLED (LOGL_TRACE, _LOG_DOMAIN) -#define _LOGT(...) _LOG (LOGL_TRACE, _LOG_DOMAIN, self, __VA_ARGS__) -#else -#define _LOGT_ENABLED() FALSE -#define _LOGT(...) G_STMT_START { if (FALSE) { _LOG (LOGL_TRACE, _LOG_DOMAIN, self, __VA_ARGS__); } } G_STMT_END -#endif - -#define _LOGD(...) _LOG (LOGL_DEBUG, _LOG_DOMAIN, self, __VA_ARGS__) -#define _LOGI(...) _LOG (LOGL_INFO , _LOG_DOMAIN, self, __VA_ARGS__) -#define _LOGW(...) _LOG (LOGL_WARN , _LOG_DOMAIN, self, __VA_ARGS__) -#define _LOGE(...) _LOG (LOGL_ERR , _LOG_DOMAIN, self, __VA_ARGS__) #define NM_PLATFORM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_PLATFORM, NMPlatformPrivate)) @@ -1873,7 +1856,7 @@ nm_platform_ip4_address_add (NMPlatform *self, g_return_val_if_fail (klass->ip4_address_add, FALSE); g_return_val_if_fail (!label || strlen (label) < sizeof (((NMPlatformIP4Address *) NULL)->label), FALSE); - if (nm_logging_enabled (LOGL_DEBUG, LOGD_PLATFORM)) { + if (_LOGD_ENABLED ()) { NMPlatformIP4Address addr = { 0 }; addr.ifindex = ifindex; @@ -1909,7 +1892,7 @@ nm_platform_ip6_address_add (NMPlatform *self, g_return_val_if_fail (preferred <= lifetime, FALSE); g_return_val_if_fail (klass->ip6_address_add, FALSE); - if (nm_logging_enabled (LOGL_DEBUG, LOGD_PLATFORM)) { + if (_LOGD_ENABLED ()) { NMPlatformIP6Address addr = { 0 }; addr.ifindex = ifindex; @@ -2190,7 +2173,7 @@ nm_platform_ip4_route_add (NMPlatform *self, g_return_val_if_fail (0 <= plen && plen <= 32, FALSE); g_return_val_if_fail (klass->ip4_route_add, FALSE); - if (nm_logging_enabled (LOGL_DEBUG, LOGD_PLATFORM)) { + if (_LOGD_ENABLED ()) { NMPlatformIP4Route route = { 0 }; route.ifindex = ifindex; @@ -2218,7 +2201,7 @@ nm_platform_ip6_route_add (NMPlatform *self, g_return_val_if_fail (0 <= plen && plen <= 128, FALSE); g_return_val_if_fail (klass->ip6_route_add, FALSE); - if (nm_logging_enabled (LOGL_DEBUG, LOGD_PLATFORM)) { + if (_LOGD_ENABLED ()) { NMPlatformIP6Route route = { 0 }; route.ifindex = ifindex; diff --git a/src/platform/nmp-object.c b/src/platform/nmp-object.c index 51684b93c7..7fe2d7d3b7 100644 --- a/src/platform/nmp-object.c +++ b/src/platform/nmp-object.c @@ -18,10 +18,11 @@ * Copyright (C) 2015 Red Hat, Inc. */ -#include "nmp-object.h" +#include "config.h" #include +#include "nmp-object.h" #include "nm-platform-utils.h" #include "NetworkManagerUtils.h" #include "nm-utils.h" @@ -29,38 +30,21 @@ /*********************************************************************************************/ -#define _LOG_DOMAIN LOGD_PLATFORM - -#define _LOG(level, domain, obj, ...) \ +#define _NMLOG_DOMAIN LOGD_PLATFORM +#define _NMLOG(level, obj, ...) \ G_STMT_START { \ const NMLogLevel __level = (level); \ - const NMLogDomain __domain = (domain); \ \ - if (nm_logging_enabled (__level, __domain)) { \ + if (nm_logging_enabled (__level, _NMLOG_DOMAIN)) { \ const NMPObject *const __obj = (obj); \ \ - _nm_log (__level, __domain, 0, \ + _nm_log (__level, _NMLOG_DOMAIN, 0, \ "nmp-object[%p/%s]: " _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \ __obj, \ (__obj ? NMP_OBJECT_GET_CLASS (__obj)->obj_type_name : "???") \ _NM_UTILS_MACRO_REST (__VA_ARGS__)); \ } \ } G_STMT_END -#define _LOG_LEVEL_ENABLED(level, domain) \ - ( nm_logging_enabled ((level), (domain)) ) - -#ifdef NM_MORE_LOGGING -#define _LOGT_ENABLED() _LOG_LEVEL_ENABLED (LOGL_TRACE, _LOG_DOMAIN) -#define _LOGT(obj, ...) _LOG (LOGL_TRACE, _LOG_DOMAIN, obj, __VA_ARGS__) -#else -#define _LOGT_ENABLED() FALSE -#define _LOGT(obj, ...) G_STMT_START { if (FALSE) { _LOG (LOGL_TRACE, _LOG_DOMAIN, obj, __VA_ARGS__); } } G_STMT_END -#endif - -#define _LOGD(obj, ...) _LOG (LOGL_DEBUG, _LOG_DOMAIN, obj, __VA_ARGS__) -#define _LOGI(obj, ...) _LOG (LOGL_INFO , _LOG_DOMAIN, obj, __VA_ARGS__) -#define _LOGW(obj, ...) _LOG (LOGL_WARN , _LOG_DOMAIN, obj, __VA_ARGS__) -#define _LOGE(obj, ...) _LOG (LOGL_ERR , _LOG_DOMAIN, obj, __VA_ARGS__) /*********************************************************************************************/ diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index 134249b0e3..da5384c0db 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -43,46 +43,28 @@ #define SETTINGS_TIMESTAMPS_FILE NMSTATEDIR "/timestamps" #define SETTINGS_SEEN_BSSIDS_FILE NMSTATEDIR "/seen-bssids" - -#define _LOG_DOMAIN LOGD_SETTINGS -#define _LOG_PREFIX_NAME "settings-connection" - -#define _LOG(level, domain, self, ...) \ +#define _NMLOG_DOMAIN LOGD_SETTINGS +#define _NMLOG_PREFIX_NAME "settings-connection" +#define _NMLOG(level, ...) \ G_STMT_START { \ const NMLogLevel __level = (level); \ - const NMLogDomain __domain = (domain); \ \ - if (nm_logging_enabled (__level, __domain)) { \ + if (nm_logging_enabled (__level, _NMLOG_DOMAIN)) { \ char __prefix[128]; \ - const char *__p_prefix = _LOG_PREFIX_NAME; \ + const char *__p_prefix = _NMLOG_PREFIX_NAME; \ const void *const __self = (self); \ \ if (__self) { \ const char *__uuid = nm_connection_get_uuid ((NMConnection *) __self); \ \ - g_snprintf (__prefix, sizeof (__prefix), "%s[%p%s%s]", _LOG_PREFIX_NAME, __self, __uuid ? "," : "", __uuid ? __uuid : ""); \ + g_snprintf (__prefix, sizeof (__prefix), "%s[%p%s%s]", _NMLOG_PREFIX_NAME, __self, __uuid ? "," : "", __uuid ? __uuid : ""); \ __p_prefix = __prefix; \ } \ - _nm_log (__level, __domain, 0, \ + _nm_log (__level, _NMLOG_DOMAIN, 0, \ "%s: " _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \ __p_prefix _NM_UTILS_MACRO_REST (__VA_ARGS__)); \ } \ } G_STMT_END -#define _LOG_LEVEL_ENABLED(level, domain) \ - ( nm_logging_enabled ((level), (domain)) ) - -#ifdef NM_MORE_LOGGING -#define _LOGT_ENABLED() _LOG_LEVEL_ENABLED (LOGL_TRACE, _LOG_DOMAIN) -#define _LOGT(...) _LOG (LOGL_TRACE, _LOG_DOMAIN, self, __VA_ARGS__) -#else -#define _LOGT_ENABLED() FALSE -#define _LOGT(...) G_STMT_START { if (FALSE) { _LOG (LOGL_TRACE, _LOG_DOMAIN, self, __VA_ARGS__); } } G_STMT_END -#endif - -#define _LOGD(...) _LOG (LOGL_DEBUG, _LOG_DOMAIN, self, __VA_ARGS__) -#define _LOGI(...) _LOG (LOGL_INFO , _LOG_DOMAIN, self, __VA_ARGS__) -#define _LOGW(...) _LOG (LOGL_WARN , _LOG_DOMAIN, self, __VA_ARGS__) -#define _LOGE(...) _LOG (LOGL_ERR , _LOG_DOMAIN, self, __VA_ARGS__) static void impl_settings_connection_get_settings (NMSettingsConnection *self, diff --git a/src/settings/plugins/ifcfg-rh/plugin.c b/src/settings/plugins/ifcfg-rh/plugin.c index 1a3f791a4c..526cdafea0 100644 --- a/src/settings/plugins/ifcfg-rh/plugin.c +++ b/src/settings/plugins/ifcfg-rh/plugin.c @@ -42,7 +42,7 @@ #include #endif -#include +#include "nm-setting-connection.h" #include "common.h" #include "nm-dbus-glib-types.h" @@ -64,22 +64,15 @@ #define DBUS_OBJECT_PATH "/com/redhat/ifcfgrh1" -#define _LOG_DEFAULT_DOMAIN LOGD_SETTINGS - -#define _LOG(level, domain, ...) \ +#define _NMLOG_DOMAIN LOGD_SETTINGS +#define _NMLOG(level, ...) \ G_STMT_START { \ - nm_log ((level), (domain), \ + nm_log ((level), (_NMLOG_DOMAIN), \ "%s" _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ "ifcfg-rh: " \ _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ } G_STMT_END -#define _LOGT(...) _LOG (LOGL_TRACE, _LOG_DEFAULT_DOMAIN, __VA_ARGS__) -#define _LOGD(...) _LOG (LOGL_DEBUG, _LOG_DEFAULT_DOMAIN, __VA_ARGS__) -#define _LOGI(...) _LOG (LOGL_INFO, _LOG_DEFAULT_DOMAIN, __VA_ARGS__) -#define _LOGW(...) _LOG (LOGL_WARN, _LOG_DEFAULT_DOMAIN, __VA_ARGS__) -#define _LOGE(...) _LOG (LOGL_ERR, _LOG_DEFAULT_DOMAIN, __VA_ARGS__) - #define ERR_GET_MSG(err) (((err) && (err)->message) ? (err)->message : "(unknown)")