From 941a7e35cd1b51dcd15159e23cc4a1e82ae4808b Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Thu, 6 May 2021 00:42:53 +0200 Subject: [PATCH] Fix infinite CPU usage on waitpid(). --- httpinput.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/httpinput.cpp b/httpinput.cpp index 274cc26..1b09abf 100644 --- a/httpinput.cpp +++ b/httpinput.cpp @@ -383,8 +383,20 @@ void HTTPInput::do_work() switch (state) { case NOT_CONNECTED: { // Reap any exited children. - int wstatus; - while (waitpid(-1, &wstatus, WNOHANG) != -1 || errno == EINTR) ; + int wstatus, err; + do { + err = waitpid(-1, &wstatus, WNOHANG); + if (err == -1) { + if (errno == EINTR) { + continue; + } + if (errno == ECHILD) { + break; + } + log_perror("waitpid"); + break; + } + } while (err != 0); request.clear(); request_bytes_sent = 0; -- 2.39.2