]> granicus.if.org Git - icinga2/commitdiff
Bugfix: Make sure timeval is valid.
authorGunnar Beutner <gunnar.beutner@netways.de>
Thu, 19 Apr 2012 07:41:12 +0000 (09:41 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Thu, 19 Apr 2012 07:41:12 +0000 (09:41 +0200)
base/application.cpp

index 16dba4575097dce17b25f8b65550ccfed840b3b9..f7ba08925b8f194800d14bec4d7ebddbef51e3db 100644 (file)
@@ -79,13 +79,15 @@ void Application::RunEventLoop(void)
                                nfds = fd;
                }
 
-               long sleep = (long)(Timer::GetNextCall() - time(NULL));
+               time_t now = time(NULL);
+               time_t next = Timer::GetNextCall();
+               long sleep = (next < now) ? 0 : (next - now);
 
                if (m_ShuttingDown)
                        break;
 
                timeval tv;
-               tv.tv_sec = sleep;
+               tv.tv_sec = (sleep < 0) ? 0 : sleep;
                tv.tv_usec = 0;
 
                int ready;