OpenSDN source code
process_signal.cc
Go to the documentation of this file.
1 //
2 // Copyright (c) 2019 Juniper Networks, Inc. All rights reserved.
3 // Copyright Contributors to the OpenSDN project
4 //
5 
6 #include <sys/wait.h>
7 #include <boost/system/error_code.hpp>
8 
9 #include <io/process_signal.h>
10 
11 namespace process {
12 
13 boost::system::error_code Signal::InitializeSigChild() {
14  boost::system::error_code ec;
15 
17  ec = AddSignal(SIGCHLD);
18  }
19 
20  return ec;
21 }
22 
24  if (sigchld_callbacks_.empty()) {
25  // Add signal first
26  AddSignal(SIGCHLD);
27  }
28  sigchld_callbacks_.push_back(handler);
29 }
30 
31 bool Signal::HandleSigOsSpecific(const boost::system::error_code& error,
32  int sig) {
33  if (sig != SIGCHLD) {
34  return false;
35  }
36 
37  int status = 0;
38  pid_t pid = 0;
39 
40  while ((pid = WaitPid(-1, &status, WNOHANG)) > 0) {
41  NotifySigChld(error, sig, pid, status);
42  }
43 
44  return true;
45 }
46 
47 } // namespace process
virtual int WaitPid(int pid, int *status, int options)
boost::system::error_code InitializeSigChild()
boost::function< void(const boost::system::error_code &error, int sig, pid_t pid, int status)> SignalChildHandler
void RegisterHandler(int sig, SignalHandler handler)
std::vector< SignalChildHandler > sigchld_callbacks_
bool HandleSigOsSpecific(const boost::system::error_code &error, int sig)
boost::system::error_code AddSignal(int sig)
void NotifySigChld(const boost::system::error_code &error, int sig, int pid, int status)
bool always_handle_sigchild_