]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
log: save errno on strerror_r()
authorChristian Brauner <christian.brauner@ubuntu.com>
Mon, 3 Sep 2018 12:19:06 +0000 (14:19 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 4 Sep 2018 11:57:35 +0000 (13:57 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/log.h

index 43199bea533b555babb33175e02db1c8f954840c..1050dc604c089c3bb991740def2fb800e6ecfabc 100644 (file)
@@ -344,7 +344,9 @@ ATTR_UNUSED static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \
                        char errno_buf[MAXPATHLEN / 2] = {"Failed to get errno string"}; \
                        char *ptr = NULL;                                                \
                        {                                                                \
+                               int saved_errno = errno;                                 \
                                ptr = strerror_r(errno, errno_buf, sizeof(errno_buf));   \
+                               errno = saved_errno;                                     \
                                if (!ptr)                                                \
                                        ptr = errno_buf;                                 \
                        }
@@ -353,7 +355,9 @@ ATTR_UNUSED static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \
                        char errno_buf[MAXPATHLEN / 2] = {"Failed to get errno string"}; \
                        char *ptr = errno_buf;                                           \
                        {                                                                \
+                               int saved_errno = errno;                                 \
                                (void)strerror_r(errno, errno_buf, sizeof(errno_buf));   \
+                               errno = saved_errno;                                     \
                        }
        #endif
 #elif ENFORCE_THREAD_SAFETY