]> www.infradead.org Git - users/hch/misc.git/commitdiff
gen_init_cpio: Ignore fsync() returning EINVAL on pipes
authorDmitry Safonov <dima@arista.com>
Tue, 7 Oct 2025 03:46:47 +0000 (04:46 +0100)
committerNathan Chancellor <nathan@kernel.org>
Tue, 7 Oct 2025 16:53:05 +0000 (09:53 -0700)
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 <ddiss@suse.de>
Cc: Nicolas Schier <nsc@kernel.org>
Signed-off-by: Dmitry Safonov <dima@arista.com>
Reviewed-by: David Disseldorp <ddiss@suse.de>
Link: https://patch.msgid.link/20251007-gen_init_cpio-pipe-v2-1-b098ab94b58a@arista.com
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
usr/gen_init_cpio.c

index 75e9561ba31392e12536e76a918245a8ea07f9b8..b7296edc6626fb0cf7c709082797d1e6a7376d6e 100644 (file)
@@ -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,