Skip to content

Commit

Permalink
fix(skipcpio): ignore broken pipe
Browse files Browse the repository at this point in the history
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'
  • Loading branch information
dtardon authored and johannbg committed Aug 18, 2022
1 parent bdef779 commit aa0369a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/skipcpio/skipcpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define _GNU_SOURCE
#endif

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -187,8 +188,10 @@ int main(int argc, char **argv)
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;
}
}
Expand Down

0 comments on commit aa0369a

Please sign in to comment.