From: Steinar H. Gunderson Date: Wed, 5 May 2021 22:42:53 +0000 (+0200) Subject: Fix infinite CPU usage on waitpid(). X-Git-Tag: 1.5.0~21 X-Git-Url: https://git.sesse.net/?p=cubemap;a=commitdiff_plain;h=941a7e35cd1b51dcd15159e23cc4a1e82ae4808b;hp=e3f2936e3c9ff3b5569759c1aaed16f03bf728f8 Fix infinite CPU usage on waitpid(). --- 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;