]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/process/detail/posix/is_running.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / process / detail / posix / is_running.hpp
CommitLineData
b32b8144
FG
1// Copyright (c) 2106 Klemens D. Morgenstern
2//
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef BOOST_PROCESS_DETAIL_POSIX_IS_RUNNING_HPP
7#define BOOST_PROCESS_DETAIL_POSIX_IS_RUNNING_HPP
8
9#include <boost/process/detail/config.hpp>
10#include <boost/process/detail/posix/child_handle.hpp>
11#include <system_error>
12#include <sys/wait.h>
13
14namespace boost { namespace process { namespace detail { namespace posix {
15
16
17constexpr int still_active = 0x7F;
18static_assert(!WIFEXITED(still_active), "Internal Error");
19
20inline bool is_running(const child_handle &p, int & exit_code)
21{
22 int status;
23 auto ret = ::waitpid(p.pid, &status, WNOHANG|WUNTRACED);
24
25 if (ret == -1)
26 {
27 if (errno != ECHILD) //because it no child is running, than this one isn't either, obviously.
28 ::boost::process::detail::throw_last_error("is_running error");
29
30 return false;
31 }
32 else if (ret == 0)
33 return true;
34 else //exited
35 {
36 if (WIFEXITED(status))
37 exit_code = status;
38 return false;
39 }
40}
41
42inline bool is_running(const child_handle &p, int & exit_code, std::error_code &ec) noexcept
43{
44 int status;
45 auto ret = ::waitpid(p.pid, &status, WNOHANG|WUNTRACED);
46
47 if (ret == -1)
48 {
49 if (errno != ECHILD) //because it no child is running, than this one isn't either, obviously.
50 ec = ::boost::process::detail::get_last_error();
51 return false;
52 }
53 else if (ret == 0)
54 return true;
55 else
56 {
57 ec.clear();
58
59 if (WIFEXITED(status))
60 exit_code = status;
61
62 return false;
63 }
64}
65
66inline bool is_running(int code)
67{
68 return !WIFEXITED(code);
69}
70
71inline int eval_exit_status(int code)
72{
73 return WEXITSTATUS(code);
74}
75
76}}}}
77
78#endif