From 3369b8367612abba378eeba9de8394837bd6f6cd Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Sun, 3 Aug 2025 08:00:05 +0200 Subject: [PATCH] refactor: Simplify EINTR check for waitpid --- src/ccache/execute.cpp | 7 +++---- src/ccache/util/exec.cpp | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/ccache/execute.cpp b/src/ccache/execute.cpp index 84d2c6d1..aa510514 100644 --- a/src/ccache/execute.cpp +++ b/src/ccache/execute.cpp @@ -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))); } { diff --git a/src/ccache/util/exec.cpp b/src/ccache/util/exec.cpp index 11cded4d..49ed7b3e 100644 --- a/src/ccache/util/exec.cpp +++ b/src/ccache/util/exec.cpp @@ -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))); -- 2.47.2