Skip to contentSkip to conversation

gen_init_cpio: Ignore fsync() returning EINVAL on pipes

PATCH Applied Dmitry Safonov 2 participants 2 messages Oct 7, 2025 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 gen_init_cpio: Ignore fsync() returning EINVAL on pipes

The reproducer:
echo | ./usr/gen_init_cpio /dev/stdin > /dev/null

fsync() on a pipe fd returns -EINVAL, which makes gen_init_cpio fail. Ignore -EINVAL from fsync().

Fixes ae18b94099b0 ("gen_init_cpio: support -o <output_file> parameter")
Cc David Disseldorp <[email protected]>
Cc Nicolas Schier <[email protected]>

---
Changes in v2:
- Instead of isfdtype() just ignore -EINVAL from fsync() (Suggested by David)
- Add minimal reproducer and shrink the patch description (David)
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 usr/gen_init_cpio.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
usr/gen_init_cpio.c +4 -1
index 75e9561ba31392e12536e76a918245a8ea07f9b8..b7296edc6626fb0cf7c709082797d1e6a7376d6e 100644
@@ -112,7 +112,10 @@ static int cpio_trailer(void)
 	    push_pad(padlen(offset, 512)) < 0)
 		return -1;
 
-	return fsync(outfd);
+	if (fsync(outfd) < 0 && errno != EINVAL)
+		return -1;
+
+	return 0;
 }
 
 static int cpio_mkslink(const char *name, const char *target,

---
base-commit: c746c3b5169831d7fb032a1051d8b45592ae8d78
change-id: 20251007-gen_init_cpio-pipe-5ad87f616a40

Best regards,

Signature · 1 line
Dmitry Safonov <[email protected]>
maintainer Applied
#1 lore raw
Quoted 8 lines · Dmitry Safonov

The reproducer:
echo | ./usr/gen_init_cpio /dev/stdin > /dev/null

fsync() on a pipe fd returns -EINVAL, which makes gen_init_cpio fail. Ignore -EINVAL from fsync().

[...]

Applied, thanks!

[1/1] gen_init_cpio: Ignore fsync() returning EINVAL on pipes

      https://git.kernel.org/kbuild/c/38492c5743f8b

Best regards,

Signature · 1 line
Nathan Chancellor <[email protected]>