File indexing completed on 2025-01-18 09:50:06
0001
0002
0003
0004
0005
0006 #ifndef BOOST_PROCESS_DETAIL_POSIX_IS_RUNNING_HPP
0007 #define BOOST_PROCESS_DETAIL_POSIX_IS_RUNNING_HPP
0008
0009 #include <boost/process/detail/config.hpp>
0010 #include <boost/process/detail/posix/child_handle.hpp>
0011 #include <system_error>
0012 #include <sys/wait.h>
0013
0014 namespace boost { namespace process { namespace detail { namespace posix {
0015
0016
0017
0018
0019 constexpr int still_active = 0x017f;
0020 static_assert(WIFSTOPPED(still_active), "Expected still_active to indicate WIFSTOPPED");
0021 static_assert(!WIFEXITED(still_active), "Expected still_active to not indicate WIFEXITED");
0022 static_assert(!WIFSIGNALED(still_active), "Expected still_active to not indicate WIFSIGNALED");
0023 static_assert(!WIFCONTINUED(still_active), "Expected still_active to not indicate WIFCONTINUED");
0024
0025 inline bool is_running(int code)
0026 {
0027 return !WIFEXITED(code) && !WIFSIGNALED(code);
0028 }
0029
0030 inline bool is_running(const child_handle &p, int & exit_code, std::error_code &ec) noexcept
0031 {
0032 int status;
0033 auto ret = ::waitpid(p.pid, &status, WNOHANG);
0034
0035 if (ret == -1)
0036 {
0037 if (errno != ECHILD)
0038 ec = ::boost::process::detail::get_last_error();
0039 return false;
0040 }
0041 else if (ret == 0)
0042 return true;
0043 else
0044 {
0045 ec.clear();
0046
0047 if (!is_running(status))
0048 exit_code = status;
0049
0050 return false;
0051 }
0052 }
0053
0054 inline bool is_running(const child_handle &p, int & exit_code)
0055 {
0056 std::error_code ec;
0057 bool b = is_running(p, exit_code, ec);
0058 boost::process::detail::throw_error(ec, "waitpid(2) failed in is_running");
0059 return b;
0060 }
0061
0062 inline int eval_exit_status(int code)
0063 {
0064 if (WIFEXITED(code))
0065 {
0066 return WEXITSTATUS(code);
0067 }
0068 else if (WIFSIGNALED(code))
0069 {
0070 return WTERMSIG(code);
0071 }
0072 else
0073 {
0074 return code;
0075 }
0076 }
0077
0078 }}}}
0079
0080 #endif