[svn-commits] tilghman: trunk r252846 - in /trunk: include/asterisk/ main/stdtime/ tests/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Mar 16 14:34:05 CDT 2010


Author: tilghman
Date: Tue Mar 16 14:34:01 2010
New Revision: 252846

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=252846
Log:
Fix test_time on Mac OS X (and other platforms without inotify)

Reviewboard: https://reviewboard.asterisk.org/r/554/

Modified:
    trunk/include/asterisk/localtime.h
    trunk/main/stdtime/localtime.c
    trunk/tests/test_time.c

Modified: trunk/include/asterisk/localtime.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/localtime.h?view=diff&rev=252846&r1=252845&r2=252846
==============================================================================
--- trunk/include/asterisk/localtime.h (original)
+++ trunk/include/asterisk/localtime.h Tue Mar 16 14:34:01 2010
@@ -78,4 +78,11 @@
  */
 char *ast_strptime(const char *s, const char *format, struct ast_tm *tm);
 
+/*!\brief Wakeup localtime monitor thread
+ * For use in testing.  Normally, the failsafe monitor thread waits 60 seconds
+ * between checks to verify whether a timezone file has changed.  This routine
+ * forces the monitor thread to wakeup immediately and check the timezone files.
+ */
+void ast_localtime_wakeup_monitor(void);
+
 #endif /* _ASTERISK_LOCALTIME_H */

Modified: trunk/main/stdtime/localtime.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/stdtime/localtime.c?view=diff&rev=252846&r1=252845&r2=252846
==============================================================================
--- trunk/main/stdtime/localtime.c (original)
+++ trunk/main/stdtime/localtime.c Tue Mar 16 14:34:01 2010
@@ -239,12 +239,11 @@
 	} buf;
 	ssize_t res;
 	struct state *cur;
-	struct timespec ten_seconds = { 10, 0 };
 
 	inotify_fd = inotify_init();
 
 	ast_mutex_lock(&initialization_lock);
-	ast_cond_signal(&initialization);
+	ast_cond_broadcast(&initialization);
 	ast_mutex_unlock(&initialization_lock);
 
 	if (inotify_fd < 0) {
@@ -261,8 +260,7 @@
 			break;
 		} else if (res < 0) {
 			if (errno == EINTR || errno == EAGAIN) {
-				/* If read fails, then wait a bit, then continue */
-				nanosleep(&ten_seconds, NULL);
+				/* If read fails, try again */
 				continue;
 			}
 			/* Sanity check -- this should never happen, either */
@@ -278,6 +276,7 @@
 			}
 		}
 		AST_LIST_TRAVERSE_SAFE_END
+		ast_cond_broadcast(&initialization);
 		AST_LIST_UNLOCK(&zonelist);
 	}
 	close(inotify_fd);
@@ -326,7 +325,7 @@
 	struct timespec sixty_seconds = { 60, 0 };
 
 	ast_mutex_lock(&initialization_lock);
-	ast_cond_signal(&initialization);
+	ast_cond_broadcast(&initialization);
 	ast_mutex_unlock(&initialization_lock);
 
 	for (;/*ever*/;) {
@@ -347,12 +346,14 @@
 			stat(name, &st);
 			lstat(name, &lst);
 			if (st.st_mtime > cur->mtime[0] || lst.st_mtime > cur->mtime[1]) {
+				ast_log(LOG_NOTICE, "Removing cached TZ entry '%s' because underlying file changed.\n", name);
 				AST_LIST_REMOVE_CURRENT(list);
 				ast_free(cur);
 				continue;
 			}
 		}
 		AST_LIST_TRAVERSE_SAFE_END
+		ast_cond_broadcast(&initialization);
 		AST_LIST_UNLOCK(&zonelist);
 	}
 	inotify_thread = AST_PTHREADT_NULL;
@@ -380,6 +381,16 @@
 	sp->mtime[1] = st.st_mtime;
 }
 #endif
+
+void ast_localtime_wakeup_monitor(void)
+{
+	if (inotify_thread != AST_PTHREADT_NULL) {
+		AST_LIST_LOCK(&zonelist);
+		pthread_kill(inotify_thread, SIGURG);
+		ast_cond_wait(&initialization, &(&zonelist)->lock);
+		AST_LIST_UNLOCK(&zonelist);
+	}
+}
 
 /*! \note
 ** Section 4.12.3 of X3.159-1989 requires that

Modified: trunk/tests/test_time.c
URL: http://svnview.digium.com/svn/asterisk/trunk/tests/test_time.c?view=diff&rev=252846&r1=252845&r2=252846
==============================================================================
--- trunk/tests/test_time.c (original)
+++ trunk/tests/test_time.c Tue Mar 16 14:34:01 2010
@@ -90,19 +90,26 @@
 			int system_res;
 			snprintf(syscmd, sizeof(syscmd), "%s " TZDIR "/%s %s", type == 0 ? "cp" : "ln -sf", zones[i], tzfile);
 			if ((system_res = system(syscmd))) {
-				ast_log(LOG_WARNING, "system() returned non-zero: %d\n", system_res);
+				ast_log(LOG_WARNING, "system(%s) returned non-zero: %d\n", syscmd, system_res);
 			}
+			ast_localtime_wakeup_monitor();
 			ast_localtime(&tv, &atm[i], tzfile);
 			if (i != 0) {
 				if (atm[i].tm_hour == atm[i - 1].tm_hour) {
 					res = AST_TEST_FAIL;
-					ast_test_status_update(test, "Failed %s test\n", type == 0 ? "deletion" : "symlink");
+					ast_test_status_update(test, "Failed %s test: %d(%s) = %d(%s)\n", type == 0 ? "deletion" : "symlink", atm[i].tm_hour, zones[i], atm[i-1].tm_hour, zones[i-1]);
 				}
 			}
+
+			/* stat(2) only has resolution to 1 second - must wait, or the mtime is the same */
+			usleep(1100000);
 		}
 	}
 
 	snprintf(syscmd, sizeof(syscmd), "rm -rf %s", tmpdir);
+	if (system(syscmd)) {
+		ast_log(LOG_WARNING, "system(%s) returned non-zero.\n", syscmd);
+	}
 
 	/* Restore SIGCHLD handler */
 	ast_unreplace_sigchld();




More information about the svn-commits mailing list