]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Simplify EINTR check for waitpid
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 3 Aug 2025 06:00:05 +0000 (08:00 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 3 Aug 2025 11:45:20 +0000 (13:45 +0200)
src/ccache/execute.cpp
src/ccache/util/exec.cpp

index 84d2c6d1d3899a2456c374f9d05b4f67a7d10348..aa510514cd655cc888831d29e40f82a48fc4086e 100644 (file)
@@ -331,11 +331,10 @@ execute(Context& ctx,
   }
 
   int status;
-  while ((result = waitpid(ctx.compiler_pid, &status, 0)) != ctx.compiler_pid) {
-    if (result == -1 && errno == EINTR) {
-      continue;
+  while (waitpid(ctx.compiler_pid, &status, 0) == -1) {
+    if (errno != EINTR) {
+      throw core::Fatal(FMT("waitpid failed: {}", strerror(errno)));
     }
-    throw core::Fatal(FMT("waitpid failed: {}", strerror(errno)));
   }
 
   {
index 11cded4d03bb940f138efcae4b99100b7e1b31d7..49ed7b3e4b23479abe8c2ae5c7483ee4205b6a7b 100644 (file)
@@ -146,11 +146,10 @@ exec_to_string(const Args& args)
   });
 
   int status;
-  while ((result = waitpid(pid, &status, 0)) != pid) {
-    if (result == -1 && errno == EINTR) {
-      continue;
+  while (waitpid(pid, &status, 0) == -1) {
+    if (errno != EINTR) {
+      return tl::unexpected(FMT("waitpid failed: {}", strerror(errno)));
     }
-    return tl::unexpected(FMT("waitpid failed: {}", strerror(errno)));
   }
   if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
     return tl::unexpected(FMT("Non-zero exit code: {}", WEXITSTATUS(status)));