Fix infinite CPU usage on waitpid().
[cubemap] / 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;