]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
fix(skipcpio): ignore broken pipe
authorDavid Tardon <dtardon@redhat.com>
Tue, 16 Aug 2022 11:30:16 +0000 (13:30 +0200)
committerJóhann B. Guðmundsson <johannbg@gmail.com>
Thu, 18 Aug 2022 06:08:45 +0000 (06:08 +0000)
If lsinitrd is called from a context in which SIGPIPE is ignored (e.g.,
from a systemd unit with default setting of IgnoreSIGPIPE=), the
following line will result in an error being issued:

bin="$($SKIP "$image" | { read -r -N 6 bin && echo "$bin"; })"

An example error from `kdumpctl start` (which internally just calls
`systemctl start kdump.service`):

kdumpctl[1287]: ERROR: src/skipcpio/skipcpio.c:191:main(): fwrite

A minimal reproducer:

systemd-run -t sh -c '/path/to/skipcpio /path/to/any/file | false'

src/skipcpio/skipcpio.c

index 13bfaf53656498aa22a96641f29f6ce78a43e9e3..f66c1869430ae340f8f65e1b9e67daa29651ba7a 100644 (file)
@@ -23,6 +23,7 @@
 #define _GNU_SOURCE
 #endif
 
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -187,8 +188,10 @@ cat_rest:
                         goto end;
                 }
 
+                errno = 0;
                 if (fwrite(buf.copy_buffer, 1, s, stdout) != s) {
-                        pr_err("fwrite\n");
+                        if (errno != EPIPE)
+                                pr_err("fwrite\n");
                         goto end;
                 }
         }