diff options
author | Sergey Bugaev <bugaevc@gmail.com> | 2021-03-22 18:31:12 +0300 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-03-23 10:13:29 +0100 |
commit | 0d9b74ad25c2def92c8e8139f50087b4e64c8d83 (patch) | |
tree | c09039b6c8cd9091ea27e9a22a159c243d3704df | |
parent | 8a43177d80c85e9cb8837544a0ac3132e1461ba6 (diff) | |
download | systemd-0d9b74ad25c2def92c8e8139f50087b4e64c8d83.tar.gz |
log: protect errno in log_open()
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().
(cherry picked from commit 0e557eef37c9ebcc8f5c19fc6fc44b6fd617cc5d)
(cherry picked from commit dabf9f2109e5b8cc26d9e0d9188deebff3edf8c2)
-rw-r--r-- | src/basic/log.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/basic/log.c b/src/basic/log.c index e2963981fb..710859b8e7 100644 --- a/src/basic/log.c +++ b/src/basic/log.c @@ -251,6 +251,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 |