[svn-commits] tilghman: trunk r251262 - in /trunk: ./ funcs/ include/asterisk/ main/ main/s...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sun Mar 7 23:13:00 CST 2010


Author: tilghman
Date: Sun Mar  7 23:12:55 2010
New Revision: 251262

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=251262
Log:
Change needed to make Mac OS X 10.6 happy

Modified:
    trunk/configure
    trunk/configure.ac
    trunk/funcs/func_pitchshift.c
    trunk/include/asterisk/autoconfig.h.in
    trunk/main/Makefile
    trunk/main/stdtime/localtime.c

Modified: trunk/configure.ac
URL: http://svnview.digium.com/svn/asterisk/trunk/configure.ac?view=diff&rev=251262&r1=251261&r2=251262
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Sun Mar  7 23:12:55 2010
@@ -317,6 +317,7 @@
 AST_EXT_LIB_SETUP([IODBC], [iODBC], [iodbc])
 AST_EXT_LIB_SETUP([ISDNNET], [ISDN4Linux Library], [isdnnet])
 AST_EXT_LIB_SETUP([JACK], [Jack Audio Connection Kit], [jack])
+AST_EXT_LIB_SETUP([KQUEUE], [kqueue support], [kqueue])
 AST_EXT_LIB_SETUP([LDAP], [OpenLDAP], [ldap])
 AST_EXT_LIB_SETUP([LIBXML2], [LibXML2], [libxml2])
 AST_EXT_LIB_SETUP([LTDL], [libtool], [ltdl])
@@ -1405,6 +1406,9 @@
 
 AST_EXT_LIB_CHECK([JACK], [jack], [jack_activate], [jack/jack.h])
 
+# BSD (and OS X) equivalent of inotify
+AST_EXT_LIB_CHECK([KQUEUE], [c], [kqueue], [sys/event.h])
+
 # Needed by unixodbc
 AST_EXT_LIB_CHECK([LTDL], [ltdl], [lt_dlinit], [ltdl.h], [])
 

Modified: trunk/funcs/func_pitchshift.c
URL: http://svnview.digium.com/svn/asterisk/trunk/funcs/func_pitchshift.c?view=diff&rev=251262&r1=251261&r2=251262
==============================================================================
--- trunk/funcs/func_pitchshift.c (original)
+++ trunk/funcs/func_pitchshift.c Sun Mar  7 23:12:55 2010
@@ -108,7 +108,9 @@
 	</function>
  ***/
 
+#ifndef M_PI
 #define M_PI 3.14159265358979323846
+#endif
 #define MAX_FRAME_LENGTH 256
 
 #define HIGHEST 2

Modified: trunk/include/asterisk/autoconfig.h.in
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/autoconfig.h.in?view=diff&rev=251262&r1=251261&r2=251262
==============================================================================
--- trunk/include/asterisk/autoconfig.h.in (original)
+++ trunk/include/asterisk/autoconfig.h.in Sun Mar  7 23:12:55 2010
@@ -424,6 +424,12 @@
 
 /* Define to the version of the Jack Audio Connection Kit library. */
 #undef HAVE_JACK_VERSION
+
+/* Define to 1 if you have the kqueue support library. */
+#undef HAVE_KQUEUE
+
+/* Define to the version of the kqueue support library. */
+#undef HAVE_KQUEUE_VERSION
 
 /* Define to 1 if you have the OpenLDAP library. */
 #undef HAVE_LDAP

Modified: trunk/main/Makefile
URL: http://svnview.digium.com/svn/asterisk/trunk/main/Makefile?view=diff&rev=251262&r1=251261&r2=251262
==============================================================================
--- trunk/main/Makefile (original)
+++ trunk/main/Makefile Sun Mar  7 23:12:55 2010
@@ -46,6 +46,9 @@
 ifneq ($(findstring darwin,$(OSARCH)),)
   AST_LIBS+=-lresolv
   ASTLINK=-Xlinker -macosx_version_min -Xlinker 10.4 -Xlinker -undefined -Xlinker dynamic_lookup -force_flat_namespace
+  ifeq ($(shell /usr/bin/sw_vers -productVersion | cut -c1-4),10.6)
+    ASTLINK+=/usr/lib/bundle1.o
+  endif
 else
 # These are used for all but Darwin
   ifneq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)

Modified: trunk/main/stdtime/localtime.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/stdtime/localtime.c?view=diff&rev=251262&r1=251261&r2=251262
==============================================================================
--- trunk/main/stdtime/localtime.c (original)
+++ trunk/main/stdtime/localtime.c Sun Mar  7 23:12:55 2010
@@ -53,6 +53,13 @@
 #include <float.h>
 #ifdef HAVE_INOTIFY
 #include <sys/inotify.h>
+#elif HAVE_KQUEUE
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/event.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 #endif
 
 #include "private.h"
@@ -152,6 +159,9 @@
 	struct lsinfo	lsis[TZ_MAX_LEAPS];
 #ifdef HAVE_INOTIFY
 	int wd[2];
+#elif defined(HAVE_KQUEUE)
+	int fd;
+	DIR *dir;
 #else
 	time_t  mtime[2];
 #endif
@@ -316,6 +326,129 @@
 			| IN_DONT_FOLLOW
 #endif
 		);
+	}
+}
+#elif HAVE_KQUEUE
+static int queue_fd = -1;
+
+static void *kqueue_daemon(void *data)
+{
+	struct kevent kev;
+	struct state *sp;
+	struct timespec no_wait = { 0, 1 };
+
+	if ((queue_fd = kqueue()) < 0) {
+		ast_log(LOG_ERROR, "Unable to initialize kqueue(): %s\n", strerror(errno));
+		inotify_thread = AST_PTHREADT_NULL;
+		ast_cond_signal(&initialization);
+		return NULL;
+	}
+
+	for (;/*ever*/;) {
+		if (kevent(queue_fd, NULL, 0, &kev, 1, NULL) < 0) {
+			continue;
+		}
+
+		sp = kev.udata;
+
+		/*!\note
+		 * If the file event fired, then the file was removed, so we'll need
+		 * to reparse the entry.  The directory event is a bit more
+		 * interesting.  Unfortunately, the queue doesn't contain information
+		 * about the file that changed (only the directory itself), so unless
+		 * we kept a record of the directory state before, it's not really
+		 * possible to know what change occurred.  But if we act paranoid and
+		 * just purge the associated file, then it will get reparsed, and
+		 * everything works fine.  It may be more work, but it's a vast
+		 * improvement over the alternative implementation, which is to stat
+		 * the file repeatedly in what is essentially a busy loop. */
+		AST_LIST_REMOVE(&zonelist, sp, list);
+
+#ifndef EV_RECEIPT
+#define EV_RECEIPT 0
+#endif
+		/* If the directory event fired, remove the file event */
+		EV_SET(&kev, sp->fd, EVFILT_VNODE, EV_DELETE | EV_RECEIPT, 0, 0, NULL);
+		kevent(queue_fd, &kev, 1, NULL, 0, &no_wait);
+		close(sp->fd);
+
+		if (sp->dir) {
+			/* If the file event fired, remove the directory event */
+			EV_SET(&kev, dirfd(sp->dir), EVFILT_VNODE, EV_DELETE | EV_RECEIPT, 0, 0, NULL);
+			kevent(queue_fd, &kev, 1, NULL, 0, &no_wait);
+			closedir(sp->dir);
+		}
+		free(sp);
+	}
+}
+
+static void add_notify(struct state *sp, const char *path)
+{
+	struct kevent kev;
+	struct timespec no_wait = { 0, 1 };
+	char watchdir[PATH_MAX + 1];
+
+	if (inotify_thread == AST_PTHREADT_NULL) {
+		ast_cond_init(&initialization, NULL);
+		ast_mutex_init(&initialization_lock);
+		ast_mutex_lock(&initialization_lock);
+		if (!(ast_pthread_create_background(&inotify_thread, NULL, kqueue_daemon, NULL))) {
+			/* Give the thread a chance to initialize */
+			ast_cond_wait(&initialization, &initialization_lock);
+		}
+		ast_mutex_unlock(&initialization_lock);
+	}
+
+	if (queue_fd < 0) {
+		/* Error already sent */
+		return;
+	}
+
+	if (readlink(path, watchdir, sizeof(watchdir) - 1) != -1) {
+		/* Special -- watch the directory for changes, because we cannot directly watch a symlink */
+		char *slash;
+		DIR *dir;
+
+		if ((slash = strrchr(watchdir, '/'))) {
+			*slash = '\0';
+		}
+		if (!(sp->dir = opendir(watchdir))) {
+			ast_log(LOG_ERROR, "Unable to watch directory with symlink '%s': %s\n", path, strerror(errno));
+			goto watch_file;
+		}
+
+		/*!\note
+		 * You may be wondering about whether there is a potential conflict
+		 * with the kqueue interface, because we might be watching the same
+		 * directory for multiple zones.  The answer is no, because kqueue
+		 * looks at the descriptor to know if there's a duplicate.  Since we
+		 * (may) have opened the directory multiple times, each represents a
+		 * different event, so no replacement of an existing event will occur.
+		 * Likewise, there's no potential leak of a descriptor.
+		 */
+		EV_SET(&kev, dirfd(sp->dir), EVFILT_VNODE, EV_ADD | EV_RECEIPT | EV_ONESHOT,
+				NOTE_WRITE | NOTE_EXTEND | NOTE_REVOKE, 0, sp);
+		if (kevent(queue_fd, &kev, 1, NULL, 0, &no_wait) < 0 && errno != 0) {
+			ast_log(LOG_ERROR, "Unable to watch '%s': %s\n", watchdir, strerror(errno));
+			closedir(dir);
+			goto watch_file;
+		}
+	}
+
+watch_file:
+	if ((sp->fd = open(path, O_RDONLY)) < 0) {
+		ast_log(LOG_ERROR, "Unable to watch '%s' for changes: %s\n", path, strerror(errno));
+		return;
+	}
+
+	EV_SET(&kev, sp->fd, EVFILT_VNODE, EV_ADD | EV_RECEIPT | EV_ONESHOT, NOTE_DELETE, 0, sp);
+	if (kevent(queue_fd, &kev, 1, NULL, 0, &no_wait) < 0 && errno != 0) {
+		/* According to the API docs, we may get -1 return value, due to the
+		 * NULL space for a returned event, but errno should be 0 unless
+		 * there's a real error. Otherwise, kevent will return 0 to indicate
+		 * that the time limit expired. */
+		ast_log(LOG_ERROR, "Unable to watch '%s': %s\n", path, strerror(errno));
+		close(sp->fd);
 	}
 }
 #else




More information about the svn-commits mailing list