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_WINDOWS_GROUP_REF_HPP_ 7 #define BOOST_PROCESS_DETAIL_WINDOWS_GROUP_REF_HPP_ 8 9 #include <boost/winapi/process.hpp> 10 #include <boost/process/detail/config.hpp> 11 #include <boost/process/detail/windows/group_handle.hpp> 12 #include <boost/process/detail/used_handles.hpp> 13 #include <boost/process/detail/windows/handler.hpp> 14 15 namespace boost { namespace process { 16 17 namespace detail { namespace windows { 18 19 20 21 struct group_ref : handler_base_ext, ::boost::process::detail::uses_handles 22 { 23 ::boost::winapi::HANDLE_ handle; 24 get_used_handlesboost::process::detail::windows::group_ref25 ::boost::winapi::HANDLE_ get_used_handles() const { return handle; } 26 group_refboost::process::detail::windows::group_ref27 explicit group_ref(group_handle &g) : 28 handle(g.handle()) 29 {} 30 31 template <class Executor> on_setupboost::process::detail::windows::group_ref32 void on_setup(Executor& exec) const 33 { 34 //I can only enable this if the current process supports breakaways. 35 if (in_group() && break_away_enabled(nullptr)) 36 exec.creation_flags |= boost::winapi::CREATE_BREAKAWAY_FROM_JOB_; 37 } 38 39 40 template <class Executor> on_successboost::process::detail::windows::group_ref41 void on_success(Executor& exec) const 42 { 43 if (!::boost::winapi::AssignProcessToJobObject(handle, exec.proc_info.hProcess)) 44 exec.set_error(::boost::process::detail::get_last_error(), 45 "AssignProcessToJobObject() failed."); 46 47 } 48 49 }; 50 51 }}}} 52 53 54 #endif /* BOOST_PROCESS_DETAIL_WINDOWS_GROUP_HPP_ */ 55