]> granicus.if.org Git - icinga2/commitdiff
Don't abuse goto for building simple loops 7000/head
authorAlexander A. Klimov <alexander.klimov@icinga.com>
Fri, 8 Mar 2019 13:59:01 +0000 (14:59 +0100)
committerAlexander A. Klimov <alexander.klimov@icinga.com>
Fri, 8 Mar 2019 13:59:01 +0000 (14:59 +0100)
lib/base/application.cpp
lib/base/process.cpp

index df93710b71016312d91a152046439f3544e43b0b..e706932e89f1a5dff215b1f4ae8d66e2f028d6bd 100644 (file)
@@ -309,52 +309,48 @@ void Application::RunEventLoop()
 
        double lastLoop = Utility::GetTime();
 
-mainloop:
-       while (!m_ShuttingDown && !m_RequestRestart) {
-               /* Watches for changes to the system time. Adjusts timers if necessary. */
-               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;
+       while (!m_ShuttingDown) {
+               if (m_RequestRestart) {
+                       m_RequestRestart = false;         // we are now handling the request, once is enough
 
 #ifdef HAVE_SYSTEMD
-               sd_notify(0, "WATCHDOG=1");
+                       sd_notify(0, "RELOADING=1");
 #endif /* HAVE_SYSTEMD */
 
-               if (std::fabs(timeDiff) > 15) {
-                       /* We made a significant jump in time. */
-                       Log(LogInformation, "Application")
-                               << "We jumped "
-                               << (timeDiff < 0 ? "forward" : "backward")
-                               << " in time: " << std::fabs(timeDiff) << " seconds";
-
-                       Timer::AdjustTimers(-timeDiff);
-               }
+                       // are we already restarting? ignore request if we already are
+                       if (!l_Restarting) {
+                               l_Restarting = true;
+                               m_ReloadProcess = StartReloadProcess();
+                       }
+               } else {
+                       /* Watches for changes to the system time. Adjusts timers if necessary. */
+                       Utility::Sleep(2.5);
 
-               lastLoop = now;
-       }
+                       if (m_RequestReopenLogs) {
+                               Log(LogNotice, "Application", "Reopening log files");
+                               m_RequestReopenLogs = false;
+                               OnReopenLogs();
+                       }
 
-       if (m_RequestRestart) {
-               m_RequestRestart = false;         // we are now handling the request, once is enough
+                       double now = Utility::GetTime();
+                       double timeDiff = lastLoop - now;
 
 #ifdef HAVE_SYSTEMD
-               sd_notify(0, "RELOADING=1");
+                       sd_notify(0, "WATCHDOG=1");
 #endif /* HAVE_SYSTEMD */
 
-               // are we already restarting? ignore request if we already are
-               if (l_Restarting)
-                       goto mainloop;
+                       if (std::fabs(timeDiff) > 15) {
+                               /* We made a significant jump in time. */
+                               Log(LogInformation, "Application")
+                                       << "We jumped "
+                                       << (timeDiff < 0 ? "forward" : "backward")
+                                       << " in time: " << std::fabs(timeDiff) << " seconds";
 
-               l_Restarting = true;
-               m_ReloadProcess = StartReloadProcess();
+                               Timer::AdjustTimers(-timeDiff);
+                       }
 
-               goto mainloop;
+                       lastLoop = now;
+               }
        }
 
 #ifdef HAVE_SYSTEMD
index 71454b5acdfa55feb4f8027d1ab5cf26992cd2a6..50c99f60a2e069de5bb66dea508e90c9fe3c2aa5 100644 (file)
@@ -413,12 +413,11 @@ static pid_t ProcessSpawn(const std::vector<String>& arguments, const Dictionary
 
        msg.msg_controllen = cmsg->cmsg_len;
 
-send_message:
-       while (sendmsg(l_ProcessControlFD, &msg, 0) < 0)
-               StartSpawnProcessHelper();
-
-       if (send(l_ProcessControlFD, jrequest.CStr(), jrequest.GetLength(), 0) < 0)
-               goto send_message;
+       do {
+               while (sendmsg(l_ProcessControlFD, &msg, 0) < 0) {
+                       StartSpawnProcessHelper();
+               }
+       } while (send(l_ProcessControlFD, jrequest.CStr(), jrequest.GetLength(), 0) < 0);
 
        char buf[4096];
 
@@ -450,12 +449,11 @@ static int ProcessKill(pid_t pid, int signum)
 
        boost::mutex::scoped_lock lock(l_ProcessControlMutex);
 
-send_message:
-       while (send(l_ProcessControlFD, &length, sizeof(length), 0) < 0)
-               StartSpawnProcessHelper();
-
-       if (send(l_ProcessControlFD, jrequest.CStr(), jrequest.GetLength(), 0) < 0)
-               goto send_message;
+       do {
+               while (send(l_ProcessControlFD, &length, sizeof(length), 0) < 0) {
+                       StartSpawnProcessHelper();
+               }
+       } while (send(l_ProcessControlFD, jrequest.CStr(), jrequest.GetLength(), 0) < 0);
 
        char buf[4096];
 
@@ -482,12 +480,11 @@ static int ProcessWaitPID(pid_t pid, int *status)
 
        boost::mutex::scoped_lock lock(l_ProcessControlMutex);
 
-send_message:
-       while (send(l_ProcessControlFD, &length, sizeof(length), 0) < 0)
-               StartSpawnProcessHelper();
-
-       if (send(l_ProcessControlFD, jrequest.CStr(), jrequest.GetLength(), 0) < 0)
-               goto send_message;
+       do {
+               while (send(l_ProcessControlFD, &length, sizeof(length), 0) < 0) {
+                       StartSpawnProcessHelper();
+               }
+       } while (send(l_ProcessControlFD, jrequest.CStr(), jrequest.GetLength(), 0) < 0);
 
        char buf[4096];