mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-03 11:25:35 +00:00
Fix processing of call files when using KQueue on OS X
In certain situations, call files are not processed when using KQueue with pbx_spool. Asterisk was sending an invalid timeout value when the spool directory is empty, causing the call to kevent to error immediately. This can create a tight loop, increasing the CPU load on the system. (closes issue ASTERISK-21176) Reported by: Carlton O'Riley patches: kqueue_osx.patch uploaded by coriley (License 6473) ........ Merged revisions 383120 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 383121 from http://svn.asterisk.org/svn/asterisk/branches/11 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@383122 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -645,9 +645,10 @@ static void *scan_thread(void *unused)
|
|||||||
char buf[8192] __attribute__((aligned (sizeof(int))));
|
char buf[8192] __attribute__((aligned (sizeof(int))));
|
||||||
struct pollfd pfd = { .fd = inotify_fd, .events = POLLIN };
|
struct pollfd pfd = { .fd = inotify_fd, .events = POLLIN };
|
||||||
#else
|
#else
|
||||||
struct timespec nowait = { 0, 1 };
|
struct timespec nowait = { .tv_sec = 0, .tv_nsec = 1 };
|
||||||
int inotify_fd = kqueue();
|
int inotify_fd = kqueue();
|
||||||
struct kevent kev;
|
struct kevent kev;
|
||||||
|
struct kevent event;
|
||||||
#endif
|
#endif
|
||||||
struct direntry *cur;
|
struct direntry *cur;
|
||||||
|
|
||||||
@@ -678,7 +679,7 @@ static void *scan_thread(void *unused)
|
|||||||
|
|
||||||
#ifndef HAVE_INOTIFY
|
#ifndef HAVE_INOTIFY
|
||||||
EV_SET(&kev, dirfd(dir), EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR, NOTE_WRITE, 0, NULL);
|
EV_SET(&kev, dirfd(dir), EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR, NOTE_WRITE, 0, NULL);
|
||||||
if (kevent(inotify_fd, &kev, 1, NULL, 0, &nowait) < 0 && errno != 0) {
|
if (kevent(inotify_fd, &kev, 1, &event, 1, &nowait) < 0 && errno != 0) {
|
||||||
ast_log(LOG_ERROR, "Unable to watch directory %s: %s\n", qdir, strerror(errno));
|
ast_log(LOG_ERROR, "Unable to watch directory %s: %s\n", qdir, strerror(errno));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -750,8 +751,18 @@ static void *scan_thread(void *unused)
|
|||||||
}
|
}
|
||||||
queue_created_files();
|
queue_created_files();
|
||||||
#else
|
#else
|
||||||
struct timespec ts2 = { next - now, 0 };
|
int num_events;
|
||||||
if (kevent(inotify_fd, NULL, 0, &kev, 1, &ts2) <= 0) {
|
/* If queue empty then wait forever */
|
||||||
|
if (next == INT_MAX) {
|
||||||
|
num_events = kevent(inotify_fd, &kev, 1, &event, 1, NULL);
|
||||||
|
} else {
|
||||||
|
struct timespec ts2 = { .tv_sec = (unsigned long int)(next - now), .tv_nsec = 0 };
|
||||||
|
num_events = kevent(inotify_fd, &kev, 1, &event, 1, &ts2);
|
||||||
|
}
|
||||||
|
if ((num_events < 0) || (event.flags == EV_ERROR)) {
|
||||||
|
ast_debug(10, "KEvent error %s\n", strerror(errno));
|
||||||
|
continue;
|
||||||
|
} else if (num_events == 0) {
|
||||||
/* Interrupt or timeout, restart calculations */
|
/* Interrupt or timeout, restart calculations */
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user