diff --git a/src/dhcp-manager/systemd-dhcp/nm-sd-adapt.h b/src/dhcp-manager/systemd-dhcp/nm-sd-adapt.h index ce1716b175..c316fb4692 100644 --- a/src/dhcp-manager/systemd-dhcp/nm-sd-adapt.h +++ b/src/dhcp-manager/systemd-dhcp/nm-sd-adapt.h @@ -57,7 +57,7 @@ G_STMT_START { \ if (nm_logging_enabled (_l, LOGD_DHCP)) { \ const char *_location = strrchr (file "", '/'); \ \ - _nm_log (_location ? _location + 1 : file, line, func, _l, LOGD_DHCP, format, ## __VA_ARGS__); \ + _nm_log_impl (_location ? _location + 1 : file, line, func, _l, LOGD_DHCP, 0, format, ## __VA_ARGS__); \ } \ } G_STMT_END diff --git a/src/nm-auth-manager.c b/src/nm-auth-manager.c index 2b929f6756..8bd167eff9 100644 --- a/src/nm-auth-manager.c +++ b/src/nm-auth-manager.c @@ -39,9 +39,9 @@ \ if ((self) != singleton_instance) \ g_snprintf (__prefix, sizeof (__prefix), "auth[%p]", (self)); \ - nm_log ((level), (domain), \ - "%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ - __prefix _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ + _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/nm-default-route-manager.c b/src/nm-default-route-manager.c index 2fd396c4f0..153c1de6bb 100644 --- a/src/nm-default-route-manager.c +++ b/src/nm-default-route-manager.c @@ -76,9 +76,9 @@ static NMDefaultRouteManager *singleton_instance; g_snprintf (__prefix, sizeof (__prefix), "default-route%c[%p]", __ch, (self)); \ else \ __prefix[STRLEN ("default-route")] = __ch; \ - nm_log (__level, __domain, \ - "%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ - __prefix _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ + _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/nm-logging.c b/src/nm-logging.c index f1291fa73b..fa770344ed 100644 --- a/src/nm-logging.c +++ b/src/nm-logging.c @@ -357,13 +357,14 @@ nm_logging_enabled (NMLogLevel level, NMLogDomain domain) } void -_nm_log (const char *file, - guint line, - const char *func, - NMLogLevel level, - NMLogDomain domain, - const char *fmt, - ...) +_nm_log_impl (const char *file, + guint line, + const char *func, + NMLogLevel level, + NMLogDomain domain, + int error, + const char *fmt, + ...) { va_list args; char *msg; @@ -379,6 +380,10 @@ _nm_log (const char *file, if (!(logging[level] & domain)) return; + /* Make sure that %m maps to the specified error */ + if (error != 0) + errno = error; + va_start (args, fmt); msg = g_strdup_vprintf (fmt, args); va_end (args); diff --git a/src/nm-logging.h b/src/nm-logging.h index e0aa71690a..00d429b095 100644 --- a/src/nm-logging.h +++ b/src/nm-logging.h @@ -100,12 +100,20 @@ typedef enum { /*< skip >*/ #define nm_log_dbg(domain, ...) nm_log (LOGL_DEBUG, (domain), __VA_ARGS__) #define nm_log_trace(domain, ...) nm_log (LOGL_TRACE, (domain), __VA_ARGS__) +/* A wrapper for the _nm_log_impl() function that adds call site information. + * Contrary to nm_log(), it unconditionally calls the function without + * checking whether logging for the given level and domain is enabled. */ +#define _nm_log(level, domain, error, ...) \ + G_STMT_START { \ + _nm_log_impl (__FILE__, __LINE__, G_STRFUNC, (level), (domain), (error), ""__VA_ARGS__); \ + } G_STMT_END + /* nm_log() only evaluates it's argument list after checking * whether logging for the given level/domain is enabled. */ #define nm_log(level, domain, ...) \ G_STMT_START { \ if (nm_logging_enabled ((level), (domain))) { \ - _nm_log (__FILE__, __LINE__, G_STRFUNC, (level), (domain), __VA_ARGS__); \ + _nm_log (level, domain, 0, __VA_ARGS__); \ } \ } G_STMT_END @@ -136,13 +144,14 @@ typedef enum { /*< skip >*/ nm_log_ptr ((level), (domain), (self), __VA_ARGS__) -void _nm_log (const char *file, - guint line, - const char *func, - NMLogLevel level, - NMLogDomain domain, - const char *fmt, - ...) __attribute__((__format__ (__printf__, 6, 7))); +void _nm_log_impl (const char *file, + guint line, + const char *func, + NMLogLevel level, + NMLogDomain domain, + int error, + const char *fmt, + ...) __attribute__((__format__ (__printf__, 7, 8))); const char *nm_logging_level_to_string (void); const char *nm_logging_domains_to_string (void); diff --git a/src/nm-manager.c b/src/nm-manager.c index 25f9533af4..0fa88d1d8a 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -3630,7 +3630,7 @@ do_sleep_wake (NMManager *self, gboolean sleeping_changed) waking_from_suspend = sleeping_changed && !priv->sleeping; if (manager_sleeping (self)) { - nm_log_info (LOGD_SUSPEND, suspending ? "sleeping..." : "disabling..."); + nm_log_info (LOGD_SUSPEND, "%s...", suspending ? "sleeping" : "disabling"); /* FIXME: are there still hardware devices that need to be disabled around * suspend/resume? @@ -3648,7 +3648,7 @@ do_sleep_wake (NMManager *self, gboolean sleeping_changed) nm_device_set_unmanaged (device, NM_UNMANAGED_INTERNAL, TRUE, NM_DEVICE_STATE_REASON_SLEEPING); } } else { - nm_log_info (LOGD_SUSPEND, waking_from_suspend ? "waking up..." : "re-enabling..."); + nm_log_info (LOGD_SUSPEND, "%s...", waking_from_suspend ? "waking up" : "re-enabling"); if (waking_from_suspend) { /* Belatedly take down Wake-on-LAN devices; ideally we wouldn't have to do this diff --git a/src/settings/plugins/ibft/plugin.c b/src/settings/plugins/ibft/plugin.c index 303971e05b..632c4df14b 100644 --- a/src/settings/plugins/ibft/plugin.c +++ b/src/settings/plugins/ibft/plugin.c @@ -63,7 +63,7 @@ read_connections (SCPluginIbft *self) NMIbftConnection *connection; if (!read_ibft_blocks ("/sbin/iscsiadm", &blocks, &error)) { - nm_log_dbg (LOGD_SETTINGS, _("ibft: failed to read iscsiadm records: %s"), error->message); + nm_log_dbg (LOGD_SETTINGS, "ibft: failed to read iscsiadm records: %s", error->message); g_error_free (error); return; } @@ -71,13 +71,13 @@ read_connections (SCPluginIbft *self) for (iter = blocks; iter; iter = iter->next) { connection = nm_ibft_connection_new (iter->data, &error); if (connection) { - nm_log_info (LOGD_SETTINGS, _("ibft: read connection '%s'"), + nm_log_info (LOGD_SETTINGS, "ibft: read connection '%s'", nm_connection_get_id (NM_CONNECTION (connection))); g_hash_table_insert (priv->connections, g_strdup (nm_connection_get_uuid (NM_CONNECTION (connection))), connection); } else { - nm_log_warn (LOGD_SETTINGS, _("ibft: failed to read iscsiadm record: %s"), error->message); + nm_log_warn (LOGD_SETTINGS, "ibft: failed to read iscsiadm record: %s", error->message); g_clear_error (&error); } }