Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/process/v1/detail/posix/group_handle.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Copyright (c) 2016 Klemens D. Morgenstern
0002 //
0003 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0004 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 #ifndef BOOST_PROCESS_DETAIL_POSIX_GROUP_HPP_
0007 #define BOOST_PROCESS_DETAIL_POSIX_GROUP_HPP_
0008 
0009 #include <boost/process/v1/detail/config.hpp>
0010 #include <boost/process/v1/detail/posix/child_handle.hpp>
0011 #include <system_error>
0012 #include <unistd.h>
0013 
0014 namespace boost { namespace process { BOOST_PROCESS_V1_INLINE namespace v1 { namespace detail { namespace posix {
0015 
0016 struct group_handle
0017 {
0018     pid_t grp = -1;
0019 
0020     typedef pid_t handle_t;
0021     handle_t handle() const { return grp; }
0022 
0023     explicit group_handle(handle_t h) :
0024         grp(h)
0025     {
0026     }
0027 
0028      group_handle() = default;
0029 
0030     ~group_handle() = default;
0031     group_handle(const group_handle & c) = delete;
0032     group_handle(group_handle && c) : grp(c.grp)
0033     {
0034         c.grp = -1;
0035     }
0036     group_handle &operator=(const group_handle & c) = delete;
0037     group_handle &operator=(group_handle && c)
0038     {
0039         grp = c.grp;
0040         c.grp = -1;
0041         return *this;
0042     }
0043 
0044     void add(handle_t proc)
0045     {
0046         if (::setpgid(proc, grp))
0047             throw_last_error();
0048     }
0049     void add(handle_t proc, std::error_code & ec) noexcept
0050     {
0051         if (::setpgid(proc, grp))
0052             ec = get_last_error();
0053     }
0054 
0055     bool has(handle_t proc)
0056     {
0057         return ::getpgid(proc) == grp;
0058     }
0059     bool has(handle_t proc, std::error_code &) noexcept
0060     {
0061         return ::getpgid(proc) == grp;
0062     }
0063 
0064     bool valid() const
0065     {
0066         return grp != -1;
0067     }
0068 };
0069 
0070 inline  void terminate(group_handle &p, std::error_code &ec) noexcept
0071 {
0072     if (::killpg(p.grp, SIGKILL) == -1)
0073         ec = boost::process::v1::detail::get_last_error();
0074     else
0075         ec.clear();
0076 
0077     p.grp = -1;
0078 }
0079 
0080 inline void terminate(group_handle &p)
0081 {
0082     std::error_code ec;
0083     terminate(p, ec);
0084     boost::process::v1::detail::throw_error(ec, "killpg(2) failed in terminate");
0085 }
0086 
0087 inline bool in_group()
0088 {
0089     return true;
0090 }
0091 
0092 }}}}}
0093 
0094 #endif /* BOOST_PROCESS_DETAIL_WINDOWS_GROUP_HPP_ */