Imported Upstream version 1.64.0
[platform/upstream/boost.git] / boost / process / detail / posix / signal.hpp
1 // Copyright (c) 2006, 2007 Julio M. Merino Vidal
2 // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
3 // Copyright (c) 2009 Boris Schaeling
4 // Copyright (c) 2010 Felipe Tanus, Boris Schaeling
5 // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
6 // Copyright (c) 2016 Klemens D. Morgenstern
7 //
8 // Distributed under the Boost Software License, Version 1.0. (See accompanying
9 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10
11 #ifndef BOOST_PROCESS_POSIX_SIGNAL_HPP
12 #define BOOST_PROCESS_POSIX_SIGNAL_HPP
13
14 #include <boost/process/detail/posix/handler.hpp>
15 #include <signal.h>
16
17 namespace boost { namespace process { namespace detail { namespace posix {
18
19 #if defined(__GLIBC__)
20     using sighandler_t = ::sighandler_t;
21 #else
22     using sighandler_t = void(*)(int);
23 #endif
24
25
26 struct sig_init_ : handler_base_ext
27 {
28
29     sig_init_ (sighandler_t handler) : _handler(handler) {}
30
31     template <class PosixExecutor>
32     void on_exec_setup(PosixExecutor&)
33     {
34         _old = ::signal(SIGCHLD, _handler);
35     }
36
37     template <class Executor>
38     void on_error(Executor&, const std::error_code &)
39     {
40         if (!_reset)
41         {
42             ::signal(SIGCHLD, _old);
43             _reset = true;
44         }
45     }
46
47     template <class Executor>
48     void on_success(Executor&)
49     {
50         if (!_reset)
51         {
52             ::signal(SIGCHLD, _old);
53             _reset = true;
54         }
55     }
56 private:
57     bool _reset = false;
58     ::boost::process::detail::posix::sighandler_t _old{0};
59     ::boost::process::detail::posix::sighandler_t _handler{0};
60 };
61
62 struct sig_
63 {
64     constexpr sig_() {}
65
66     sig_init_ operator()(::boost::process::detail::posix::sighandler_t h) const {return h;}
67     sig_init_ operator= (::boost::process::detail::posix::sighandler_t h) const {return h;}
68     sig_init_ dfl() const {return SIG_DFL;}
69     sig_init_ ign() const {return SIG_IGN;}
70
71 };
72
73
74
75
76
77 }}}}
78
79 #endif