From aa6108d70f2889bc35bc0a0b16526f907fbbaa81 Mon Sep 17 00:00:00 2001 From: Simon Bucher Date: Wed, 30 Sep 2026 07:29:37 +0000 Subject: [PATCH] kernel: handle EINTR and signal termination in run_command When `run_command` reads subprocess output via `fgets` in a multi-threaded process, incoming signals can interrupt the underlying `read` syscall with `EINTR`. Previously, `while (fgets(...) != NULL)` exited the read loop immediately on `EINTR` and called `pclose`, closing the pipe early while the child was still running (or causing the child to die with `SIGPIPE`). Additionally, `run_command` returned `WEXITSTATUS(ret)` without checking `WIFEXITED(ret)`, which evaluates to `0` when a child terminates due to an unhandled signal. Retry `fgets` after clearing the stream error state when `ferror(f) && errno == EINTR`, and return `-1` if `!WIFEXITED(ret)`. --- kernel/yosys.cc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/kernel/yosys.cc b/kernel/yosys.cc index 999c7a45b..ab073dd1c 100644 --- a/kernel/yosys.cc +++ b/kernel/yosys.cc @@ -192,10 +192,17 @@ int run_command(const std::string &command, std::function