[icinga-checkins] icinga.org: icinga2/master: Don' t violate POSIX by ensuring that the argument to usleep(3) is less than 1000000

git at icinga.org git at icinga.org
Wed Aug 10 12:30:32 CEST 2016


Module: icinga2
Branch: master
Commit: 148b4da285859cb33fea42b5152ed0cbce6d6650
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=148b4da285859cb33fea42b5152ed0cbce6d6650

Author: Timo Buhrmester <van.fstd at gmail.com>
Date:   Wed Aug 10 11:51:13 2016 +0200

Don't violate POSIX by ensuring that the argument to usleep(3) is less than 1000000

fixes #12391

Signed-off-by: Gunnar Beutner <gunnar.beutner at netways.de>

---

 lib/base/utility.cpp |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/base/utility.cpp b/lib/base/utility.cpp
index ae2b9f6..9834a64 100644
--- a/lib/base/utility.cpp
+++ b/lib/base/utility.cpp
@@ -421,7 +421,11 @@ pid_t Utility::GetPid(void)
 void Utility::Sleep(double timeout)
 {
 #ifndef _WIN32
-	usleep(timeout * 1000 * 1000);
+	unsigned long micros = timeout * 1000000u;
+	if (timeout >= 1.0)
+		sleep((unsigned)timeout);
+
+	usleep(micros % 1000000u);
 #else /* _WIN32 */
 	::Sleep(timeout * 1000);
 #endif /* _WIN32 */



More information about the icinga-checkins mailing list