From 215c50922d75ecf75eebc9c871adcdc0fabe3f2d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 11 Dec 2016 22:33:19 +0100 Subject: [PATCH] logging: preserve errno in logging functions It would be nice that our logging functions are guaranteed to preserve errno. We are currently not very consistent about handling errno, let's improve on that. --- src/nm-logging.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/nm-logging.c b/src/nm-logging.c index 50927f8caf..c242d90319 100644 --- a/src/nm-logging.c +++ b/src/nm-logging.c @@ -599,6 +599,7 @@ _nm_log_impl (const char *file, va_list args; char *msg; GTimeVal tv; + int errno_saved; if ((guint) level >= G_N_ELEMENTS (_nm_logging_enabled_state)) g_return_if_reached (); @@ -606,6 +607,8 @@ _nm_log_impl (const char *file, if (!(_nm_logging_enabled_state[level] & domain)) return; + errno_saved = errno; + /* Make sure that %m maps to the specified error */ if (error != 0) { if (error < 0) @@ -719,6 +722,8 @@ _nm_log_impl (const char *file, } g_free (msg); + + errno = errno_saved; } /*****************************************************************************/