From a05bb258b15455dedf282be0baae5dc3098442c1 Mon Sep 17 00:00:00 2001
From: Joshua Colp <jcolp@digium.com>
Date: Mon, 28 Dec 2015 16:02:19 -0400
Subject: [PATCH] test_time: Provide a timeout when waiting.

The test_timezone_watch unit test is written to expect a
condition to be signaled when the inotify daemon thread runs.
There exists a small window where the test_timezone_watch
thread can signal the inotify daemon thread while it is not
reading on the underlying file descriptor. If this occurs
the test_timezone_watch thread will wait indefinitely for a
signal that will never arrive.

This change adds a timeout to the condition so it will return
regardless after a period of time.

Change-Id: Ifed981879df6de3d93acd3ee0a70f92546517390
---
 main/stdtime/localtime.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/main/stdtime/localtime.c b/main/stdtime/localtime.c
index 927d473fd3..c10b7af623 100644
--- a/main/stdtime/localtime.c
+++ b/main/stdtime/localtime.c
@@ -796,13 +796,16 @@ static void sstate_free(struct state *p)
 
 void ast_localtime_wakeup_monitor(struct ast_test *info)
 {
+	struct timeval wait_now = ast_tvnow();
+	struct timespec wait_time = { .tv_sec = wait_now.tv_sec + 2, .tv_nsec = wait_now.tv_usec * 1000 };
+
 	if (inotify_thread != AST_PTHREADT_NULL) {
 		AST_LIST_LOCK(&zonelist);
 #ifdef TEST_FRAMEWORK
 		test = info;
 #endif
 		pthread_kill(inotify_thread, SIGURG);
-		ast_cond_wait(&initialization, &(&zonelist)->lock);
+		ast_cond_timedwait(&initialization, &(&zonelist)->lock, &wait_time);
 #ifdef TEST_FRAMEWORK
 		test = NULL;
 #endif
-- 
GitLab