]> git.sesse.net Git - cubemap/commitdiff
Fix infinite CPU usage on waitpid().
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 5 May 2021 22:42:53 +0000 (00:42 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 5 May 2021 22:56:02 +0000 (00:56 +0200)
httpinput.cpp

index 274cc2687b160d45e365fc7f4daafb665b9d2660..1b09abf6ce8ad550b6c371853fdbcd0bc0bb8e6f 100644 (file)
@@ -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;