From 7f478f86ca34c08f1e04de6d69123e7695a4be16 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 6 Oct 2016 15:55:01 +0200 Subject: [PATCH 1/6] logging: avoid copy of logging message fo syslog and glib logging backend As both syslog() and g_log() accept a format string, we should not create fullmsg ahead. This saves an additional clone of the message. --- src/nm-logging.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/nm-logging.c b/src/nm-logging.c index d0149ffebe..e824bd17e5 100644 --- a/src/nm-logging.c +++ b/src/nm-logging.c @@ -569,8 +569,6 @@ _nm_log_impl (const char *file, { va_list args; char *msg; - char *fullmsg; - char s_buf_timestamp[64]; GTimeVal tv; if ((guint) level >= G_N_ELEMENTS (_nm_logging_enabled_state)) @@ -590,8 +588,15 @@ _nm_log_impl (const char *file, msg = g_strdup_vprintf (fmt, args); va_end (args); +#define MESSAGE_FMT "%s%-7s [%ld.%04ld] %s" +#define MESSAGE_ARG(global, tv, msg) \ + (global).prefix, \ + (global).level_desc[level].level_str, \ + (tv).tv_sec, \ + ((tv).tv_usec / 100), \ + (msg) + g_get_current_time (&tv); - nm_sprintf_buf (s_buf_timestamp, " [%ld.%04ld]", tv.tv_sec, tv.tv_usec / 100); switch (global.log_backend) { #if SYSTEMD_JOURNAL @@ -608,12 +613,7 @@ _nm_log_impl (const char *file, boottime = nm_utils_monotonic_timestamp_as_boottime (now, 1); _iovec_set_format (iov, iov_free, i_field++, "PRIORITY=%d", global.level_desc[level].syslog_level); - _iovec_set_format (iov, iov_free, i_field++, "MESSAGE=" - "%s%-7s%s %s", - global.prefix, - global.level_desc[level].level_str, - s_buf_timestamp, - msg); + _iovec_set_format (iov, iov_free, i_field++, "MESSAGE="MESSAGE_FMT, MESSAGE_ARG (global, tv, msg)); _iovec_set_string (iov, iov_free, i_field++, syslog_identifier_full (&global)); _iovec_set_format (iov, iov_free, i_field++, "SYSLOG_PID=%ld", (long) getpid ()); { @@ -680,18 +680,13 @@ _nm_log_impl (const char *file, } break; #endif + case LOG_BACKEND_SYSLOG: + syslog (global.level_desc[level].syslog_level, + MESSAGE_FMT, MESSAGE_ARG (global, tv, msg)); + break; default: - fullmsg = g_strdup_printf ("%s%-7s%s %s", - global.prefix, - global.level_desc[level].level_str, - s_buf_timestamp, - msg); - - if (global.log_backend == LOG_BACKEND_SYSLOG) - syslog (global.level_desc[level].syslog_level, "%s", fullmsg); - else - g_log (syslog_identifier_domain (&global), global.level_desc[level].g_log_level, "%s", fullmsg); - g_free (fullmsg); + g_log (syslog_identifier_domain (&global), global.level_desc[level].g_log_level, + MESSAGE_FMT, MESSAGE_ARG (global, tv, msg)); break; } From f43b21b71d389fc1c01f3b4683b7fa8e3d69fe12 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 6 Oct 2016 16:55:12 +0200 Subject: [PATCH 2/6] logging: avoid some heap allocations constructing journal logging data --- src/nm-logging.c | 123 +++++++++++++++++++++++++++-------------------- 1 file changed, 72 insertions(+), 51 deletions(-) diff --git a/src/nm-logging.c b/src/nm-logging.c index e824bd17e5..e695a60a25 100644 --- a/src/nm-logging.c +++ b/src/nm-logging.c @@ -40,6 +40,17 @@ #include "nm-errors.h" #include "nm-core-utils.h" +/* often we have some static string where we need to know the maximum length. + * _MAX_LEN() returns @max but adds a debugging assertion that @str is indeed + * shorter then @mac. */ +#define _MAX_LEN(max, str) \ + ({ \ + const char *const _str = (str); \ + \ + nm_assert (_str && strlen (str) < (max)); \ + (max); \ + }) + void (*_nm_logging_clear_platform_logging_cache) (void); static void @@ -524,9 +535,22 @@ nm_logging_get_level (NMLogDomain domain) } #if SYSTEMD_JOURNAL -_nm_printf (4, 5) static void -_iovec_set_format (struct iovec *iov, gboolean *iov_free, int i, const char *format, ...) +_iovec_set (struct iovec *iov, const void *str, gsize len) +{ + iov->iov_base = (void *) str; + iov->iov_len = len; +} + +static void +_iovec_set_string (struct iovec *iov, const char *str) +{ + _iovec_set (iov, str, strlen (str)); +} + +_nm_printf (3, 4) +static void +_iovec_set_format (struct iovec *iov, gpointer *iov_free, const char *format, ...) { va_list ap; char *str; @@ -535,26 +559,24 @@ _iovec_set_format (struct iovec *iov, gboolean *iov_free, int i, const char *for str = g_strdup_vprintf (format, ap); va_end (ap); - iov[i].iov_base = str; - iov[i].iov_len = strlen (str); - iov_free[i] = TRUE; + _iovec_set_string (iov, str); + *iov_free = str; } -static void -_iovec_set_string_l (struct iovec *iov, gboolean *iov_free, int i, const char *str, gsize len) -{ - iov[i].iov_base = (char *) str; - iov[i].iov_len = len; - iov_free[i] = FALSE; -} - -static void -_iovec_set_string (struct iovec *iov, gboolean *iov_free, int i, const char *str) -{ - _iovec_set_string_l (iov, iov_free, i, str, strlen (str)); -} - -#define _iovec_set_literal_string(iov, iov_free, i, str) _iovec_set_string_l ((iov), (iov_free), (i), (""str""), NM_STRLEN (str)) +#define _iovec_set_format_a(iov, reserve_extra, format, ...) \ + G_STMT_START { \ + const gsize _size = (reserve_extra) + (NM_STRLEN (format) + 3); \ + char *const _buf = g_alloca (_size); \ + int _len; \ + \ + _len = g_snprintf (_buf, _size, ""format"", ##__VA_ARGS__);\ + \ + nm_assert (_len >= 0); \ + nm_assert (_len <= _size); \ + nm_assert (_len == strlen (_buf)); \ + \ + _iovec_set ((iov), _buf, _len); \ + } G_STMT_END #endif void @@ -604,23 +626,23 @@ _nm_log_impl (const char *file, { gint64 now, boottime; #define _NUM_MAX_FIELDS_SYSLOG_FACILITY 10 -#define _NUM_FIELDS (10 + _NUM_MAX_FIELDS_SYSLOG_FACILITY) - int i_field = 0; - struct iovec iov[_NUM_FIELDS]; - gboolean iov_free[_NUM_FIELDS]; + struct iovec iov_data[12 + _NUM_MAX_FIELDS_SYSLOG_FACILITY]; + struct iovec *iov = iov_data; + gpointer iov_free_data[3]; + gpointer *iov_free = iov_free_data; + nm_auto_free_gstring GString *s_domain_all = NULL; now = nm_utils_get_monotonic_timestamp_ns (); boottime = nm_utils_monotonic_timestamp_as_boottime (now, 1); - _iovec_set_format (iov, iov_free, i_field++, "PRIORITY=%d", global.level_desc[level].syslog_level); - _iovec_set_format (iov, iov_free, i_field++, "MESSAGE="MESSAGE_FMT, MESSAGE_ARG (global, tv, msg)); - _iovec_set_string (iov, iov_free, i_field++, syslog_identifier_full (&global)); - _iovec_set_format (iov, iov_free, i_field++, "SYSLOG_PID=%ld", (long) getpid ()); + _iovec_set_format_a (iov++, 30, "PRIORITY=%d", global.level_desc[level].syslog_level); + _iovec_set_format (iov++, iov_free++, "MESSAGE="MESSAGE_FMT, MESSAGE_ARG (global, tv, msg)); + _iovec_set_string (iov++, syslog_identifier_full (&global)); + _iovec_set_format_a (iov++, 30, "SYSLOG_PID=%ld", (long) getpid ()); { const LogDesc *diter; int i_domain = _NUM_MAX_FIELDS_SYSLOG_FACILITY; const char *s_domain_1 = NULL; - GString *s_domain_all = NULL; NMLogDomain dom_all = domain; NMLogDomain dom = dom_all & _nm_logging_enabled_state[level]; @@ -635,8 +657,10 @@ _nm_log_impl (const char *file, if (!s_domain_1) s_domain_1 = diter->name; else { - if (!s_domain_all) - s_domain_all = g_string_new (s_domain_1); + if (!s_domain_all) { + s_domain_all = g_string_new ("NM_LOG_DOMAINS="); + g_string_append (s_domain_all, s_domain_1); + } g_string_append_c (s_domain_all, ','); g_string_append (s_domain_all, diter->name); } @@ -644,7 +668,7 @@ _nm_log_impl (const char *file, if (NM_FLAGS_HAS (dom, diter->num)) { if (i_domain > 0) { /* SYSLOG_FACILITY is specified multiple times for each domain that is actually enabled. */ - _iovec_set_format (iov, iov_free, i_field++, "SYSLOG_FACILITY=%s", diter->name); + _iovec_set_format_a (iov++, _MAX_LEN (30, diter->name), "SYSLOG_FACILITY=%s", diter->name); i_domain--; } dom &= ~diter->num; @@ -652,31 +676,28 @@ _nm_log_impl (const char *file, if (!dom && !dom_all) break; } - if (s_domain_all) { - _iovec_set_format (iov, iov_free, i_field++, "NM_LOG_DOMAINS=%s", s_domain_all->str); - g_string_free (s_domain_all, TRUE); - } else - _iovec_set_format (iov, iov_free, i_field++, "NM_LOG_DOMAINS=%s", s_domain_1); + if (s_domain_all) + _iovec_set (iov++, s_domain_all->str, s_domain_all->len); + else + _iovec_set_format_a (iov++, _MAX_LEN (30, s_domain_1), "NM_LOG_DOMAINS=%s", s_domain_1); } - _iovec_set_format (iov, iov_free, i_field++, "NM_LOG_LEVEL=%s", global.level_desc[level].name); + _iovec_set_format_a (iov++, _MAX_LEN (15, global.level_desc[level].name), "NM_LOG_LEVEL=%s", global.level_desc[level].name); if (func) - _iovec_set_format (iov, iov_free, i_field++, "CODE_FUNC=%s", func); - _iovec_set_format (iov, iov_free, i_field++, "CODE_FILE=%s", file ?: ""); - _iovec_set_format (iov, iov_free, i_field++, "CODE_LINE=%u", line); - _iovec_set_format (iov, iov_free, i_field++, "TIMESTAMP_MONOTONIC=%lld.%06lld", (long long) (now / NM_UTILS_NS_PER_SECOND), (long long) ((now % NM_UTILS_NS_PER_SECOND) / 1000)); - _iovec_set_format (iov, iov_free, i_field++, "TIMESTAMP_BOOTTIME=%lld.%06lld", (long long) (boottime / NM_UTILS_NS_PER_SECOND), (long long) ((boottime % NM_UTILS_NS_PER_SECOND) / 1000)); + _iovec_set_format (iov++, iov_free++, "CODE_FUNC=%s", func); + _iovec_set_format (iov++, iov_free++, "CODE_FILE=%s", file ?: ""); + _iovec_set_format_a (iov++, 20, "CODE_LINE=%u", line); + _iovec_set_format_a (iov++, 60, "TIMESTAMP_MONOTONIC=%lld.%06lld", (long long) (now / NM_UTILS_NS_PER_SECOND), (long long) ((now % NM_UTILS_NS_PER_SECOND) / 1000)); + _iovec_set_format_a (iov++, 60, "TIMESTAMP_BOOTTIME=%lld.%06lld", (long long) (boottime / NM_UTILS_NS_PER_SECOND), (long long) ((boottime % NM_UTILS_NS_PER_SECOND) / 1000)); if (error != 0) - _iovec_set_format (iov, iov_free, i_field++, "ERRNO=%d", error); + _iovec_set_format_a (iov++, 30, "ERRNO=%d", error); - nm_assert (i_field <= G_N_ELEMENTS (iov)); + nm_assert (iov <= &iov_data[G_N_ELEMENTS (iov_data)]); + nm_assert (iov_free <= &iov_free_data[G_N_ELEMENTS (iov_free_data)]); - sd_journal_sendv (iov, i_field); + sd_journal_sendv (iov_data, iov - iov_data); - for (; i_field > 0; ) { - i_field--; - if (iov_free[i_field]) - g_free (iov[i_field].iov_base); - } + for (; --iov_free >= iov_free_data; ) + g_free (*iov_free); } break; #endif From 64951f07fb39e1c88448ba2ad72a5e710712c89d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 6 Oct 2016 21:28:40 +0200 Subject: [PATCH 3/6] logging: remove LOGD_HW alias for LOGD_PLATFORM Since commit 1495853e01299d1eb33d4eb10b91e37dcf855cc8, LOGD_HW is renamed to LOGD_PLATFORM. Remove the internal usage of the deprecated name. --- src/devices/adsl/nm-atm-manager.c | 14 +++++------ src/devices/nm-device-bond.c | 2 +- src/devices/nm-device-ethernet.c | 14 +++++------ src/devices/nm-device-factory.c | 18 +++++++-------- src/devices/nm-device-ip-tunnel.c | 8 +++---- src/devices/nm-device-macvlan.c | 2 +- src/devices/nm-device-tun.c | 2 +- src/devices/nm-device-veth.c | 2 +- src/devices/nm-device-vxlan.c | 2 +- src/devices/nm-device.c | 30 ++++++++++++------------ src/devices/wifi/nm-device-wifi.c | 2 +- src/devices/wifi/nm-wifi-factory.c | 2 +- src/devices/wwan/nm-modem.c | 4 ++-- src/nm-logging.h | 1 - src/nm-manager.c | 6 ++--- src/nm-rfkill-manager.c | 2 +- src/platform/wifi/wifi-utils-nl80211.c | 16 ++++++------- src/platform/wifi/wifi-utils-wext.c | 32 +++++++++++++------------- 18 files changed, 79 insertions(+), 80 deletions(-) diff --git a/src/devices/adsl/nm-atm-manager.c b/src/devices/adsl/nm-atm-manager.c index 5decea5200..36f9635266 100644 --- a/src/devices/adsl/nm-atm-manager.c +++ b/src/devices/adsl/nm-atm-manager.c @@ -90,7 +90,7 @@ dev_get_attrs (GUdevDevice *udev_device, path = g_udev_device_get_sysfs_path (udev_device); if (!path) { - nm_log_warn (LOGD_HW, "couldn't determine device path; ignoring..."); + nm_log_warn (LOGD_PLATFORM, "couldn't determine device path; ignoring..."); return FALSE; } @@ -132,11 +132,11 @@ adsl_add (NMAtmManager *self, GUdevDevice *udev_device) ifname = g_udev_device_get_name (udev_device); if (!ifname) { - nm_log_warn (LOGD_HW, "failed to get device's interface name"); + nm_log_warn (LOGD_PLATFORM, "failed to get device's interface name"); return; } - nm_log_dbg (LOGD_HW, "(%s): found ATM device", ifname); + nm_log_dbg (LOGD_PLATFORM, "(%s): found ATM device", ifname); atm_index_path = g_strdup_printf ("/sys/class/atm/%s/atmindex", NM_ASSERT_VALID_PATH_COMPONENT (ifname)); @@ -145,12 +145,12 @@ adsl_add (NMAtmManager *self, GUdevDevice *udev_device) 10, 0, G_MAXINT, -1); if (atm_index < 0) { - nm_log_warn (LOGD_HW, "(%s): failed to get ATM index", ifname); + nm_log_warn (LOGD_PLATFORM, "(%s): failed to get ATM index", ifname); return; } if (!dev_get_attrs (udev_device, &sysfs_path, &driver)) { - nm_log_warn (LOGD_HW, "(%s): failed to get ATM attributes", ifname); + nm_log_warn (LOGD_PLATFORM, "(%s): failed to get ATM attributes", ifname); return; } @@ -175,7 +175,7 @@ adsl_remove (NMAtmManager *self, GUdevDevice *udev_device) const char *iface = g_udev_device_get_name (udev_device); GSList *iter; - nm_log_dbg (LOGD_HW, "(%s): removing ATM device", iface); + nm_log_dbg (LOGD_PLATFORM, "(%s): removing ATM device", iface); for (iter = priv->devices; iter; iter = iter->next) { NMDevice *device = iter->data; @@ -232,7 +232,7 @@ handle_uevent (GUdevClient *client, ifindex = g_udev_device_get_property (device, "IFINDEX"); seqnum = g_udev_device_get_seqnum (device); - nm_log_dbg (LOGD_HW, "UDEV event: action '%s' subsys '%s' device '%s' (%s); seqnum=%" G_GUINT64_FORMAT, + nm_log_dbg (LOGD_PLATFORM, "UDEV event: action '%s' subsys '%s' device '%s' (%s); seqnum=%" G_GUINT64_FORMAT, action, subsys, g_udev_device_get_name (device), ifindex ? ifindex : "unknown", seqnum); if (!strcmp (action, "add")) diff --git a/src/devices/nm-device-bond.c b/src/devices/nm-device-bond.c index 6d3a2facad..2d1b986d87 100644 --- a/src/devices/nm-device-bond.c +++ b/src/devices/nm-device-bond.c @@ -134,7 +134,7 @@ set_bond_attr (NMDevice *device, NMBondMode mode, const char *attr, const char * ret = nm_platform_sysctl_master_set_option (NM_PLATFORM_GET, ifindex, attr, value); if (!ret) - _LOGW (LOGD_HW, "failed to set bonding attribute '%s' to '%s'", attr, value); + _LOGW (LOGD_PLATFORM, "failed to set bonding attribute '%s' to '%s'", attr, value); return ret; } diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index e7d43763b5..83d0af1fe6 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -187,7 +187,7 @@ _update_s390_subchannels (NMDeviceEthernet *self) parent_path = g_udev_device_get_sysfs_path (parent); dir = g_dir_open (parent_path, 0, &error); if (!dir) { - _LOGW (LOGD_DEVICE | LOGD_HW, "update-s390: failed to open directory '%s': %s", + _LOGW (LOGD_DEVICE | LOGD_PLATFORM, "update-s390: failed to open directory '%s': %s", parent_path, error->message); g_clear_error (&error); return; @@ -217,11 +217,11 @@ _update_s390_subchannels (NMDeviceEthernet *self) g_hash_table_insert (priv->s390_options, g_strdup (item), value); value = NULL; } else - _LOGW (LOGD_DEVICE | LOGD_HW, "update-s390: error reading %s", path); + _LOGW (LOGD_DEVICE | LOGD_PLATFORM, "update-s390: error reading %s", path); } if (error) { - _LOGW (LOGD_DEVICE | LOGD_HW, "update-s390: failed reading sysfs for %s (%s)", item, error->message); + _LOGW (LOGD_DEVICE | LOGD_PLATFORM, "update-s390: failed reading sysfs for %s (%s)", item, error->message); g_clear_error (&error); } } @@ -246,7 +246,7 @@ _update_s390_subchannels (NMDeviceEthernet *self) priv->subchannels_dbus[2] = g_strdup (priv->subchan3); priv->subchannels_dbus[3] = NULL; - _LOGI (LOGD_DEVICE | LOGD_HW, "update-s390: found s390 '%s' subchannels [%s]", + _LOGI (LOGD_DEVICE | LOGD_PLATFORM, "update-s390: found s390 '%s' subchannels [%s]", nm_device_get_driver ((NMDevice *) self) ?: "(unknown driver)", priv->subchannels); @@ -310,7 +310,7 @@ get_generic_capabilities (NMDevice *device) if (nm_platform_link_supports_carrier_detect (NM_PLATFORM_GET, nm_device_get_ifindex (device))) return NM_DEVICE_CAP_CARRIER_DETECT; else { - _LOGI (LOGD_HW, "driver '%s' does not support carrier detection.", + _LOGI (LOGD_PLATFORM, "driver '%s' does not support carrier detection.", nm_device_get_driver (device)); return NM_DEVICE_CAP_NONE; } @@ -1323,7 +1323,7 @@ deactivate (NMDevice *device) s_dcb = (NMSettingDcb *) nm_device_get_applied_setting (device, NM_TYPE_SETTING_DCB); if (s_dcb) { if (!nm_dcb_cleanup (nm_device_get_iface (device), &error)) { - _LOGW (LOGD_DEVICE | LOGD_HW, "failed to disable DCB/FCoE: %s", + _LOGW (LOGD_DEVICE | LOGD_PLATFORM, "failed to disable DCB/FCoE: %s", error->message); g_clear_error (&error); } @@ -1528,7 +1528,7 @@ get_link_speed (NMDevice *device) priv->speed = speed; _notify (self, PROP_SPEED); - _LOGD (LOGD_HW | LOGD_ETHER, "speed is now %d Mb/s", speed); + _LOGD (LOGD_PLATFORM | LOGD_ETHER, "speed is now %d Mb/s", speed); } static void diff --git a/src/devices/nm-device-factory.c b/src/devices/nm-device-factory.c index 840328437c..d75de4963c 100644 --- a/src/devices/nm-device-factory.c +++ b/src/devices/nm-device-factory.c @@ -369,7 +369,7 @@ read_device_factory_paths (void) dir = g_dir_open (NMPLUGINDIR, 0, &error); if (!dir) { - nm_log_warn (LOGD_HW, "device plugin: failed to open directory %s: %s", + nm_log_warn (LOGD_PLATFORM, "device plugin: failed to open directory %s: %s", NMPLUGINDIR, error->message); g_clear_error (&error); @@ -391,17 +391,17 @@ read_device_factory_paths (void) if (stat (data.path, &data.st) != 0) { errsv = errno; - nm_log_warn (LOGD_HW, "device plugin: skip invalid file %s (error during stat: %s)", data.path, strerror (errsv)); + nm_log_warn (LOGD_PLATFORM, "device plugin: skip invalid file %s (error during stat: %s)", data.path, strerror (errsv)); goto NEXT; } if (!S_ISREG (data.st.st_mode)) goto NEXT; if (data.st.st_uid != 0) { - nm_log_warn (LOGD_HW, "device plugin: skip invalid file %s (file must be owned by root)", data.path); + nm_log_warn (LOGD_PLATFORM, "device plugin: skip invalid file %s (file must be owned by root)", data.path); goto NEXT; } if (data.st.st_mode & (S_IWGRP | S_IWOTH | S_ISUID)) { - nm_log_warn (LOGD_HW, "device plugin: skip invalid file %s (invalid file permissions)", data.path); + nm_log_warn (LOGD_PLATFORM, "device plugin: skip invalid file %s (invalid file permissions)", data.path); goto NEXT; } @@ -443,7 +443,7 @@ _add_factory (NMDeviceFactory *factory, if (check_duplicates) { found = find_factory (link_types, setting_types); if (found) { - nm_log_warn (LOGD_HW, "Loading device plugin failed: multiple plugins " + nm_log_warn (LOGD_PLATFORM, "Loading device plugin failed: multiple plugins " "for same type (using '%s' instead of '%s')", (char *) g_object_get_data (G_OBJECT (found), PLUGIN_PATH_TAG), path); @@ -459,7 +459,7 @@ _add_factory (NMDeviceFactory *factory, callback (factory, user_data); - nm_log_info (LOGD_HW, "Loaded device plugin: %s (%s)", G_OBJECT_TYPE_NAME (factory), path); + nm_log_info (LOGD_PLATFORM, "Loaded device plugin: %s (%s)", G_OBJECT_TYPE_NAME (factory), path); return TRUE; } @@ -502,12 +502,12 @@ nm_device_factory_manager_load_factories (NMDeviceFactoryManagerFactoryFunc call plugin = g_module_open (*path, G_MODULE_BIND_LOCAL); if (!plugin) { - nm_log_warn (LOGD_HW, "(%s): failed to load plugin: %s", item, g_module_error ()); + nm_log_warn (LOGD_PLATFORM, "(%s): failed to load plugin: %s", item, g_module_error ()); continue; } if (!g_module_symbol (plugin, "nm_device_factory_create", (gpointer) &create_func)) { - nm_log_warn (LOGD_HW, "(%s): failed to find device factory creator: %s", item, g_module_error ()); + nm_log_warn (LOGD_PLATFORM, "(%s): failed to find device factory creator: %s", item, g_module_error ()); g_module_close (plugin); continue; } @@ -518,7 +518,7 @@ nm_device_factory_manager_load_factories (NMDeviceFactoryManagerFactoryFunc call factory = create_func (&error); if (!factory) { - nm_log_warn (LOGD_HW, "(%s): failed to initialize device factory: %s", + nm_log_warn (LOGD_PLATFORM, "(%s): failed to initialize device factory: %s", item, NM_G_ERROR_MSG (error)); g_clear_error (&error); continue; diff --git a/src/devices/nm-device-ip-tunnel.c b/src/devices/nm-device-ip-tunnel.c index 1bb9f2f069..036e3ea4d7 100644 --- a/src/devices/nm-device-ip-tunnel.c +++ b/src/devices/nm-device-ip-tunnel.c @@ -167,7 +167,7 @@ clear: lnk = nm_platform_link_get_lnk_gre (NM_PLATFORM_GET, ifindex, NULL); if (!lnk) { - _LOGW (LOGD_HW, "could not read %s properties", "gre"); + _LOGW (LOGD_PLATFORM, "could not read %s properties", "gre"); goto clear; } @@ -212,7 +212,7 @@ clear: lnk = nm_platform_link_get_lnk_sit (NM_PLATFORM_GET, ifindex, NULL); if (!lnk) { - _LOGW (LOGD_HW, "could not read %s properties", "sit"); + _LOGW (LOGD_PLATFORM, "could not read %s properties", "sit"); goto clear; } @@ -227,7 +227,7 @@ clear: lnk = nm_platform_link_get_lnk_ipip (NM_PLATFORM_GET, ifindex, NULL); if (!lnk) { - _LOGW (LOGD_HW, "could not read %s properties", "ipip"); + _LOGW (LOGD_PLATFORM, "could not read %s properties", "ipip"); goto clear; } @@ -243,7 +243,7 @@ clear: lnk = nm_platform_link_get_lnk_ip6tnl (NM_PLATFORM_GET, ifindex, NULL); if (!lnk) { - _LOGW (LOGD_HW, "could not read %s properties", "ip6tnl"); + _LOGW (LOGD_PLATFORM, "could not read %s properties", "ip6tnl"); goto clear; } diff --git a/src/devices/nm-device-macvlan.c b/src/devices/nm-device-macvlan.c index 6c01a9b6a6..2cfd2492a6 100644 --- a/src/devices/nm-device-macvlan.c +++ b/src/devices/nm-device-macvlan.c @@ -190,7 +190,7 @@ update_properties (NMDevice *device) props = nm_platform_link_get_lnk_macvlan (NM_PLATFORM_GET, nm_device_get_ifindex (device), &plink); if (!props) { - _LOGW (LOGD_HW, "could not get %s properties", priv->props.tap ? "macvtap" : "macvlan"); + _LOGW (LOGD_PLATFORM, "could not get %s properties", priv->props.tap ? "macvtap" : "macvlan"); return; } diff --git a/src/devices/nm-device-tun.c b/src/devices/nm-device-tun.c index 1870b5fdf4..2bed672b5f 100644 --- a/src/devices/nm-device-tun.c +++ b/src/devices/nm-device-tun.c @@ -182,7 +182,7 @@ update_connection (NMDevice *device, NMConnection *connection) } if (!nm_platform_link_tun_get_properties (NM_PLATFORM_GET, nm_device_get_ifindex (device), &props)) { - _LOGW (LOGD_HW, "failed to get TUN interface info while updating connection."); + _LOGW (LOGD_PLATFORM, "failed to get TUN interface info while updating connection."); return; } diff --git a/src/devices/nm-device-veth.c b/src/devices/nm-device-veth.c index 33078d786c..0407c2a47e 100644 --- a/src/devices/nm-device-veth.c +++ b/src/devices/nm-device-veth.c @@ -91,7 +91,7 @@ get_peer (NMDeviceVeth *self) return priv->peer; if (!nm_platform_link_veth_get_properties (NM_PLATFORM_GET, nm_device_get_ifindex (device), &peer_ifindex)) { - _LOGW (LOGD_HW, "could not read veth properties"); + _LOGW (LOGD_PLATFORM, "could not read veth properties"); return NULL; } diff --git a/src/devices/nm-device-vxlan.c b/src/devices/nm-device-vxlan.c index 583cb6677b..1113a5b8b1 100644 --- a/src/devices/nm-device-vxlan.c +++ b/src/devices/nm-device-vxlan.c @@ -92,7 +92,7 @@ update_properties (NMDevice *device) props = nm_platform_link_get_lnk_vxlan (NM_PLATFORM_GET, nm_device_get_ifindex (device), NULL); if (!props) { - _LOGW (LOGD_HW, "could not get vxlan properties"); + _LOGW (LOGD_PLATFORM, "could not get vxlan properties"); return; } diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 64b0065e8d..55e1ff5344 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -798,7 +798,7 @@ nm_device_set_ip_iface (NMDevice *self, const char *iface) nm_platform_link_set_up (NM_PLATFORM_GET, priv->ip_ifindex, NULL); } else { /* Device IP interface must always be a kernel network interface */ - _LOGW (LOGD_HW, "failed to look up interface index"); + _LOGW (LOGD_PLATFORM, "failed to look up interface index"); } } @@ -941,7 +941,7 @@ get_ip_iface_identifier (NMDevice *self, NMUtilsIPv6IfaceId *out_iid) priv->dev_id, out_iid); if (!success) { - _LOGW (LOGD_HW, "failed to generate interface identifier " + _LOGW (LOGD_PLATFORM, "failed to generate interface identifier " "for link type %u hwaddr_len %u", pllink->type, (unsigned) pllink->addr.len); } return success; @@ -2340,7 +2340,7 @@ realize_start_setup (NMDevice *self, const NMPlatformLink *plink) if (nm_device_has_capability (self, NM_DEVICE_CAP_CARRIER_DETECT)) { check_carrier (self); - _LOGD (LOGD_HW, + _LOGD (LOGD_PLATFORM, "carrier is %s%s", priv->carrier ? "ON" : "OFF", priv->ignore_carrier ? " (but ignored)" : ""); @@ -9203,12 +9203,12 @@ nm_device_bring_up (NMDevice *self, gboolean block, gboolean *no_firmware) NM_SET_OUT (no_firmware, FALSE); if (!nm_device_get_enabled (self)) { - _LOGD (LOGD_HW, "bringing up device ignored due to disabled"); + _LOGD (LOGD_PLATFORM, "bringing up device ignored due to disabled"); return FALSE; } ifindex = nm_device_get_ip_ifindex (self); - _LOGD (LOGD_HW, "bringing up device %d", ifindex); + _LOGD (LOGD_PLATFORM, "bringing up device %d", ifindex); if (ifindex <= 0) { /* assume success. */ } else { @@ -9234,9 +9234,9 @@ nm_device_bring_up (NMDevice *self, gboolean block, gboolean *no_firmware) if (!device_is_up) { if (block) - _LOGW (LOGD_HW, "device not up after timeout!"); + _LOGW (LOGD_PLATFORM, "device not up after timeout!"); else - _LOGD (LOGD_HW, "device not up immediately"); + _LOGD (LOGD_PLATFORM, "device not up immediately"); return FALSE; } @@ -9285,7 +9285,7 @@ nm_device_take_down (NMDevice *self, gboolean block) g_return_if_fail (NM_IS_DEVICE (self)); ifindex = nm_device_get_ip_ifindex (self); - _LOGD (LOGD_HW, "taking down device %d", ifindex); + _LOGD (LOGD_PLATFORM, "taking down device %d", ifindex); if (ifindex <= 0) { /* devices without ifindex are always up. */ return; @@ -9308,9 +9308,9 @@ nm_device_take_down (NMDevice *self, gboolean block) if (device_is_up) { if (block) - _LOGW (LOGD_HW, "device not down after timeout!"); + _LOGW (LOGD_PLATFORM, "device not down after timeout!"); else - _LOGD (LOGD_HW, "device not down immediately"); + _LOGD (LOGD_PLATFORM, "device not down immediately"); } } @@ -11285,7 +11285,7 @@ _set_state_full (NMDevice *self, if (reason != NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED) { if (old_state == NM_DEVICE_STATE_UNMANAGED || priv->firmware_missing) { if (!nm_device_bring_up (self, TRUE, &no_firmware) && no_firmware) - _LOGW (LOGD_HW, "firmware may be missing."); + _LOGW (LOGD_PLATFORM, "firmware may be missing."); nm_device_set_firmware_missing (self, no_firmware ? TRUE : FALSE); } @@ -11679,7 +11679,7 @@ nm_device_update_hw_address (NMDevice *self) g_free (priv->hw_addr); priv->hw_addr = nm_utils_hwaddr_ntoa (hwaddr, hwaddrlen); - _LOGD (LOGD_HW | LOGD_DEVICE, "hw-addr: hardware address now %s", priv->hw_addr); + _LOGD (LOGD_PLATFORM | LOGD_DEVICE, "hw-addr: hardware address now %s", priv->hw_addr); _notify (self, PROP_HW_ADDRESS); if ( !priv->hw_addr_initial @@ -11696,11 +11696,11 @@ nm_device_update_hw_address (NMDevice *self) } else { /* Invalid or no hardware address */ if (priv->hw_addr_len != 0) { - _LOGD (LOGD_HW | LOGD_DEVICE, + _LOGD (LOGD_PLATFORM | LOGD_DEVICE, "hw-addr: failed reading current MAC address (stay with %s)", priv->hw_addr); } else { - _LOGD (LOGD_HW | LOGD_DEVICE, + _LOGD (LOGD_PLATFORM | LOGD_DEVICE, "hw-addr: failed reading current MAC address"); } } @@ -11760,7 +11760,7 @@ nm_device_update_permanent_hw_address (NMDevice *self) * * In some cases it might be necessary to know whether this is a "real" or * a temporary address (fake). */ - _LOGD (LOGD_HW | LOGD_ETHER, "hw-addr: %s (use current: %s)", + _LOGD (LOGD_PLATFORM | LOGD_ETHER, "hw-addr: %s (use current: %s)", success_read ? "read HW addr length of permanent MAC address differs" : "unable to read permanent MAC address", diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 477af4aa23..bfb0780477 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -203,7 +203,7 @@ constructed (GObject *object) G_OBJECT_CLASS (nm_device_wifi_parent_class)->constructed (object); if (priv->capabilities & NM_WIFI_DEVICE_CAP_AP) - _LOGI (LOGD_HW | LOGD_WIFI, "driver supports Access Point (AP) mode"); + _LOGI (LOGD_PLATFORM | LOGD_WIFI, "driver supports Access Point (AP) mode"); /* Connect to the supplicant manager */ priv->sup_mgr = g_object_ref (nm_supplicant_manager_get ()); diff --git a/src/devices/wifi/nm-wifi-factory.c b/src/devices/wifi/nm-wifi-factory.c index 1bd0756a48..0622a834b4 100644 --- a/src/devices/wifi/nm-wifi-factory.c +++ b/src/devices/wifi/nm-wifi-factory.c @@ -79,7 +79,7 @@ create_device (NMDeviceFactory *factory, if (!nm_platform_wifi_get_capabilities (NM_PLATFORM_GET, plink->ifindex, &capabilities)) { - nm_log_warn (LOGD_HW | LOGD_WIFI, "(%s) failed to initialize Wi-Fi driver for ifindex %d", iface, plink->ifindex); + nm_log_warn (LOGD_PLATFORM | LOGD_WIFI, "(%s) failed to initialize Wi-Fi driver for ifindex %d", iface, plink->ifindex); return NULL; } diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c index 9897424466..aeb8a987f5 100644 --- a/src/devices/wwan/nm-modem.c +++ b/src/devices/wwan/nm-modem.c @@ -1474,12 +1474,12 @@ constructor (GType type, priv = NM_MODEM_GET_PRIVATE ((NMModem *) object); if (!priv->data_port && !priv->control_port) { - nm_log_err (LOGD_HW, "neither modem command nor data interface provided"); + nm_log_err (LOGD_PLATFORM, "neither modem command nor data interface provided"); goto err; } if (!priv->path) { - nm_log_err (LOGD_HW, "D-Bus path not provided"); + nm_log_err (LOGD_PLATFORM, "D-Bus path not provided"); goto err; } diff --git a/src/nm-logging.h b/src/nm-logging.h index 917a2ee0be..59f2ad2b05 100644 --- a/src/nm-logging.h +++ b/src/nm-logging.h @@ -79,7 +79,6 @@ typedef enum { /*< skip >*/ /* aliases: */ LOGD_DHCP = LOGD_DHCP4 | LOGD_DHCP6, LOGD_IP = LOGD_IP4 | LOGD_IP6, - LOGD_HW = LOGD_PLATFORM, } NMLogDomain; /* Log levels */ diff --git a/src/nm-manager.c b/src/nm-manager.c index 4c542a53d6..74efb5dda4 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -2131,10 +2131,10 @@ platform_link_added (NMManager *self, device = nm_device_factory_create_device (factory, plink->name, plink, NULL, &ignore, &error); if (!device) { if (!ignore) { - _LOGW (LOGD_HW, "%s: factory failed to create device: %s", + _LOGW (LOGD_PLATFORM, "%s: factory failed to create device: %s", plink->name, error->message); } else { - _LOGD (LOGD_HW, "%s: factory failed to create device: %s", + _LOGD (LOGD_PLATFORM, "%s: factory failed to create device: %s", plink->name, error->message); } return; @@ -2150,7 +2150,7 @@ platform_link_added (NMManager *self, case NM_LINK_TYPE_OLPC_MESH: case NM_LINK_TYPE_TEAM: case NM_LINK_TYPE_WIFI: - _LOGI (LOGD_HW, "(%s): '%s' plugin not available; creating generic device", + _LOGI (LOGD_PLATFORM, "(%s): '%s' plugin not available; creating generic device", plink->name, nm_link_type_to_string (plink->type)); nm_plugin_missing = TRUE; /* fall through */ diff --git a/src/nm-rfkill-manager.c b/src/nm-rfkill-manager.c index 14346c32a2..36afd35ec7 100644 --- a/src/nm-rfkill-manager.c +++ b/src/nm-rfkill-manager.c @@ -351,7 +351,7 @@ handle_uevent (GUdevClient *client, subsys = g_udev_device_get_subsystem (device); g_return_if_fail (!g_strcmp0 (subsys, "rfkill")); - nm_log_dbg (LOGD_HW, "udev rfkill event: action '%s' device '%s'", + nm_log_dbg (LOGD_PLATFORM, "udev rfkill event: action '%s' device '%s'", action, g_udev_device_get_name (device)); if (!strcmp (action, "add")) diff --git a/src/platform/wifi/wifi-utils-nl80211.c b/src/platform/wifi/wifi-utils-nl80211.c index 79f217a8d5..2e222eb801 100644 --- a/src/platform/wifi/wifi-utils-nl80211.c +++ b/src/platform/wifi/wifi-utils-nl80211.c @@ -1003,7 +1003,7 @@ static int nl80211_wiphy_info_handler (struct nl_msg *msg, void *arg) case WLAN_CIPHER_SUITE_SMS4: break; default: - nm_log_dbg (LOGD_HW | LOGD_WIFI, "Don't know the meaning of NL80211_ATTR_CIPHER_SUITE %#8.8x.", ciphers[i]); + nm_log_dbg (LOGD_PLATFORM | LOGD_WIFI, "Don't know the meaning of NL80211_ATTR_CIPHER_SUITE %#8.8x.", ciphers[i]); break; } } @@ -1071,42 +1071,42 @@ wifi_nl80211_init (const char *iface, int ifindex) if (nl80211_send_and_recv (nl80211, msg, nl80211_wiphy_info_handler, &device_info) < 0) { - nm_log_dbg (LOGD_HW | LOGD_WIFI, + nm_log_dbg (LOGD_PLATFORM | LOGD_WIFI, "(%s): NL80211_CMD_GET_WIPHY request failed", nl80211->parent.iface); goto error; } if (!device_info.success) { - nm_log_dbg (LOGD_HW | LOGD_WIFI, + nm_log_dbg (LOGD_PLATFORM | LOGD_WIFI, "(%s): NL80211_CMD_GET_WIPHY request indicated failure", nl80211->parent.iface); goto error; } if (!device_info.supported) { - nm_log_dbg (LOGD_HW | LOGD_WIFI, + nm_log_dbg (LOGD_PLATFORM | LOGD_WIFI, "(%s): driver does not fully support nl80211, falling back to WEXT", nl80211->parent.iface); goto error; } if (!device_info.can_scan_ssid) { - nm_log_err (LOGD_HW | LOGD_WIFI, + nm_log_err (LOGD_PLATFORM | LOGD_WIFI, "(%s): driver does not support SSID scans", nl80211->parent.iface); goto error; } if (device_info.num_freqs == 0 || device_info.freqs == NULL) { - nm_log_err (LOGD_HW | LOGD_WIFI, + nm_log_err (LOGD_PLATFORM | LOGD_WIFI, "(%s): driver reports no supported frequencies", nl80211->parent.iface); goto error; } if (device_info.caps == 0) { - nm_log_err (LOGD_HW | LOGD_WIFI, + nm_log_err (LOGD_PLATFORM | LOGD_WIFI, "(%s): driver doesn't report support of any encryption", nl80211->parent.iface); goto error; @@ -1120,7 +1120,7 @@ wifi_nl80211_init (const char *iface, int ifindex) if (device_info.can_wowlan) nl80211->parent.get_wowlan = wifi_nl80211_get_wowlan; - nm_log_info (LOGD_HW | LOGD_WIFI, + nm_log_info (LOGD_PLATFORM | LOGD_WIFI, "(%s): using nl80211 for WiFi device control", nl80211->parent.iface); diff --git a/src/platform/wifi/wifi-utils-wext.c b/src/platform/wifi/wifi-utils-wext.c index 002ac6aae6..df1d989c6b 100644 --- a/src/platform/wifi/wifi-utils-wext.c +++ b/src/platform/wifi/wifi-utils-wext.c @@ -105,7 +105,7 @@ wifi_wext_get_mode (WifiData *data) if (ioctl (wext->fd, SIOCGIWMODE, &wrq) < 0) { if (errno != ENODEV) { - nm_log_warn (LOGD_HW | LOGD_WIFI, + nm_log_warn (LOGD_PLATFORM | LOGD_WIFI, "(%s): error %d getting card mode", wext->parent.iface, errno); } @@ -154,7 +154,7 @@ wifi_wext_set_mode (WifiData *data, const NM80211Mode mode) nm_utils_ifname_cpy (wrq.ifr_name, wext->parent.iface); if (ioctl (wext->fd, SIOCSIWMODE, &wrq) < 0) { if (errno != ENODEV) { - nm_log_err (LOGD_HW | LOGD_WIFI, "(%s): error setting mode %d", + nm_log_err (LOGD_PLATFORM | LOGD_WIFI, "(%s): error setting mode %d", wext->parent.iface, mode); } return FALSE; @@ -178,7 +178,7 @@ wifi_wext_set_powersave (WifiData *data, guint32 powersave) nm_utils_ifname_cpy (wrq.ifr_name, wext->parent.iface); if (ioctl (wext->fd, SIOCSIWPOWER, &wrq) < 0) { if (errno != ENODEV) { - nm_log_err (LOGD_HW | LOGD_WIFI, "(%s): error setting powersave %" G_GUINT32_FORMAT, + nm_log_err (LOGD_PLATFORM | LOGD_WIFI, "(%s): error setting powersave %" G_GUINT32_FORMAT, wext->parent.iface, powersave); } return FALSE; @@ -196,7 +196,7 @@ wifi_wext_get_freq (WifiData *data) memset (&wrq, 0, sizeof (struct iwreq)); nm_utils_ifname_cpy (wrq.ifr_name, wext->parent.iface); if (ioctl (wext->fd, SIOCGIWFREQ, &wrq) < 0) { - nm_log_warn (LOGD_HW | LOGD_WIFI, + nm_log_warn (LOGD_PLATFORM | LOGD_WIFI, "(%s): error getting frequency: %s", wext->parent.iface, strerror (errno)); return 0; @@ -230,7 +230,7 @@ wifi_wext_get_bssid (WifiData *data, guint8 *out_bssid) memset (&wrq, 0, sizeof (wrq)); nm_utils_ifname_cpy (wrq.ifr_name, wext->parent.iface); if (ioctl (wext->fd, SIOCGIWAP, &wrq) < 0) { - nm_log_warn (LOGD_HW | LOGD_WIFI, + nm_log_warn (LOGD_PLATFORM | LOGD_WIFI, "(%s): error getting associated BSSID: %s", wext->parent.iface, strerror (errno)); return FALSE; @@ -360,7 +360,7 @@ wifi_wext_get_qual (WifiData *data) nm_utils_ifname_cpy (wrq.ifr_name, wext->parent.iface); if (ioctl (wext->fd, SIOCGIWSTATS, &wrq) < 0) { - nm_log_warn (LOGD_HW | LOGD_WIFI, + nm_log_warn (LOGD_PLATFORM | LOGD_WIFI, "(%s): error getting signal strength: %s", wext->parent.iface, strerror (errno)); return -1; @@ -403,7 +403,7 @@ wifi_wext_set_mesh_channel (WifiData *data, guint32 channel) } if (ioctl (wext->fd, SIOCSIWFREQ, &wrq) < 0) { - nm_log_err (LOGD_HW | LOGD_WIFI | LOGD_OLPC, + nm_log_err (LOGD_PLATFORM | LOGD_WIFI | LOGD_OLPC, "(%s): error setting channel to %d: %s", wext->parent.iface, channel, strerror (errno)); return FALSE; @@ -431,7 +431,7 @@ wifi_wext_set_mesh_ssid (WifiData *data, const guint8 *ssid, gsize len) return TRUE; if (errno != ENODEV) { - nm_log_err (LOGD_HW | LOGD_WIFI | LOGD_OLPC, + nm_log_err (LOGD_PLATFORM | LOGD_WIFI | LOGD_OLPC, "(%s): error setting SSID to '%s': %s", wext->parent.iface, ssid ? nm_utils_escape_ssid (ssid, len) : "(null)", @@ -482,7 +482,7 @@ wext_get_range (WifiDataWext *wext, success = TRUE; break; } else if (errno != EAGAIN) { - nm_log_err (LOGD_HW | LOGD_WIFI, + nm_log_err (LOGD_PLATFORM | LOGD_WIFI, "(%s): couldn't get driver range information (%d).", wext->parent.iface, errno); break; @@ -492,7 +492,7 @@ wext_get_range (WifiDataWext *wext, } if (i <= 0) { - nm_log_warn (LOGD_HW | LOGD_WIFI, + nm_log_warn (LOGD_PLATFORM | LOGD_WIFI, "(%s): driver took too long to respond to IWRANGE query.", wext->parent.iface); } @@ -583,13 +583,13 @@ wifi_wext_init (const char *iface, int ifindex, gboolean check_scan) memset (&range, 0, sizeof (struct iw_range)); if (wext_get_range (wext, &range, &response_len) == FALSE) { - nm_log_info (LOGD_HW | LOGD_WIFI, "(%s): driver WEXT range request failed", + nm_log_info (LOGD_PLATFORM | LOGD_WIFI, "(%s): driver WEXT range request failed", wext->parent.iface); goto error; } if ((response_len < 300) || (range.we_version_compiled < 21)) { - nm_log_info (LOGD_HW | LOGD_WIFI, + nm_log_info (LOGD_PLATFORM | LOGD_WIFI, "(%s): driver WEXT version too old (got %d, expected >= 21)", wext->parent.iface, range.we_version_compiled); @@ -613,7 +613,7 @@ wifi_wext_init (const char *iface, int ifindex, gboolean check_scan) /* Check for scanning capability; cards that can't scan are not supported */ if (check_scan && (wext_can_scan (wext) == FALSE)) { - nm_log_info (LOGD_HW | LOGD_WIFI, + nm_log_info (LOGD_PLATFORM | LOGD_WIFI, "(%s): drivers that cannot scan are unsupported", wext->parent.iface); goto error; @@ -625,12 +625,12 @@ wifi_wext_init (const char *iface, int ifindex, gboolean check_scan) */ scan_capa_range = (struct iw_range_with_scan_capa *) ⦥ if (scan_capa_range->scan_capa & NM_IW_SCAN_CAPA_ESSID) { - nm_log_info (LOGD_HW | LOGD_WIFI, + nm_log_info (LOGD_PLATFORM | LOGD_WIFI, "(%s): driver supports SSID scans (scan_capa 0x%02X).", wext->parent.iface, scan_capa_range->scan_capa); } else { - nm_log_info (LOGD_HW | LOGD_WIFI, + nm_log_info (LOGD_PLATFORM | LOGD_WIFI, "(%s): driver does not support SSID scans (scan_capa 0x%02X).", wext->parent.iface, scan_capa_range->scan_capa); @@ -644,7 +644,7 @@ wifi_wext_init (const char *iface, int ifindex, gboolean check_scan) if (has_5ghz) wext->parent.caps |= NM_WIFI_DEVICE_CAP_FREQ_5GHZ; - nm_log_info (LOGD_HW | LOGD_WIFI, + nm_log_info (LOGD_PLATFORM | LOGD_WIFI, "(%s): using WEXT for WiFi device control", wext->parent.iface); From 64e02a0ac79bd1bd14adcbf7cb3eba299e17a2b5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 6 Oct 2016 21:40:18 +0200 Subject: [PATCH 4/6] logging: protect VPN_PLUGIN logging domain VPN_PLUGIN is special. With # nmcli general logging level TRACE domains ALL the logging verbosity of VPN_PLUGIN domain should not be set higher then info. The user has to explicitly set it via: # nmcli general logging level TRACE domains ALL,VPN_PLUGIN:TRACE This was not the case for # nmcli general logging level TRACE Fix that. --- src/nm-logging.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/nm-logging.c b/src/nm-logging.c index e695a60a25..f8ecf0c94b 100644 --- a/src/nm-logging.c +++ b/src/nm-logging.c @@ -329,6 +329,13 @@ nm_logging_setup (const char *level, bits = 0; + if (domains_free) { + /* The caller didn't provide any domains to set (`nmcli general logging level DEBUG`). + * We reset all domains that were previously set, but we still want to protect + * VPN_PLUGIN domain. */ + protect = LOGD_VPN_PLUGIN; + } + /* Check for combined domains */ if (!g_ascii_strcasecmp (*iter, LOGD_ALL_STRING)) { bits = LOGD_ALL; @@ -380,7 +387,7 @@ nm_logging_setup (const char *level, new_logging[i] &= ~bits; else { new_logging[i] |= bits; - if ( protect + if ( (protect & bits) && i < LOGL_INFO) new_logging[i] &= ~protect; } From 8bca7704c9e81427febf84606176caaed5dbafb4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 6 Oct 2016 22:14:01 +0200 Subject: [PATCH 5/6] config: print default value for logging.audit --- configure.ac | 16 ++++++++-------- src/nm-audit-manager.c | 2 +- src/nm-config-data.c | 1 + src/nm-config.h | 4 +++- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/configure.ac b/configure.ac index 6f067c20da..7172093101 100644 --- a/configure.ac +++ b/configure.ac @@ -524,16 +524,16 @@ else fi if test "$have_libaudit" = "yes"; then AC_DEFINE(HAVE_LIBAUDIT, 1, [Define if you have libaudit support]) - if test "$with_libaudit" = "yes-disabled-by-default"; then - AC_DEFINE(NM_CONFIG_DEFAULT_LOGGING_AUDIT, FALSE, [The default value of the logging.audit configuration option]) - NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT='false' - else - AC_DEFINE(NM_CONFIG_DEFAULT_LOGGING_AUDIT, TRUE, [The default value of the logging.audit configuration option]) - NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT='true' - fi + if test "$with_libaudit" = "yes-disabled-by-default"; then + AC_DEFINE(NM_CONFIG_DEFAULT_LOGGING_AUDIT, "false", [The default value of the logging.audit configuration option]) + NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT='false' + else + AC_DEFINE(NM_CONFIG_DEFAULT_LOGGING_AUDIT, "true", [The default value of the logging.audit configuration option]) + NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT='true' + fi else AC_DEFINE(HAVE_LIBAUDIT, 0, [Define if you have libaudit support]) - AC_DEFINE(NM_CONFIG_DEFAULT_LOGGING_AUDIT, FALSE, [The default value of the logging.audit configuration option]) + AC_DEFINE(NM_CONFIG_DEFAULT_LOGGING_AUDIT, "false", [The default value of the logging.audit configuration option]) NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT='false' fi AC_SUBST(NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT) diff --git a/src/nm-audit-manager.c b/src/nm-audit-manager.c index 384a5c3fb5..c8bbc5ccc5 100644 --- a/src/nm-audit-manager.c +++ b/src/nm-audit-manager.c @@ -336,7 +336,7 @@ init_auditd (NMAuditManager *self) if (nm_config_data_get_value_boolean (data, NM_CONFIG_KEYFILE_GROUP_LOGGING, NM_CONFIG_KEYFILE_KEY_AUDIT, - NM_CONFIG_DEFAULT_LOGGING_AUDIT)) { + NM_CONFIG_DEFAULT_LOGGING_AUDIT_BOOL)) { if (priv->auditd_fd < 0) { priv->auditd_fd = audit_open (); if (priv->auditd_fd < 0) diff --git a/src/nm-config-data.c b/src/nm-config-data.c index 73427d2a86..0875e69bd7 100644 --- a/src/nm-config-data.c +++ b/src/nm-config-data.c @@ -544,6 +544,7 @@ static struct { { NM_CONFIG_KEYFILE_GROUP_MAIN, "rc-manager", NM_CONFIG_DEFAULT_DNS_RC_MANAGER }, { NM_CONFIG_KEYFILE_GROUP_MAIN, "auth-polkit", NM_CONFIG_DEFAULT_AUTH_POLKIT }, { NM_CONFIG_KEYFILE_GROUP_LOGGING, "backend", NM_CONFIG_LOGGING_BACKEND_DEFAULT }, + { NM_CONFIG_KEYFILE_GROUP_LOGGING, "audit", NM_CONFIG_DEFAULT_LOGGING_AUDIT }, }; void diff --git a/src/nm-config.h b/src/nm-config.h index bfa23e1121..0d3faa8832 100644 --- a/src/nm-config.h +++ b/src/nm-config.h @@ -182,7 +182,9 @@ extern char *_nm_config_match_env; /*****************************************************************************/ #define NM_CONFIG_DEVICE_STATE_DIR ""NMRUNDIR"/devices" -#define NM_CONFIG_DEFAULT_AUTH_POLKIT_BOOL (nm_streq0 (NM_CONFIG_DEFAULT_AUTH_POLKIT, "true")) + +#define NM_CONFIG_DEFAULT_AUTH_POLKIT_BOOL (nm_streq (""NM_CONFIG_DEFAULT_AUTH_POLKIT, "true")) +#define NM_CONFIG_DEFAULT_LOGGING_AUDIT_BOOL (nm_streq (""NM_CONFIG_DEFAULT_LOGGING_AUDIT, "true")) typedef enum { NM_CONFIG_DEVICE_STATE_MANAGED_TYPE_UNKNOWN = -1, From 78d34d7c2e003d53d6daaee859655e4c2718718d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 6 Oct 2016 23:01:46 +0200 Subject: [PATCH 6/6] config: fix printing default values for missing sections Previously, the default values were only printed if the corresponding section was already present. Fix that. Also, we call nm_config_data_log() also to dump the configuration into the logfile. In that case (!stream), exclude the default values. --- src/nm-config-data.c | 56 ++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/src/nm-config-data.c b/src/nm-config-data.c index 0875e69bd7..c508d0e264 100644 --- a/src/nm-config-data.c +++ b/src/nm-config-data.c @@ -473,6 +473,7 @@ _nm_config_data_log_sort (const char **pa, const char **pb, gpointer dummy) gboolean a_is_connection, b_is_connection; gboolean a_is_device, b_is_device; gboolean a_is_intern, b_is_intern; + gboolean a_is_main, b_is_main; const char *a = *pa; const char *b = *pb; @@ -531,8 +532,12 @@ _nm_config_data_log_sort (const char **pa, const char **pb, gpointer dummy) if (b_is_device && !a_is_device) return -1; - /* no reordering. */ - return 0; + a_is_main = nm_streq0 (a, "main"); + b_is_main = nm_streq0 (b, "main"); + if (a_is_main != b_is_main) + return a_is_main ? -1 : 1; + + return g_strcmp0 (a, b); } static struct { @@ -558,6 +563,8 @@ nm_config_data_log (const NMConfigData *self, gsize ngroups; guint g, k, i; FILE *stream = print_stream; + gs_unref_ptrarray GPtrArray *groups_full = NULL; + gboolean print_default = !!stream; g_return_if_fail (NM_IS_CONFIG_DATA (self)); @@ -583,18 +590,35 @@ nm_config_data_log (const NMConfigData *self, if (!groups) ngroups = 0; - if (groups && groups[0]) { - g_qsort_with_data (groups, ngroups, - sizeof (char *), - (GCompareDataFunc) _nm_config_data_log_sort, - NULL); + groups_full = g_ptr_array_sized_new (ngroups + 5); + + if (ngroups) { + g_ptr_array_set_size (groups_full, ngroups); + memcpy (groups_full->pdata, groups, sizeof (groups[0]) * ngroups); + g_ptr_array_sort_with_data (groups_full, (GCompareDataFunc) _nm_config_data_log_sort, NULL); + } + + if (print_default) { + for (g = 0; g < G_N_ELEMENTS (default_values); g++) { + const char *group = default_values[g].group; + gssize idx; + + idx = _nm_utils_array_find_binary_search ((gconstpointer *) groups_full->pdata, + sizeof (char *), + groups_full->len, + &group, + (GCompareDataFunc) _nm_config_data_log_sort, + NULL); + if (idx < 0) + g_ptr_array_insert (groups_full, (~idx), (gpointer) group); + } } if (!stream) - _LOG (stream, prefix, "config-data[%p]: %lu groups", self, (unsigned long) ngroups); + _LOG (stream, prefix, "config-data[%p]: %u groups", self, groups_full->len); - for (g = 0; g < ngroups; g++) { - const char *group = groups[g]; + for (g = 0; g < groups_full->len; g++) { + const char *group = groups_full->pdata[g]; gs_strfreev char **keys = NULL; gboolean is_atomic; @@ -604,11 +628,13 @@ nm_config_data_log (const NMConfigData *self, _LOG (stream, prefix, "[%s]%s", group, is_atomic && !stream ? " # atomic section" : ""); /* Print default values as comments */ - for (i = 0; i < G_N_ELEMENTS (default_values); i++) { - if ( nm_streq (default_values[i].group, group) - && !g_key_file_has_key (priv->keyfile, group, default_values[i].key, NULL)) { - _LOG (stream, prefix, "%s# %s=%s", key_prefix, default_values[i].key, - default_values[i].value); + if (print_default) { + for (i = 0; i < G_N_ELEMENTS (default_values); i++) { + if ( nm_streq (default_values[i].group, group) + && !g_key_file_has_key (priv->keyfile, group, default_values[i].key, NULL)) { + _LOG (stream, prefix, "%s# %s=%s", key_prefix, default_values[i].key, + default_values[i].value); + } } }