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_REF_HPP_ 7 #define BOOST_PROCESS_DETAIL_POSIX_GROUP_REF_HPP_ 8 9 #include <boost/process/detail/config.hpp> 10 #include <boost/process/detail/posix/group_handle.hpp> 11 #include <boost/process/detail/posix/handler.hpp> 12 #include <unistd.h> 13 14 15 namespace boost { namespace process { 16 17 namespace detail { namespace posix { 18 19 20 21 struct group_ref : handler_base_ext 22 { 23 group_handle & grp; 24 25 group_refboost::process::detail::posix::group_ref26 explicit group_ref(group_handle & g) : 27 grp(g) 28 {} 29 30 template <class Executor> on_exec_setupboost::process::detail::posix::group_ref31 void on_exec_setup(Executor&) const 32 { 33 if (grp.grp == -1) 34 ::setpgid(0, 0); 35 else 36 ::setpgid(0, grp.grp); 37 } 38 39 template <class Executor> on_successboost::process::detail::posix::group_ref40 void on_success(Executor& exec) const 41 { 42 if (grp.grp == -1) 43 grp.grp = exec.pid; 44 45 } 46 47 }; 48 49 }}}} 50 51 52 #endif /* BOOST_PROCESS_DETAIL_POSIX_GROUP_REF_HPP_ */ 53