6aac43
From a84df47afae75a0b4068c78d8201a515a841f353 Mon Sep 17 00:00:00 2001
6aac43
From: David Tardon <dtardon@redhat.com>
6aac43
Date: Tue, 16 Aug 2022 13:30:16 +0200
6aac43
Subject: [PATCH] fix(skipcpio): ignore broken pipe
d1a34d
6aac43
If lsinitrd is called from a context in which SIGPIPE is ignored (e.g.,
6aac43
from a systemd unit with default setting of IgnoreSIGPIPE=), the
6aac43
following line will result in an error being issued:
6aac43
6aac43
bin="$($SKIP "$image" | { read -r -N 6 bin && echo "$bin"; })"
6aac43
6aac43
An example error from `kdumpctl start` (which internally just calls
6aac43
`systemctl start kdump.service`):
6aac43
6aac43
kdumpctl[1287]: ERROR: src/skipcpio/skipcpio.c:191:main(): fwrite
6aac43
6aac43
A minimal reproducer:
6aac43
6aac43
systemd-run -t sh -c '/path/to/skipcpio /path/to/any/file | false'
6aac43
6aac43
(cherry-picked from e9a4d73b73b716a9d2d5f01ceb7b427ef544ed9b)
6aac43
6aac43
Resolves: #2109803
d1a34d
---
6aac43
 src/skipcpio/skipcpio.c | 5 ++++-
6aac43
 1 file changed, 4 insertions(+), 1 deletion(-)
d1a34d
6aac43
diff --git a/src/skipcpio/skipcpio.c b/src/skipcpio/skipcpio.c
6aac43
index 13bfaf53..f66c1869 100644
6aac43
--- a/src/skipcpio/skipcpio.c
6aac43
+++ b/src/skipcpio/skipcpio.c
6aac43
@@ -23,6 +23,7 @@
6aac43
 #define _GNU_SOURCE
6aac43
 #endif
d1a34d
 
6aac43
+#include <errno.h>
6aac43
 #include <stdio.h>
6aac43
 #include <stdlib.h>
6aac43
 #include <string.h>
6aac43
@@ -187,8 +188,10 @@ cat_rest:
6aac43
                         goto end;
6aac43
                 }
d1a34d
 
6aac43
+                errno = 0;
6aac43
                 if (fwrite(buf.copy_buffer, 1, s, stdout) != s) {
6aac43
-                        pr_err("fwrite\n");
6aac43
+                        if (errno != EPIPE)
6aac43
+                                pr_err("fwrite\n");
6aac43
                         goto end;
6aac43
                 }
6aac43
         }