70 DL((
FORK,
"exec \"%s %s\")\n", cmd_.c_str (), args_.c_str ()));
71 if (cmd_.size () == 0) {
84 string arg_list (cmd_);
85 arg_list +=
" " + args_;
94 for (
int i = 0; i < 1024; i++) {
97 pid_t nullfd = open(
"/dev/null", O_WRONLY | O_CREAT, 0666);
99 syslog (LOG_ERR,
"failed to open \"/dev/null\"");
103 (void) dup2 (nullfd, 1);
104 (void) dup2 (nullfd, 2);
105 (void) close (nullfd);
108 execvp (cmd_.c_str (), argv);
110 EL((
ASSAERR,
"fork_exec (\"%s\") failed\n", cmd_.c_str ()));
114 if (! wait_for_completion_) {
138 DL((
FORK,
"Caught signal # %d\n", signum_));
140 if (signum_ == SIGCHLD) {
143 pid_t ret = ::wait (&status);
144 DL((
FORK,
"wait() = %d (PID)\n", ret));
146 if (ret > 0 && (WIFEXITED (status))) {
168 if ((
m_pid = fork()) < 0) {
169 EL((
ASSAERR,
"failed to fork() - out of swap space?\n"));
192 list<fnode_t* >::iterator i;
199 if ((*i)->needKill()) {
200 ::kill((*i)->getPID(), SIGTERM);
205 while ( !
m_list.empty() ) {
214 list<fnode_t* >::iterator j;
217 if ((*j)->getPID() == pid) {
Class to handle processing command-line options.
An abstract interface for handling I/O events, timers, and such.
ASSA_DECL_SINGLETON(ForkList)
A simple wrapper around fork() library function call.
#define EL(X)
A macro for writing error message to the Logger.
#define DL(X)
A macro for writing debug message to the Logger.
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
SigAction is a C++ wrapper around sigaction structure.
Class SigHandler is a UNIX signal handlers manager/dispatcher class.
int handle_signal(int signum_)
Signal handler callback.
static void str_to_argv(const string &src_, int &argc_, char **&argv_)
Static function.
ForkList is a singleton class that keeps a list of all forked children.
list< fnode_t * > m_list
List of children's data structures.
~ForkList()
Destructor. Wipe out childer based on their state.
Fork class is a simple wrapper around C library function fork().
state_t
Child completion states.
@ LEAVE_ALONE
Ignore all running children on exit.
bool isChild() const
Test whether we are in child section of the code.
@ COLLECT_STATUS
Wait for child to complete and collect its exit status.
SigAction m_old_disp
Old signal disposition.
SigHandler m_local_sh
Local signal handler.
static int fork_exec(const string &cmd_, const string &args_, wait4status_t wait_for_completion_, bool ignore_output_=false)
Execute an external command.
Fork(state_t exit_action_=WAIT_ON_EXIT, wait4status_t catch_status_=COLLECT_STATUS)
Fork the current process in two immediately.
int get_exit_status() const
Retrieve exit status of a child process if the constructor's parameter catch_status_ was set to TRUE.
pid_t getChildPID() const
Retrieve child process id.
ChildStatusHandler m_chstath
Handler to catch Child's status.
virtual int remove(int signum_, EventHandler *eh_=0, SigAction *new_disp_=0, SigAction *old_disp_=0)
Remove EventHandler associated with signum_.
virtual int install(int signum_, EventHandler *new_hand_, SigAction *new_disp_=0, EventHandler **old_hand_=0, SigAction *old_disp_=0)
Add new signal handler and new disposition for the signal.
static ForkList * get_instance()
Return an instance of templated class T.
@ FORK
Class Fork messages
@ ASSAERR
ASSA and system errors