]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
log: protect errno in log_open()
authorSergey Bugaev <bugaevc@gmail.com>
Mon, 22 Mar 2021 15:31:12 +0000 (18:31 +0300)
committerSergey Bugaev <bugaevc@gmail.com>
Mon, 22 Mar 2021 16:34:03 +0000 (19:34 +0300)
Commit 0b1f3c768ce1bd1490a5e53f539976dcef8ca765 has introduced log_open()
calls after exec fails post-fork. However, the log_open() call itself could
change the value of errno, which, for me, manifested in:

$ coredumpctl gdb
...
Failed to invoke gdb: Success

Fix this by using PROTECT_ERRNO in log_open().

src/basic/log.c

index c8cca96bca48615ab765143877180680b38dc265..0e6023cff222451bfb9a6b4300f54683bcc7676a 100644 (file)
@@ -252,6 +252,13 @@ int log_open(void) {
 
         /* Do not call from library code. */
 
+        /* This function is often called in preparation for being able
+         * to log. Let's make sure we don't clobber errno, so that a call
+         * to a logging function immediately following a log_open() call
+         * can still easily reference an error that happened immediately
+         * before the log_open() call. */
+        PROTECT_ERRNO;
+
         /* If we don't use the console we close it here, to not get
          * killed by SAK. If we don't use syslog we close it here so
          * that we are not confused by somebody deleting the socket in