]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/process/detail/posix/group_handle.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / process / detail / posix / group_handle.hpp
1 // Copyright (c) 2016 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_GROUP_HPP_
7 #define BOOST_PROCESS_DETAIL_POSIX_GROUP_HPP_
8
9 #include <boost/process/detail/posix/child_handle.hpp>
10 #include <system_error>
11 #include <unistd.h>
12
13 namespace boost { namespace process { namespace detail { namespace posix {
14
15
16
17 struct group_handle
18 {
19 pid_t grp = -1;
20
21 typedef pid_t handle_t;
22 handle_t handle() const { return grp; }
23
24 explicit group_handle(handle_t h) :
25 grp(h)
26 {
27 }
28
29
30 group_handle() = default;
31
32 ~group_handle() = default;
33 group_handle(const group_handle & c) = delete;
34 group_handle(group_handle && c) : grp(c.grp)
35 {
36 c.grp = -1;
37 }
38 group_handle &operator=(const group_handle & c) = delete;
39 group_handle &operator=(group_handle && c)
40 {
41
42 grp = c.grp;
43 c.grp = -1;
44 return *this;
45 }
46
47 void add(handle_t proc)
48 {
49 if (::setpgid(proc, grp))
50 throw_last_error();
51 }
52 void add(handle_t proc, std::error_code & ec) noexcept
53 {
54 if (::setpgid(proc, grp))
55 ec = get_last_error();
56 }
57
58 bool has(handle_t proc)
59 {
60 return ::getpgid(proc) == grp;
61 }
62 bool has(handle_t proc, std::error_code & ec) noexcept
63 {
64 return ::getpgid(proc) == grp;
65
66 }
67
68 bool valid() const
69 {
70 return grp != -1;
71 }
72
73 };
74
75 inline void terminate(group_handle &p)
76 {
77 if (::killpg(p.grp, SIGKILL) == -1)
78 boost::process::detail::throw_last_error("killpg(2) failed");
79 p.grp = -1;
80 }
81
82 inline void terminate(group_handle &p, std::error_code &ec) noexcept
83 {
84 if (::killpg(p.grp, SIGKILL) == -1)
85 ec = boost::process::detail::get_last_error();
86 else
87 ec.clear();
88
89 p.grp = -1;
90 }
91
92
93 inline bool in_group()
94 {
95 return true;
96 }
97
98
99
100 }}}}
101
102
103 #endif /* BOOST_PROCESS_DETAIL_WINDOWS_GROUP_HPP_ */