29 prefix_ senf::scheduler::detail::SignalDispatcher::SignalDispatcher()
32 if (pipe(sigPipe_) < 0)
34 sigemptyset(&sigSet_);
35 detail::FdManager::instance().set(sigPipe_[0], detail::FdManager::EV_READ,
this);
38 prefix_ senf::scheduler::detail::SignalDispatcher::~SignalDispatcher()
40 for (SignalSet::iterator i (handlers_.begin()); i != handlers_.end(); ++i) {
41 ::signal(i->signal_, SIG_DFL);
42 detail::FIFORunner::instance().dequeue(&(*i));
44 sigprocmask(SIG_UNBLOCK, &sigSet_, 0);
45 detail::FdManager::instance().remove(sigPipe_[0]);
50 prefix_ void senf::scheduler::detail::SignalDispatcher::add(SignalEvent & event)
52 SignalSet::iterator i (handlers_.find(event));
53 if (i != handlers_.end())
54 throw DuplicateSignalRegistrationException()
55 <<
" for signal " <<
signalName(event.signal_) <<
" (" <<
event.signal_ <<
")";
57 handlers_.insert(event);
58 sigaddset(&sigSet_, event.signal_);
59 detail::FIFORunner::instance().enqueue(&event);
63 sigaddset(&sig, event.signal_);
64 sigprocmask(blocked_ ? SIG_BLOCK : SIG_UNBLOCK, &sig, 0);
68 act.sa_sigaction = &sigHandler;
69 act.sa_mask = sigSet_;
70 act.sa_flags = SA_SIGINFO | SA_RESTART;
71 for (SignalSet::iterator i (handlers_.begin()); i != handlers_.end(); ++i) {
72 if (i->signal_ == SIGCHLD)
73 act.sa_flags |= SA_NOCLDSTOP;
75 act.sa_flags &= ~SA_NOCLDSTOP;
76 if (sigaction(i->signal_, &act, 0) < 0)
81 prefix_ void senf::scheduler::detail::SignalDispatcher::remove(SignalEvent & event)
83 ::signal(event.signal_, SIG_DFL);
84 detail::FIFORunner::instance().dequeue(&event);
85 handlers_.erase(event);
88 sigaddset(&sig, event.signal_);
89 sigprocmask(SIG_UNBLOCK, &sig, 0);
92 prefix_ void senf::scheduler::detail::SignalDispatcher::signal(
int events)
95 if (read(sigPipe_[0], &info,
sizeof(info)) <
int(
sizeof(info)))
97 SignalSet::iterator i (handlers_.find(info.si_signo, FindNumericSignal()));
98 if (i == handlers_.end())
104 prefix_ void senf::scheduler::detail::SignalDispatcher::sigHandler(
int signal,
105 ::siginfo_t * siginfo,
108 SENF_ASSERT( alive(),
"Internal failure: Destroyed signal handler called" );
110 siginfo->si_signo =
signal;
112 senf::IGNORE( write(instance().sigPipe_[1], siginfo,
sizeof(*siginfo)) );
115 prefix_ void senf::scheduler::SignalEvent::v_run()
120 prefix_ char const * senf::scheduler::SignalEvent::v_type()
126 prefix_ std::string senf::scheduler::SignalEvent::v_info()
#define SENF_THROW_SYSTEM_EXCEPTION(desc)
StatsDataCollectorKernel signal
SignalDispatcher public header.
#define SENF_ASSERT(x, comment)
std::string const & signalName(int signal)