diff options
author | Thomas Haller <thaller@redhat.com> | 2014-12-05 00:54:30 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-03-02 14:22:09 +0100 |
commit | 5162426d416a4d309602d695c5966d109fc7bcc0 (patch) | |
tree | 4a10a1af7f4d2098320a6f1a153b01b694b741e0 | |
parent | 94b9c79cf67a09ab79a3826ed46a4cc8150ca5cc (diff) | |
download | NetworkManager-5162426d416a4d309602d695c5966d109fc7bcc0.tar.gz |
logging: add error argument to _nm_log() to support "%m" format specifier
A gnu extension to printf adds the format specifier "%m"
to print @errno. To preserve the error number until the
point where the logging statement is constructed, pass
it as an additional argument to _nm_log().
This is not (yet) used from NM internal code. But systemd is adding
similar functionality to its logging functions. Add the same also to
nm-logging, to support systemd's usage of "%m".
-rw-r--r-- | src/dhcp-manager/systemd-dhcp/nm-sd-adapt.h | 2 | ||||
-rw-r--r-- | src/nm-logging.c | 5 | ||||
-rw-r--r-- | src/nm-logging.h | 5 |
3 files changed, 9 insertions, 3 deletions
diff --git a/src/dhcp-manager/systemd-dhcp/nm-sd-adapt.h b/src/dhcp-manager/systemd-dhcp/nm-sd-adapt.h index ce1716b175..a95f5bfb42 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 (_location ? _location + 1 : file, line, func, _l, LOGD_DHCP, 0, format, ## __VA_ARGS__); \ } \ } G_STMT_END diff --git a/src/nm-logging.c b/src/nm-logging.c index 7f2170ca39..1e9d422f2a 100644 --- a/src/nm-logging.c +++ b/src/nm-logging.c @@ -365,6 +365,7 @@ _nm_log (const char *file, const char *func, NMLogLevel level, NMLogDomain domain, + int error, const char *fmt, ...) { @@ -382,6 +383,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 4ab2db3ad5..7417dfa0f7 100644 --- a/src/nm-logging.h +++ b/src/nm-logging.h @@ -105,7 +105,7 @@ typedef enum { /*< skip >*/ #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 (__FILE__, __LINE__, G_STRFUNC, (level), (domain), 0, __VA_ARGS__); \ } \ } G_STMT_END @@ -139,8 +139,9 @@ void _nm_log (const char *file, const char *func, NMLogLevel level, NMLogDomain domain, + int error, const char *fmt, - ...) __attribute__((__format__ (__printf__, 6, 7))); + ...) __attribute__((__format__ (__printf__, 7, 8))); const char *nm_logging_level_to_string (void); const char *nm_logging_domains_to_string (void); |