group_ref.hpp 1.5 KB

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