mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-24 22:24:44 +02:00
Merge pull request #7000 from Icinga/bugfix/goto-loop
Don't abuse goto for building simple loops
This commit is contained in:
commit
c2f180395a
@ -300,52 +300,48 @@ void Application::RunEventLoop()
|
|||||||
|
|
||||||
double lastLoop = Utility::GetTime();
|
double lastLoop = Utility::GetTime();
|
||||||
|
|
||||||
mainloop:
|
while (!m_ShuttingDown) {
|
||||||
while (!m_ShuttingDown && !m_RequestRestart) {
|
if (m_RequestRestart) {
|
||||||
/* Watches for changes to the system time. Adjusts timers if necessary. */
|
m_RequestRestart = false; // we are now handling the request, once is enough
|
||||||
Utility::Sleep(2.5);
|
|
||||||
|
|
||||||
if (m_RequestReopenLogs) {
|
|
||||||
Log(LogNotice, "Application", "Reopening log files");
|
|
||||||
m_RequestReopenLogs = false;
|
|
||||||
OnReopenLogs();
|
|
||||||
}
|
|
||||||
|
|
||||||
double now = Utility::GetTime();
|
|
||||||
double timeDiff = lastLoop - now;
|
|
||||||
|
|
||||||
#ifdef HAVE_SYSTEMD
|
#ifdef HAVE_SYSTEMD
|
||||||
sd_notify(0, "WATCHDOG=1");
|
sd_notify(0, "RELOADING=1");
|
||||||
#endif /* HAVE_SYSTEMD */
|
#endif /* HAVE_SYSTEMD */
|
||||||
|
|
||||||
if (std::fabs(timeDiff) > 15) {
|
// are we already restarting? ignore request if we already are
|
||||||
/* We made a significant jump in time. */
|
if (!l_Restarting) {
|
||||||
Log(LogInformation, "Application")
|
l_Restarting = true;
|
||||||
<< "We jumped "
|
m_ReloadProcess = StartReloadProcess();
|
||||||
<< (timeDiff < 0 ? "forward" : "backward")
|
}
|
||||||
<< " in time: " << std::fabs(timeDiff) << " seconds";
|
} else {
|
||||||
|
/* Watches for changes to the system time. Adjusts timers if necessary. */
|
||||||
|
Utility::Sleep(2.5);
|
||||||
|
|
||||||
Timer::AdjustTimers(-timeDiff);
|
if (m_RequestReopenLogs) {
|
||||||
}
|
Log(LogNotice, "Application", "Reopening log files");
|
||||||
|
m_RequestReopenLogs = false;
|
||||||
|
OnReopenLogs();
|
||||||
|
}
|
||||||
|
|
||||||
lastLoop = now;
|
double now = Utility::GetTime();
|
||||||
}
|
double timeDiff = lastLoop - now;
|
||||||
|
|
||||||
if (m_RequestRestart) {
|
|
||||||
m_RequestRestart = false; // we are now handling the request, once is enough
|
|
||||||
|
|
||||||
#ifdef HAVE_SYSTEMD
|
#ifdef HAVE_SYSTEMD
|
||||||
sd_notify(0, "RELOADING=1");
|
sd_notify(0, "WATCHDOG=1");
|
||||||
#endif /* HAVE_SYSTEMD */
|
#endif /* HAVE_SYSTEMD */
|
||||||
|
|
||||||
// are we already restarting? ignore request if we already are
|
if (std::fabs(timeDiff) > 15) {
|
||||||
if (l_Restarting)
|
/* We made a significant jump in time. */
|
||||||
goto mainloop;
|
Log(LogInformation, "Application")
|
||||||
|
<< "We jumped "
|
||||||
|
<< (timeDiff < 0 ? "forward" : "backward")
|
||||||
|
<< " in time: " << std::fabs(timeDiff) << " seconds";
|
||||||
|
|
||||||
l_Restarting = true;
|
Timer::AdjustTimers(-timeDiff);
|
||||||
m_ReloadProcess = StartReloadProcess();
|
}
|
||||||
|
|
||||||
goto mainloop;
|
lastLoop = now;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_SYSTEMD
|
#ifdef HAVE_SYSTEMD
|
||||||
|
@ -399,12 +399,11 @@ static pid_t ProcessSpawn(const std::vector<String>& arguments, const Dictionary
|
|||||||
|
|
||||||
msg.msg_controllen = cmsg->cmsg_len;
|
msg.msg_controllen = cmsg->cmsg_len;
|
||||||
|
|
||||||
send_message:
|
do {
|
||||||
while (sendmsg(l_ProcessControlFD, &msg, 0) < 0)
|
while (sendmsg(l_ProcessControlFD, &msg, 0) < 0) {
|
||||||
StartSpawnProcessHelper();
|
StartSpawnProcessHelper();
|
||||||
|
}
|
||||||
if (send(l_ProcessControlFD, jrequest.CStr(), jrequest.GetLength(), 0) < 0)
|
} while (send(l_ProcessControlFD, jrequest.CStr(), jrequest.GetLength(), 0) < 0);
|
||||||
goto send_message;
|
|
||||||
|
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
|
|
||||||
@ -436,12 +435,11 @@ static int ProcessKill(pid_t pid, int signum)
|
|||||||
|
|
||||||
boost::mutex::scoped_lock lock(l_ProcessControlMutex);
|
boost::mutex::scoped_lock lock(l_ProcessControlMutex);
|
||||||
|
|
||||||
send_message:
|
do {
|
||||||
while (send(l_ProcessControlFD, &length, sizeof(length), 0) < 0)
|
while (send(l_ProcessControlFD, &length, sizeof(length), 0) < 0) {
|
||||||
StartSpawnProcessHelper();
|
StartSpawnProcessHelper();
|
||||||
|
}
|
||||||
if (send(l_ProcessControlFD, jrequest.CStr(), jrequest.GetLength(), 0) < 0)
|
} while (send(l_ProcessControlFD, jrequest.CStr(), jrequest.GetLength(), 0) < 0);
|
||||||
goto send_message;
|
|
||||||
|
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
|
|
||||||
@ -468,12 +466,11 @@ static int ProcessWaitPID(pid_t pid, int *status)
|
|||||||
|
|
||||||
boost::mutex::scoped_lock lock(l_ProcessControlMutex);
|
boost::mutex::scoped_lock lock(l_ProcessControlMutex);
|
||||||
|
|
||||||
send_message:
|
do {
|
||||||
while (send(l_ProcessControlFD, &length, sizeof(length), 0) < 0)
|
while (send(l_ProcessControlFD, &length, sizeof(length), 0) < 0) {
|
||||||
StartSpawnProcessHelper();
|
StartSpawnProcessHelper();
|
||||||
|
}
|
||||||
if (send(l_ProcessControlFD, jrequest.CStr(), jrequest.GetLength(), 0) < 0)
|
} while (send(l_ProcessControlFD, jrequest.CStr(), jrequest.GetLength(), 0) < 0);
|
||||||
goto send_message;
|
|
||||||
|
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user