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