// We read an errno code; exec() failed, and the service startup failed.
if (sr->pid != -1) {
sr->child_listener.deregister(eventLoop, sr->pid);
+ sr->reserved_child_watch = false;
}
sr->pid = -1;
log(LogLevel::ERROR, sr->service_name, ": execution failed: ", strerror(exec_status));
}
else if (wait_r == 0) {
// We can track the child
- // TODO we must use a preallocated watch!!
- child_listener.add_watch(eventLoop, pid);
+ child_listener.add_reserved(eventLoop, pid, DEFAULT_PRIORITY - 10);
tracking_child = true;
+ reserved_child_watch = true;
return pid_result_t::OK;
}
else {
pid_t forkpid;
try {
- // We add the status listener with a high priority (i.e. low priority value) so that process
- // termination is handled early. This means we have always recorded that the process is
- // terminated by the time that we handle events that might otherwise cause us to signal the
- // process, so we avoid sending a signal to an invalid (and possibly recycled) process ID.
- child_status_listener.add_watch(eventLoop, pipefd[0], IN_EVENTS, true, DEFAULT_PRIORITY - 10);
+ child_status_listener.add_watch(eventLoop, pipefd[0], IN_EVENTS);
child_status_registered = true;
- forkpid = child_listener.fork(eventLoop);
+ // We specify a high priority (i.e. low priority value) so that process termination is
+ // handled early. This means we have always recorded that the process is terminated by the
+ // time that we handle events that might otherwise cause us to signal the process, so we
+ // avoid sending a signal to an invalid (and possibly recycled) process ID.
+ forkpid = child_listener.fork(eventLoop, reserved_child_watch, DEFAULT_PRIORITY - 10);
+ reserved_child_watch = true;
}
catch (std::exception &e) {
log(LogLevel::ERROR, service_name, ": Could not fork: ", e.what());
restart_interval.tv_sec = 10;
restart_interval.tv_nsec = 0;
max_restart_interval_count = 3;
+
+ waiting_restart_timer = false;
+ reserved_child_watch = false;
}
void base_process_service::do_restart() noexcept
int max_restart_interval_count;
timespec restart_delay;
- bool waiting_restart_timer = false;
+ bool waiting_restart_timer : 1;
+ bool reserved_child_watch : 1;
// Start the process, return true on success
virtual bool start_ps_process() noexcept override;
{
doing_recovery = false;
tracking_child = false;
+ reserved_child_watch = false;
}
~bgproc_service() noexcept