group_ref.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. #ifndef BOOST_PROCESS_DETAIL_WINDOWS_GROUP_REF_HPP_
  6. #define BOOST_PROCESS_DETAIL_WINDOWS_GROUP_REF_HPP_
  7. #include <boost/process/detail/config.hpp>
  8. #include <boost/process/detail/windows/group_handle.hpp>
  9. #include <boost/winapi/process.hpp>
  10. #include <boost/process/detail/windows/handler.hpp>
  11. namespace boost { namespace process {
  12. namespace detail { namespace windows {
  13. struct group_ref : handler_base_ext
  14. {
  15. ::boost::winapi::HANDLE_ handle;
  16. explicit group_ref(group_handle &g) :
  17. handle(g.handle())
  18. {}
  19. template <class Executor>
  20. void on_setup(Executor& exec) const
  21. {
  22. //I can only enable this if the current process supports breakaways.
  23. if (in_group() && break_away_enabled(nullptr))
  24. exec.creation_flags |= boost::winapi::CREATE_BREAKAWAY_FROM_JOB_;
  25. }
  26. template <class Executor>
  27. void on_success(Executor& exec) const
  28. {
  29. if (!::boost::winapi::AssignProcessToJobObject(handle, exec.proc_info.hProcess))
  30. exec.set_error(::boost::process::detail::get_last_error(),
  31. "AssignProcessToJobObject() failed.");
  32. }
  33. };
  34. }}}}
  35. #endif /* BOOST_PROCESS_DETAIL_WINDOWS_GROUP_HPP_ */