From f5ecd46e227b9a203b36577330bafc9e69ddb1d6 Mon Sep 17 00:00:00 2001 From: Ilya Naidanov Date: Tue, 6 Oct 2026 10:08:16 +0500 Subject: [PATCH] binfmt: clear the ignored flush failure before the registration loop The "flush out all rules" step writes to /proc/sys/fs/binfmt_misc/status and explicitly ignores failure, but it assigns the result to the same r that RET_GATHER() consumes below. RET_GATHER() keeps the first error it is given, so a failed flush is still returned from run() and systemd-binfmt exits 1 even when every rule in binfmt.d was registered successfully. Reset r after the ignored flush so it cannot be gathered. Tested on WSL2 (kernel 6.18.40.1-microsoft-standard-WSL2), systemd 261, where /proc/sys/fs/binfmt_misc/status is a read-only tmpfs. Before this, the binary registered /etc/binfmt.d/nixos.conf successfully and then exited 1; after, it exits 0. /proc/sys/fs/binfmt_misc/WSLInterop stays enabled in both cases. Fixes #44035. (cherry picked from commit 8fc6b2141b113f63427a766aa800539437138d6c) --- src/binfmt/binfmt.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/binfmt/binfmt.c b/src/binfmt/binfmt.c index 0c91ede6bb..da70187527 100644 --- a/src/binfmt/binfmt.c +++ b/src/binfmt/binfmt.c @@ -219,6 +219,8 @@ static int run(int argc, char *argv[]) { else log_debug("Flushed all binfmt_misc rules."); + r = 0; + STRV_FOREACH(f, files) RET_GATHER(r, apply_file(*f, true)); }