From c8179a99e0d1fd08f6bfa12f63994c155f46907f Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Sat, 24 May 2025 09:38:36 +0800 Subject: [PATCH] Checking waitpid res for zombie process reaping. Fixes comment by @mathisloge in issue #447. --- include/boost/process/v2/posix/default_launcher.hpp | 3 ++- include/boost/process/v2/posix/fork_and_forget_launcher.hpp | 3 ++- include/boost/process/v2/posix/pdfork_launcher.hpp | 3 ++- include/boost/process/v2/posix/vfork_launcher.hpp | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/boost/process/v2/posix/default_launcher.hpp b/include/boost/process/v2/posix/default_launcher.hpp index fc826fea2..7a2018c43 100644 --- a/include/boost/process/v2/posix/default_launcher.hpp +++ b/include/boost/process/v2/posix/default_launcher.hpp @@ -411,7 +411,8 @@ struct default_launcher if (ec) { detail::on_error(*this, executable, argv, ec, inits...); - do { ::waitpid(pid, nullptr, 0); } while (errno == EINTR); + int res = 0; + do { res = ::waitpid(pid, nullptr, 0); } while ((res == -1) && (errno == EINTR)); return basic_process{exec}; } } diff --git a/include/boost/process/v2/posix/fork_and_forget_launcher.hpp b/include/boost/process/v2/posix/fork_and_forget_launcher.hpp index f86314dee..26a1e6e45 100644 --- a/include/boost/process/v2/posix/fork_and_forget_launcher.hpp +++ b/include/boost/process/v2/posix/fork_and_forget_launcher.hpp @@ -124,7 +124,8 @@ struct fork_and_forget_launcher : default_launcher if (ec) { detail::on_error(*this, executable, argv, ec, inits...); - do { ::waitpid(pid, nullptr, 0); } while (errno == EINTR); + int res = 0; + do { res = ::waitpid(pid, nullptr, 0); } while ((res != -1) && (errno == EINTR)); return basic_process{exec}; } } diff --git a/include/boost/process/v2/posix/pdfork_launcher.hpp b/include/boost/process/v2/posix/pdfork_launcher.hpp index 0a082f562..5affc51e9 100644 --- a/include/boost/process/v2/posix/pdfork_launcher.hpp +++ b/include/boost/process/v2/posix/pdfork_launcher.hpp @@ -161,7 +161,8 @@ struct pdfork_launcher : default_launcher if (ec) { detail::on_error(*this, executable, argv, ec, inits...); - do { ::waitpid(pid, nullptr, 0); } while (errno == EINTR); + int res = 0; + do { res = ::waitpid(pid, nullptr, 0); } while ((res == -1) && (errno == EINTR)); return basic_process{exec}; } } diff --git a/include/boost/process/v2/posix/vfork_launcher.hpp b/include/boost/process/v2/posix/vfork_launcher.hpp index bb1b9f2ca..49e2a70b0 100644 --- a/include/boost/process/v2/posix/vfork_launcher.hpp +++ b/include/boost/process/v2/posix/vfork_launcher.hpp @@ -121,7 +121,8 @@ struct vfork_launcher : default_launcher if (ec) { detail::on_error(*this, executable, argv, ec, inits...); - do { ::waitpid(pid, nullptr, 0); } while (errno == EINTR); + int res = 0; + do { res = ::waitpid(pid, nullptr, 0); } while ((res != -1) && (errno == EINTR)); return basic_process{exec}; }