summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2016-03-03 09:20:18 +0100
committerBeniamino Galvani <bgalvani@redhat.com>2016-03-04 11:55:41 +0100
commitf48ee45ff0eea2d8a317fc8f79c0a114fd966f65 (patch)
treec9ffaeb73c7e3dc459958d6d1690ff2720baa4f5
parentd2cc33a5b9a09d0d2d1d2f05f7b5d5e01ca78045 (diff)
downloadNetworkManager-f48ee45ff0eea2d8a317fc8f79c0a114fd966f65.tar.gz
policy: use logging helpers
-rw-r--r--src/nm-policy.c129
1 files changed, 69 insertions, 60 deletions
diff --git a/src/nm-policy.c b/src/nm-policy.c
index b54468167c..bbfc3dd638 100644
--- a/src/nm-policy.c
+++ b/src/nm-policy.c
@@ -47,6 +47,15 @@
#include "nm-dhcp4-config.h"
#include "nm-dhcp6-config.h"
+#define _NMLOG_PREFIX_NAME "policy"
+#define _NMLOG(level, domain, ...) \
+ G_STMT_START { \
+ nm_log ((level), (domain), \
+ "%s" _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \
+ _NMLOG_PREFIX_NAME": " \
+ _NM_UTILS_MACRO_REST (__VA_ARGS__)); \
+ } G_STMT_END
+
typedef struct {
NMManager *manager;
NMFirewallManager *firewall_manager;
@@ -132,8 +141,8 @@ set_system_hostname (const char *new_hostname, const char *msg)
errno = 0;
ret = gethostname (old_hostname, HOST_NAME_MAX);
if (ret != 0) {
- nm_log_warn (LOGD_DNS, "couldn't get the system hostname: (%d) %s",
- errno, strerror (errno));
+ _LOGW (LOGD_DNS, "couldn't get the system hostname: (%d) %s",
+ errno, strerror (errno));
} else {
/* Don't set the hostname if it isn't actually changing */
if ( (new_hostname && !strcmp (old_hostname, new_hostname))
@@ -143,15 +152,15 @@ set_system_hostname (const char *new_hostname, const char *msg)
name = (new_hostname && strlen (new_hostname)) ? new_hostname : FALLBACK_HOSTNAME4;
- nm_log_info (LOGD_DNS, "Setting system hostname to '%s' (%s)", name, msg);
+ _LOGI (LOGD_DNS, "setting system hostname to '%s' (%s)", name, msg);
ret = sethostname (name, strlen (name));
if (ret != 0) {
int errsv = errno;
- nm_log_warn (LOGD_DNS, "couldn't set the system hostname to '%s': (%d) %s",
- name, errsv, strerror (errsv));
+ _LOGW (LOGD_DNS, "couldn't set the system hostname to '%s': (%d) %s",
+ name, errsv, strerror (errsv));
if (errsv == EPERM)
- nm_log_warn (LOGD_DNS, "You should use hostnamed when systemd hardening is in effect!");
+ _LOGW (LOGD_DNS, "you should use hostnamed when systemd hardening is in effect!");
}
return (ret == 0);
@@ -290,8 +299,8 @@ update_system_hostname (NMPolicy *policy, NMDevice *best4, NMDevice *best6)
return;
}
}
- nm_log_warn (LOGD_DNS, "DHCPv4-provided hostname '%s' looks invalid; ignoring it",
- dhcp_hostname);
+ _LOGW (LOGD_DNS, "DHCPv4-provided hostname '%s' looks invalid; ignoring it",
+ dhcp_hostname);
}
}
} else if (best6) {
@@ -309,8 +318,8 @@ update_system_hostname (NMPolicy *policy, NMDevice *best4, NMDevice *best6)
return;
}
}
- nm_log_warn (LOGD_DNS, "DHCPv6-provided hostname '%s' looks invalid; ignoring it",
- dhcp_hostname);
+ _LOGW (LOGD_DNS, "DHCPv6-provided hostname '%s' looks invalid; ignoring it",
+ dhcp_hostname);
}
}
}
@@ -469,8 +478,8 @@ update_ip4_routing (NMPolicy *policy, gboolean force_update)
priv->default_device4 = default_device;
connection = nm_active_connection_get_applied_connection (best_ac);
- nm_log_info (LOGD_CORE, "Policy set '%s' (%s) as default for IPv4 routing and DNS.",
- nm_connection_get_id (connection), ip_iface);
+ _LOGI (LOGD_CORE, "set '%s' (%s) as default for IPv4 routing and DNS",
+ nm_connection_get_id (connection), ip_iface);
g_object_notify (G_OBJECT (policy), NM_POLICY_DEFAULT_IP4_DEVICE);
}
@@ -564,8 +573,8 @@ update_ip6_routing (NMPolicy *policy, gboolean force_update)
priv->default_device6 = default_device6;
connection = nm_active_connection_get_applied_connection (best_ac);
- nm_log_info (LOGD_CORE, "Policy set '%s' (%s) as default for IPv6 routing and DNS.",
- nm_connection_get_id (connection), ip_iface);
+ _LOGI (LOGD_CORE, "set '%s' (%s) as default for IPv6 routing and DNS",
+ nm_connection_get_id (connection), ip_iface);
g_object_notify (G_OBJECT (policy), NM_POLICY_DEFAULT_IP6_DEVICE);
}
@@ -686,8 +695,8 @@ auto_activate_device (gpointer user_data)
GError *error = NULL;
NMAuthSubject *subject;
- nm_log_info (LOGD_DEVICE, "Auto-activating connection '%s'.",
- nm_settings_connection_get_id (best_connection));
+ _LOGI (LOGD_DEVICE, "auto-activating connection '%s'",
+ nm_settings_connection_get_id (best_connection));
subject = nm_auth_subject_new_internal ();
if (!nm_manager_activate_connection (priv->manager,
best_connection,
@@ -695,10 +704,10 @@ auto_activate_device (gpointer user_data)
data->device,
subject,
&error)) {
- nm_log_info (LOGD_DEVICE, "Connection '%s' auto-activation failed: (%d) %s",
- nm_settings_connection_get_id (best_connection),
- error->code,
- error->message);
+ _LOGI (LOGD_DEVICE, "connection '%s' auto-activation failed: (%d) %s",
+ nm_settings_connection_get_id (best_connection),
+ error->code,
+ error->message);
g_error_free (error);
}
g_object_unref (subject);
@@ -773,9 +782,9 @@ process_secondaries (NMPolicy *policy,
continue;
if (connected) {
- nm_log_dbg (LOGD_DEVICE, "Secondary connection '%s' SUCCEEDED; active path '%s'",
- nm_active_connection_get_settings_connection_id (active),
- nm_exported_object_get_path (NM_EXPORTED_OBJECT (active)));
+ _LOGD (LOGD_DEVICE, "secondary connection '%s' succeeded; active path '%s'",
+ nm_active_connection_get_settings_connection_id (active),
+ nm_exported_object_get_path (NM_EXPORTED_OBJECT (active)));
/* Secondary connection activated */
secondary_data->secondaries = g_slist_remove (secondary_data->secondaries, secondary_active);
@@ -789,9 +798,9 @@ process_secondaries (NMPolicy *policy,
break;
}
} else {
- nm_log_dbg (LOGD_DEVICE, "Secondary connection '%s' FAILED; active path '%s'",
- nm_active_connection_get_settings_connection_id (active),
- nm_exported_object_get_path (NM_EXPORTED_OBJECT (active)));
+ _LOGD (LOGD_DEVICE, "secondary connection '%s' failed; active path '%s'",
+ nm_active_connection_get_settings_connection_id (active),
+ nm_exported_object_get_path (NM_EXPORTED_OBJECT (active)));
/* Secondary connection failed -> do not watch other connections */
priv->pending_secondaries = g_slist_remove (priv->pending_secondaries, secondary_data);
@@ -824,10 +833,10 @@ reset_autoconnect_all (NMPolicy *policy, NMDevice *device)
GSList *connections, *iter;
if (device) {
- nm_log_dbg (LOGD_DEVICE, "Re-enabling autoconnect for all connections on %s",
- nm_device_get_iface (device));
+ _LOGD (LOGD_DEVICE, "re-enabling autoconnect for all connections on %s",
+ nm_device_get_iface (device));
} else
- nm_log_dbg (LOGD_DEVICE, "Re-enabling autoconnect for all connections");
+ _LOGD (LOGD_DEVICE, "re-enabling autoconnect for all connections");
connections = nm_settings_get_connections (priv->settings);
for (iter = connections; iter; iter = g_slist_next (iter)) {
@@ -845,7 +854,7 @@ reset_autoconnect_for_failed_secrets (NMPolicy *policy)
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
GSList *connections, *iter;
- nm_log_dbg (LOGD_DEVICE, "Re-enabling autoconnect for all connections with failed secrets");
+ _LOGD (LOGD_DEVICE, "re-enabling autoconnect for all connections with failed secrets");
connections = nm_settings_get_connections (priv->settings);
for (iter = connections; iter; iter = g_slist_next (iter)) {
@@ -865,8 +874,8 @@ block_autoconnect_for_device (NMPolicy *policy, NMDevice *device)
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
GSList *connections, *iter;
- nm_log_dbg (LOGD_DEVICE, "Blocking autoconnect for all connections on %s",
- nm_device_get_iface (device));
+ _LOGD (LOGD_DEVICE, "blocking autoconnect for all connections on %s",
+ nm_device_get_iface (device));
/* NMDevice keeps its own autoconnect-able-ness state; we only need to
* explicitly block connections for software devices, where the NMDevice
@@ -1061,14 +1070,14 @@ activate_secondary_connections (NMPolicy *policy,
settings_con = nm_settings_get_connection_by_uuid (priv->settings, sec_uuid);
if (!settings_con) {
- nm_log_warn (LOGD_DEVICE, "Secondary connection '%s' auto-activation failed: The connection doesn't exist.",
- sec_uuid);
+ _LOGW (LOGD_DEVICE, "secondary connection '%s' auto-activation failed: The connection doesn't exist.",
+ sec_uuid);
success = FALSE;
break;
}
if (!nm_connection_is_type (NM_CONNECTION (settings_con), NM_SETTING_VPN_SETTING_NAME)) {
- nm_log_warn (LOGD_DEVICE, "Secondary connection '%s (%s)' auto-activation failed: The connection is not a VPN.",
- nm_settings_connection_get_id (settings_con), sec_uuid);
+ _LOGW (LOGD_DEVICE, "secondary connection '%s (%s)' auto-activation failed: The connection is not a VPN.",
+ nm_settings_connection_get_id (settings_con), sec_uuid);
success = FALSE;
break;
}
@@ -1076,9 +1085,9 @@ activate_secondary_connections (NMPolicy *policy,
req = nm_device_get_act_request (device);
g_assert (req);
- nm_log_dbg (LOGD_DEVICE, "Activating secondary connection '%s (%s)' for base connection '%s (%s)'",
- nm_settings_connection_get_id (settings_con), sec_uuid,
- nm_connection_get_id (connection), nm_connection_get_uuid (connection));
+ _LOGD (LOGD_DEVICE, "activating secondary connection '%s (%s)' for base connection '%s (%s)'",
+ nm_settings_connection_get_id (settings_con), sec_uuid,
+ nm_connection_get_id (connection), nm_connection_get_uuid (connection));
ac = nm_manager_activate_connection (priv->manager,
settings_con,
nm_exported_object_get_path (NM_EXPORTED_OBJECT (req)),
@@ -1088,10 +1097,10 @@ activate_secondary_connections (NMPolicy *policy,
if (ac)
secondary_ac_list = g_slist_append (secondary_ac_list, g_object_ref (ac));
else {
- nm_log_warn (LOGD_DEVICE, "Secondary connection '%s (%s)' auto-activation failed: (%d) %s",
- nm_settings_connection_get_id (settings_con), sec_uuid,
- error->code,
- error->message);
+ _LOGW (LOGD_DEVICE, "secondary connection '%s (%s)' auto-activation failed: (%d) %s",
+ nm_settings_connection_get_id (settings_con), sec_uuid,
+ error->code,
+ error->message);
g_clear_error (&error);
success = FALSE;
break;
@@ -1135,19 +1144,19 @@ device_state_changed (NMDevice *device,
guint32 tries = nm_settings_connection_get_autoconnect_retries (connection);
if (reason == NM_DEVICE_STATE_REASON_NO_SECRETS) {
- nm_log_dbg (LOGD_DEVICE, "Connection '%s' now blocked from autoconnect due to no secrets",
- nm_settings_connection_get_id (connection));
+ _LOGD (LOGD_DEVICE, "connection '%s' now blocked from autoconnect due to no secrets",
+ nm_settings_connection_get_id (connection));
nm_settings_connection_set_autoconnect_blocked_reason (connection, NM_DEVICE_STATE_REASON_NO_SECRETS);
} else if (tries > 0) {
- nm_log_dbg (LOGD_DEVICE, "Connection '%s' failed to autoconnect; %d tries left",
- nm_settings_connection_get_id (connection), tries);
+ _LOGD (LOGD_DEVICE, "connection '%s' failed to autoconnect; %d tries left",
+ nm_settings_connection_get_id (connection), tries);
nm_settings_connection_set_autoconnect_retries (connection, tries - 1);
}
if (nm_settings_connection_get_autoconnect_retries (connection) == 0) {
- nm_log_info (LOGD_DEVICE, "Disabling autoconnect for connection '%s'.",
- nm_settings_connection_get_id (connection));
+ _LOGI (LOGD_DEVICE, "disabling autoconnect for connection '%s'.",
+ nm_settings_connection_get_id (connection));
/* Schedule a handler to reset retries count */
if (!priv->reset_retries_id) {
gint32 retry_time = nm_settings_connection_get_autoconnect_retry_time (connection);
@@ -1199,8 +1208,8 @@ device_state_changed (NMDevice *device,
} else {
if (connection) {
/* The connection was deactivated, so block just this connection */
- nm_log_dbg (LOGD_DEVICE, "Blocking autoconnect of connection '%s' by user request",
- nm_settings_connection_get_id (connection));
+ _LOGD (LOGD_DEVICE, "blocking autoconnect of connection '%s' by user request",
+ nm_settings_connection_get_id (connection));
nm_settings_connection_set_autoconnect_blocked_reason (connection,
NM_DEVICE_STATE_REASON_USER_REQUESTED);
}
@@ -1491,9 +1500,9 @@ vpn_connection_retry_after_failure (NMVpnConnection *vpn, NMPolicy *policy)
NULL,
nm_active_connection_get_subject (ac),
&error)) {
- nm_log_warn (LOGD_DEVICE, "VPN '%s' reconnect failed: %s",
- nm_settings_connection_get_id (connection),
- error->message ? error->message : "unknown");
+ _LOGW (LOGD_DEVICE, "VPN '%s' reconnect failed: %s",
+ nm_settings_connection_get_id (connection),
+ error->message ? error->message : "unknown");
g_clear_error (&error);
}
}
@@ -1606,8 +1615,8 @@ dns_config_changed (NMDnsManager *dns_manager, gpointer user_data)
if (priv->lookup_addr) {
char *str = NULL;
- nm_log_dbg (LOGD_DNS, "restarting reverse-lookup thread for address %s",
- (str = g_inet_address_to_string (priv->lookup_addr)));
+ _LOGD (LOGD_DNS, "restarting reverse-lookup thread for address %s",
+ (str = g_inet_address_to_string (priv->lookup_addr)));
g_free (str);
priv->lookup_cancellable = g_cancellable_new ();
@@ -1670,10 +1679,10 @@ _deactivate_if_active (NMManager *manager, NMSettingsConnection *connection)
nm_exported_object_get_path (NM_EXPORTED_OBJECT (ac)),
NM_DEVICE_STATE_REASON_CONNECTION_REMOVED,
&error)) {
- nm_log_warn (LOGD_DEVICE, "Connection '%s' disappeared, but error deactivating it: (%d) %s",
- nm_settings_connection_get_id (connection),
- error ? error->code : -1,
- error ? error->message : "(unknown)");
+ _LOGW (LOGD_DEVICE, "connection '%s' disappeared, but error deactivating it: (%d) %s",
+ nm_settings_connection_get_id (connection),
+ error ? error->code : -1,
+ error ? error->message : "(unknown)");
g_clear_error (&error);
}
}