[libvirt] [PATCH] util: ignore SIGPIPE when writing to stderr/stdout

Wang Yechao wang.yechao255 at zte.com.cn
Sat Oct 12 08:04:11 UTC 2019


libvirtd's stderr/stdout redirected to journald by default, so if
the journald has stopped, libvirtd and libvirtd's child process
will receive SIGPIPE signal when writing logs to stderr/stdout.

journald stopped reasons:
1. manual command "systemctl stop systemd-journald.service"
2. oom killer kill it.
...

Signed-off-by: Wang Yechao <wang.yechao255 at zte.com.cn>
---
 src/util/virlog.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/util/virlog.c b/src/util/virlog.c
index 4c76fbc..127e121 100644
--- a/src/util/virlog.c
+++ b/src/util/virlog.c
@@ -39,6 +39,7 @@
 # include <sys/un.h>
 #endif
 #include <fnmatch.h>
+#include <signal.h>
 
 #include "virerror.h"
 #include "virlog.h"
@@ -732,6 +733,9 @@ virLogOutputToFd(virLogSourcePtr source ATTRIBUTE_UNUSED,
     if (fd < 0)
         return;
 
+    if (fd == STDERR_FILENO || fd == STDOUT_FILENO)
+        signal(SIGPIPE, SIG_IGN);
+
     if (virAsprintfQuiet(&msg, "%s: %s", timestamp, str) < 0)
         return;
 
@@ -740,6 +744,10 @@ virLogOutputToFd(virLogSourcePtr source ATTRIBUTE_UNUSED,
 
     if (flags & VIR_LOG_STACK_TRACE)
         virLogStackTraceToFd(fd);
+
+    if (fd == STDERR_FILENO || fd == STDOUT_FILENO)
+        signal(SIGPIPE, SIG_DFL);
+
 }
 
 
-- 
1.8.3.1




More information about the libvir-list mailing list