mirror of https://github.com/Icinga/icinga2.git
StartUnixWorker(): watch forked child via waitpid(), not SIGCHLD handler
Before: On SIGCHLD from the forked worker the umbrella process sets a failure flag. StartUnixWorker() recognises that and does waitpid(), failure message, etc.. On OpenBSD we can't tell the signal source, so we always set the failure flag. That's not how our IPC shall work, that breaks the IPC sooner or later. After: No SIGCHLD handling and no failure flag setting. Instead StartUnixWorker()'s wait loop uses waitpid(x,y,WNOHANG) to avoid false positives while watching the forked worker.
This commit is contained in:
parent
643e9cd48b
commit
df9008bfc4
|
@ -381,13 +381,6 @@ static void UmbrellaSignalHandler(int num, siginfo_t *info, void*)
|
|||
l_CurrentlyStartingUnixWorkerState.store(UnixWorkerState::LoadedConfig);
|
||||
}
|
||||
break;
|
||||
case SIGCHLD:
|
||||
if (l_CurrentlyStartingUnixWorkerState.load() == UnixWorkerState::Pending
|
||||
&& (info->si_pid == 0 || info->si_pid == l_CurrentlyStartingUnixWorkerPid.load()) ) {
|
||||
// The seamless worker currently being started by StartUnixWorker() failed
|
||||
l_CurrentlyStartingUnixWorkerState.store(UnixWorkerState::Failed);
|
||||
}
|
||||
break;
|
||||
case SIGINT:
|
||||
case SIGTERM:
|
||||
// Someone requested our termination
|
||||
|
@ -570,30 +563,23 @@ static pid_t StartUnixWorker(const std::vector<std::string>& configs, bool close
|
|||
NotifyWatchdog();
|
||||
#endif /* HAVE_SYSTEMD */
|
||||
|
||||
switch (l_CurrentlyStartingUnixWorkerState.load()) {
|
||||
case UnixWorkerState::LoadedConfig:
|
||||
Log(LogNotice, "cli")
|
||||
<< "Worker process successfully loaded its config";
|
||||
break;
|
||||
case UnixWorkerState::Failed:
|
||||
if (waitpid(pid, nullptr, WNOHANG) > 0) {
|
||||
Log(LogNotice, "cli")
|
||||
<< "Worker process couldn't load its config";
|
||||
|
||||
while (waitpid(pid, nullptr, 0) == -1 && errno == EINTR) {
|
||||
#ifdef HAVE_SYSTEMD
|
||||
NotifyWatchdog();
|
||||
#endif /* HAVE_SYSTEMD */
|
||||
}
|
||||
pid = -2;
|
||||
break;
|
||||
default:
|
||||
Utility::Sleep(0.2);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (l_CurrentlyStartingUnixWorkerState.load() == UnixWorkerState::LoadedConfig) {
|
||||
Log(LogNotice, "cli")
|
||||
<< "Worker process successfully loaded its config";
|
||||
break;
|
||||
}
|
||||
|
||||
Utility::Sleep(0.2);
|
||||
}
|
||||
|
||||
// Reset flags for the next time
|
||||
l_CurrentlyStartingUnixWorkerPid.store(-1);
|
||||
l_CurrentlyStartingUnixWorkerState.store(UnixWorkerState::Pending);
|
||||
|
|
Loading…
Reference in New Issue