Skip to content

fix(extractinitrd): ignore broken pipe - #2750

Closed
aafeijoo-suse wants to merge 2 commits into
dracut-ng:mainfrom
aafeijoo-suse:extractinitrd-pipe-fix
Closed

aafeijoo-suse wants to merge 2 commits into
dracut-ng:mainfrom
aafeijoo-suse:extractinitrd-pipe-fix

Conversation

@aafeijoo-suse

Copy link
Copy Markdown
Contributor

When the consumer of the output ends before the write operation is complete, extractinitrd complains on stderr and exits with a non-zero code. Reproduced directly using the code from git main:

$ sudo dracutbasedir=. ./lsinitrd.sh | grep -q image
extractinitrd: zstd failed

Here grep exits on its first match, which is the "Early CPIO image" line. lsinitrd then runs extractinitrd --parts 2- --to-stdout on the already closed stdout, cpio dies of SIGPIPE, the decompressor gets EPIPE, and waitpid() reports a child that did not exit normally.

This issue was reintroduced after replacing skipcpio with extractinitrd; it was already fixed in aa0369a (Fedora's kdump.service has the default "IgnoreSIGPIPE=yes" and executes a bash script which calls lsinitrd ... | ... in several places).

Checklist

  • I have tested it locally
  • I have reviewed and updated any documentation if relevant
  • I am providing new code and test(s) for it

@aafeijoo-suse
aafeijoo-suse requested a review from a team as a code owner September 9, 2026 09:24
@github-actions github-actions Bot added c extractinitrd test Issues related to testing labels Sep 9, 2026
When the consumer of the output ends before the write operation is complete,
extractinitrd complains on stderr and exits with a non-zero code. Reproduced
directly using the code from git main:

```
$ sudo dracutbasedir=. ./lsinitrd.sh | grep -q image
dracut-extractinitrd: zstd failed
```

Here grep exits on its first match, which is the "Early CPIO image" line.
lsinitrd then runs `dracut-extractinitrd --parts 2- --to-stdout` on the already
closed stdout, cpio dies of SIGPIPE, the decompressor gets EPIPE, and
`waitpid()` reports a child that did not exit normally.

This issue was reintroduced after replacing skipcpio with extractinitrd; it was
already fixed in aa0369a (Fedora's
kdump.service has the default "IgnoreSIGPIPE=yes" and executes a bash script
which calls `lsinitrd ... | ...` in several places).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Internal cpio failures can be misclassified as downstream broken pipes and incorrectly return success.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Updates extractinitrd to quietly handle downstream consumers closing output pipes.

Changes:

  • Handles EPIPE and child SIGPIPE conditions.
  • Adds broken-pipe tests across compression formats and signal dispositions.
File summaries
File Description
src/extractinitrd/extractinitrd.c Adds broken-pipe handling for parent and child processes.
test/TEST-83-EXTRACTINITRD/test.sh Tests early consumer termination without errors.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

ok = false;

return !ok;
return !ok && !broken_pipe;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, the bot is right:

$ sudo ./dracut-extractinitrd /boot/initrd -- --fake-option
cpio: unrecognized option '--fake-option'
Try 'cpio --help' or 'cpio --usage' for more information.
$ echo $?
0

I guess this needs at least 2 flags to handle the exit status.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c extractinitrd test Issues related to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants