From c22bca1f87c395665c35c8f64f4f9721781d7ff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 15 Nov 2025 18:57:23 +0800 Subject: [PATCH] Processing (Linux): blocks SIGCHLD and simplify poll error handling Partially reverts e9ab67b380734d5c9527376b0b5e38b90bf37b97 Fixes #2056 & unfixes #1418 --- src/common/init.c | 9 ++++----- src/common/processing_linux.c | 32 +++++--------------------------- 2 files changed, 9 insertions(+), 32 deletions(-) diff --git a/src/common/init.c b/src/common/init.c index 8e27ebaf1..fe7544245 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -92,10 +92,6 @@ static void exitSignalHandler(FF_MAYBE_UNUSED int signal) resetConsole(); exit(0); } -static void chldSignalHandler(FF_MAYBE_UNUSED int signal) -{ - // empty; used to interrupt the poll and read syscalls -} #endif void ffStart(void) @@ -121,7 +117,10 @@ void ffStart(void) sigaction(SIGINT, &action, NULL); sigaction(SIGTERM, &action, NULL); sigaction(SIGQUIT, &action, NULL); - sigaction(SIGCHLD, &(struct sigaction) { .sa_handler = chldSignalHandler }, NULL); + sigset_t newmask; + sigemptyset(&newmask); + sigaddset(&newmask, SIGCHLD); + sigprocmask(SIG_BLOCK, &newmask, NULL); #endif //reset everything to default before we start printing diff --git a/src/common/processing_linux.c b/src/common/processing_linux.c index c4139ff4b..7ddd725da 100644 --- a/src/common/processing_linux.c +++ b/src/common/processing_linux.c @@ -184,30 +184,13 @@ const char* ffProcessReadOutput(FFProcessHandle* handle, FFstrbuf* buffer) waitpid(childPid, NULL, 0); return "poll(&pollfd, 1, timeout) timeout (try increasing --processing-timeout)"; } - else if (pollret < 0) - { - if (errno == EINTR) - { - // The child process has been terminated. See `chldSignalHandler` in `common/init.c` - if (waitpid(childPid, NULL, WNOHANG) == childPid) - { - // Read remaining data from the pipe - fcntl(childPipeFd, F_SETFL, O_CLOEXEC | O_NONBLOCK); - childPid = -1; - } - } - else - { - kill(childPid, SIGTERM); - waitpid(childPid, NULL, 0); - return "poll(&pollfd, 1, timeout) error: not EINTR"; - } - } - else if (pollfd.revents & POLLERR) + else if (pollret < 0 || (pollfd.revents & POLLERR)) { kill(childPid, SIGTERM); waitpid(childPid, NULL, 0); - return "poll(&pollfd, 1, timeout) error: POLLERR"; + return pollret < 0 + ? "poll(&pollfd, 1, timeout) error: pollret < 0" + : "poll(&pollfd, 1, timeout) error: pollfd.revents & POLLERR"; } } @@ -229,12 +212,7 @@ const char* ffProcessReadOutput(FFProcessHandle* handle, FFstrbuf* buffer) return NULL; } else if (nRead < 0) - { - if (errno == EAGAIN) - return NULL; - else - break; - } + break; } return "read(childPipeFd, str, FF_PIPE_BUFSIZ) failed";