group_ref.hpp 1.1 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_POSIX_GROUP_REF_HPP_
  6. #define BOOST_PROCESS_DETAIL_POSIX_GROUP_REF_HPP_
  7. #include <boost/process/detail/config.hpp>
  8. #include <boost/process/detail/posix/group_handle.hpp>
  9. #include <boost/process/detail/posix/handler.hpp>
  10. #include <unistd.h>
  11. namespace boost { namespace process {
  12. namespace detail { namespace posix {
  13. struct group_ref : handler_base_ext
  14. {
  15. group_handle & grp;
  16. explicit group_ref(group_handle & g) :
  17. grp(g)
  18. {}
  19. template <class Executor>
  20. void on_exec_setup(Executor&) const
  21. {
  22. if (grp.grp == -1)
  23. ::setpgid(0, 0);
  24. else
  25. ::setpgid(0, grp.grp);
  26. }
  27. template <class Executor>
  28. void on_success(Executor& exec) const
  29. {
  30. if (grp.grp == -1)
  31. grp.grp = exec.pid;
  32. }
  33. };
  34. }}}}
  35. #endif /* BOOST_PROCESS_DETAIL_POSIX_GROUP_REF_HPP_ */