[asterisk-commits] dlee: branch 13 r431092 - in /branches/13: ./ channels/sip/include/ funcs/ in...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Jan 26 08:49:44 CST 2015
Author: dlee
Date: Mon Jan 26 08:49:32 2015
New Revision: 431092
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=431092
Log:
Various fixes for OS X
This patch addresses compilation errors on OS X. It's been a while, so
there's quite a few things.
* Fixed __attribute__ decls in route.h to be portable.
* Fixed htonll and ntohll to work when they are defined as macros.
* Replaced sem_t usage with our ast_sem wrapper.
* Added ast_sem_timedwait to our ast_sem wrapper.
* Fixed some GCC 4.9 warnings using sig*set() functions.
* Fixed some format strings for portability.
* Fixed compilation issues with res_timing_kqueue (although tests still fail
on OS X).
* Fixed menuconfig /sbin/launchd detection, which disables res_timing_kqueue
on OS X).
ASTERISK-24539 #close
Reported by: George Joseph
ASTERISK-24544 #close
Reported by: George Joseph
Review: https://reviewboard.asterisk.org/r/4327/
Modified:
branches/13/channels/sip/include/route.h
branches/13/configure
branches/13/configure.ac
branches/13/funcs/func_presencestate.c
branches/13/include/asterisk/autoconfig.h.in
branches/13/include/asterisk/sem.h
branches/13/main/app.c
branches/13/main/asterisk.c
branches/13/main/bridge_channel.c
branches/13/main/rtp_engine.c
branches/13/main/sem.c
branches/13/res/res_timing_kqueue.c
Modified: branches/13/channels/sip/include/route.h
URL: http://svnview.digium.com/svn/asterisk/branches/13/channels/sip/include/route.h?view=diff&rev=431092&r1=431091&r2=431092
==============================================================================
--- branches/13/channels/sip/include/route.h (original)
+++ branches/13/channels/sip/include/route.h Mon Jan 26 08:49:32 2015
@@ -98,7 +98,7 @@
* \retval NULL on failure
*/
struct ast_str *sip_route_list(const struct sip_route *route, int formatcli, int skip)
- __attribute_malloc__ __attribute_warn_unused_result__;
+ __attribute__((__malloc__)) __attribute__((__warn_unused_result__));
/*!
* \brief Check if the route is strict
Modified: branches/13/configure.ac
URL: http://svnview.digium.com/svn/asterisk/branches/13/configure.ac?view=diff&rev=431092&r1=431091&r2=431092
==============================================================================
--- branches/13/configure.ac (original)
+++ branches/13/configure.ac Mon Jan 26 08:49:32 2015
@@ -660,7 +660,25 @@
AC_FUNC_STRTOD
AC_FUNC_UTIME_NULL
AC_FUNC_VPRINTF
-AC_CHECK_FUNCS([asprintf atexit closefrom dup2 eaccess endpwent euidaccess ffsll ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday glob htonll ioperm inet_ntoa isascii memchr memmove memset mkdir mkdtemp munmap ntohll newlocale ppoll putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtod strtol strtold strtoq unsetenv utime vasprintf getpeereid sysctl swapctl])
+AC_CHECK_FUNCS([asprintf atexit closefrom dup2 eaccess endpwent euidaccess ffsll ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday glob ioperm inet_ntoa isascii memchr memmove memset mkdir mkdtemp munmap newlocale ppoll putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtod strtol strtold strtoq unsetenv utime vasprintf getpeereid sysctl swapctl])
+
+AC_MSG_CHECKING(for htonll)
+AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM([#include <arpa/inet.h>],
+ [return htonll(0);])],
+ AC_MSG_RESULT(yes)
+ AC_DEFINE(HAVE_HTONLL, 1, [Define to 1 if arpa/inet.h includes a htonll definition.]),
+ AC_MSG_RESULT(no)
+)
+
+AC_MSG_CHECKING(for ntohll)
+AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM([#include <arpa/inet.h>],
+ [return ntohll(0);])],
+ AC_MSG_RESULT(yes)
+ AC_DEFINE(HAVE_NTOHLL, 1, [Define to 1 if arpa/inet.h includes a ntohll definition.]),
+ AC_MSG_RESULT(no)
+)
# NOTE: we use AC_CHECK_LIB to get -lm into the arguments for later checks,
# so that AC_CHECK_FUNCS can detect functions in that library.
@@ -2432,10 +2450,9 @@
PBX_LAUNCHD=0
if test "${cross_compiling}" = "no";
then
- AC_CHECK_FILE(/sbin/launchd, AC_DEFINE([HAVE_SBIN_LAUNCHD], 1, [Define to 1 if your system has /sbin/launchd.]))
- if test "${HAVE_SBIN_LAUNCHD}" = 1; then
- PBX_LAUNCHD=1
- fi
+ AC_CHECK_FILE(/sbin/launchd,
+ [PBX_LAUNCHD=1]
+ AC_DEFINE([HAVE_SBIN_LAUNCHD], 1, [Define to 1 if your system has /sbin/launchd.]))
fi
AC_SUBST(PBX_LAUNCHD)
Modified: branches/13/funcs/func_presencestate.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/funcs/func_presencestate.c?view=diff&rev=431092&r1=431091&r2=431092
==============================================================================
--- branches/13/funcs/func_presencestate.c (original)
+++ branches/13/funcs/func_presencestate.c Mon Jan 26 08:49:32 2015
@@ -41,7 +41,7 @@
#include "asterisk/app.h"
#ifdef TEST_FRAMEWORK
#include "asterisk/test.h"
-#include <semaphore.h>
+#include "asterisk/sem.h"
#endif
/*** DOCUMENTATION
@@ -664,7 +664,7 @@
struct test_cb_data {
struct ast_presence_state_message *presence_state;
/* That's right. I'm using a semaphore */
- sem_t sem;
+ struct ast_sem sem;
};
static struct test_cb_data *test_cb_data_alloc(void)
@@ -675,7 +675,7 @@
return NULL;
}
- if (sem_init(&cb_data->sem, 0, 0)) {
+ if (ast_sem_init(&cb_data->sem, 0, 0)) {
ast_free(cb_data);
return NULL;
}
@@ -686,7 +686,7 @@
static void test_cb_data_destroy(struct test_cb_data *cb_data)
{
ao2_cleanup(cb_data->presence_state);
- sem_destroy(&cb_data->sem);
+ ast_sem_destroy(&cb_data->sem);
ast_free(cb_data);
}
@@ -699,7 +699,7 @@
cb_data->presence_state = stasis_message_data(msg);
ao2_ref(cb_data->presence_state, +1);
- sem_post(&cb_data->sem);
+ ast_sem_post(&cb_data->sem);
}
static enum ast_test_result_state presence_change_common(struct ast_test *test,
@@ -727,7 +727,7 @@
return AST_TEST_FAIL;
}
- sem_wait(&cb_data->sem);
+ ast_sem_wait(&cb_data->sem);
ast_copy_string(out_state, ast_presence_state2str(cb_data->presence_state->state), out_state_size);
ast_copy_string(out_subtype, cb_data->presence_state->subtype, out_subtype_size);
Modified: branches/13/include/asterisk/autoconfig.h.in
URL: http://svnview.digium.com/svn/asterisk/branches/13/include/asterisk/autoconfig.h.in?view=diff&rev=431092&r1=431091&r2=431092
==============================================================================
--- branches/13/include/asterisk/autoconfig.h.in (original)
+++ branches/13/include/asterisk/autoconfig.h.in Mon Jan 26 08:49:32 2015
@@ -324,7 +324,7 @@
/* Define to 1 if you have the Hoard Memory Allocator library. */
#undef HAVE_HOARD
-/* Define to 1 if you have the `htonll' function. */
+/* Define to 1 if arpa/inet.h includes a htonll definition. */
#undef HAVE_HTONLL
/* Define to 1 if you have the iCal library. */
@@ -524,7 +524,7 @@
/* Define to 1 if you have the newt library. */
#undef HAVE_NEWT
-/* Define to 1 if you have the `ntohll' function. */
+/* Define to 1 if arpa/inet.h includes a ntohll definition. */
#undef HAVE_NTOHLL
/* Define to 1 if your C library can safely print NULL to string formats. */
@@ -1299,6 +1299,11 @@
/* Define to 1 if running on Darwin. */
#undef _DARWIN_UNLIMITED_SELECT
+/* Enable large inode numbers on Mac OS X 10.5. */
+#ifndef _DARWIN_USE_64_BIT_INODE
+# define _DARWIN_USE_64_BIT_INODE 1
+#endif
+
/* Number of bits in a file offset, on hosts where this is settable. */
#undef _FILE_OFFSET_BITS
Modified: branches/13/include/asterisk/sem.h
URL: http://svnview.digium.com/svn/asterisk/branches/13/include/asterisk/sem.h?view=diff&rev=431092&r1=431091&r2=431092
==============================================================================
--- branches/13/include/asterisk/sem.h (original)
+++ branches/13/include/asterisk/sem.h Mon Jan 26 08:49:32 2015
@@ -57,6 +57,11 @@
static force_inline int ast_sem_wait(struct ast_sem *sem)
{
return sem_wait(&sem->real_sem);
+}
+
+static force_inline int ast_sem_timedwait(struct ast_sem *sem, const struct timespec *abs_timeout)
+{
+ return sem_timedwait(&sem->real_sem, abs_timeout);
}
static force_inline int ast_sem_getvalue(struct ast_sem *sem, int *sval)
@@ -137,6 +142,20 @@
int ast_sem_wait(struct ast_sem *sem);
/*!
+ * \brief Decrements the semaphore, waiting until abs_timeout.
+ *
+ * If the semaphore's current value is zero, this function blocks until another
+ * thread posts (ast_sem_post()) to the semaphore (or is interrupted by a signal
+ * handler, which sets errno to EINTR).
+ *
+ * \param sem Semaphore to decrement.
+ *
+ * \return 0 on success.
+ * \return -1 on error, errno set to indicate error.
+ */
+int ast_sem_timedwait(struct ast_sem *sem, const struct timespec *abs_timeout);
+
+/*!
* \brief Gets the current value of the semaphore.
*
* If threads are blocked on this semaphore, POSIX allows the return value to be
Modified: branches/13/main/app.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/main/app.c?view=diff&rev=431092&r1=431091&r2=431092
==============================================================================
--- branches/13/main/app.c (original)
+++ branches/13/main/app.c Mon Jan 26 08:49:32 2015
@@ -2911,7 +2911,9 @@
ast_replace_sigchld();
}
- sigfillset(&signal_set);
+ /* GCC 4.9 gives a bogus "right-hand operand of comma expression has
+ * no effect" warning */
+ (void) sigfillset(&signal_set);
pthread_sigmask(SIG_BLOCK, &signal_set, &old_set);
pid = fork();
Modified: branches/13/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/main/asterisk.c?view=diff&rev=431092&r1=431091&r2=431092
==============================================================================
--- branches/13/main/asterisk.c (original)
+++ branches/13/main/asterisk.c Mon Jan 26 08:49:32 2015
@@ -4366,12 +4366,14 @@
}
ast_makesocket();
- sigemptyset(&sigs);
- sigaddset(&sigs, SIGHUP);
- sigaddset(&sigs, SIGTERM);
- sigaddset(&sigs, SIGINT);
- sigaddset(&sigs, SIGPIPE);
- sigaddset(&sigs, SIGWINCH);
+ /* GCC 4.9 gives a bogus "right-hand operand of comma expression has
+ * no effect" warning */
+ (void) sigemptyset(&sigs);
+ (void) sigaddset(&sigs, SIGHUP);
+ (void) sigaddset(&sigs, SIGTERM);
+ (void) sigaddset(&sigs, SIGINT);
+ (void) sigaddset(&sigs, SIGPIPE);
+ (void) sigaddset(&sigs, SIGWINCH);
pthread_sigmask(SIG_BLOCK, &sigs, NULL);
sigaction(SIGURG, &urg_handler, NULL);
signal(SIGINT, __quit_handler);
Modified: branches/13/main/bridge_channel.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/main/bridge_channel.c?view=diff&rev=431092&r1=431091&r2=431092
==============================================================================
--- branches/13/main/bridge_channel.c (original)
+++ branches/13/main/bridge_channel.c Mon Jan 26 08:49:32 2015
@@ -35,7 +35,6 @@
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include <signal.h>
-#include <semaphore.h>
#include "asterisk/heap.h"
#include "asterisk/astobj2.h"
@@ -56,6 +55,7 @@
#include "asterisk/parking.h"
#include "asterisk/causes.h"
#include "asterisk/test.h"
+#include "asterisk/sem.h"
/*!
* \brief Used to queue an action frame onto a bridge channel and write an action frame into a bridge.
@@ -101,7 +101,7 @@
/*! Unique ID of this synchronization object. Corresponds with ID in synchronous frame payload */
unsigned int id;
/*! Semaphore used for synchronization */
- sem_t sem;
+ struct ast_sem sem;
/*! Pointer to next entry in the list */
AST_LIST_ENTRY(bridge_sync) list;
};
@@ -124,7 +124,7 @@
{
memset(sync_struct, 0, sizeof(*sync_struct));
sync_struct->id = id;
- sem_init(&sync_struct->sem, 0, 0);
+ ast_sem_init(&sync_struct->sem, 0, 0);
AST_RWLIST_WRLOCK(&sync_structs);
AST_RWLIST_INSERT_TAIL(&sync_structs, sync_struct, list);
@@ -157,7 +157,7 @@
AST_LIST_TRAVERSE_SAFE_END;
AST_RWLIST_UNLOCK(&sync_structs);
- sem_destroy(&sync_struct->sem);
+ ast_sem_destroy(&sync_struct->sem);
}
/*!
@@ -189,7 +189,7 @@
.tv_nsec = timeout_val.tv_usec * 1000,
};
- sem_timedwait(&sync_struct->sem, &timeout_spec);
+ ast_sem_timedwait(&sync_struct->sem, &timeout_spec);
}
/*!
@@ -204,7 +204,7 @@
*/
static void bridge_sync_signal(struct bridge_sync *sync_struct)
{
- sem_post(&sync_struct->sem);
+ ast_sem_post(&sync_struct->sem);
}
void ast_bridge_channel_lock_bridge(struct ast_bridge_channel *bridge_channel)
Modified: branches/13/main/rtp_engine.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/main/rtp_engine.c?view=diff&rev=431092&r1=431091&r2=431092
==============================================================================
--- branches/13/main/rtp_engine.c (original)
+++ branches/13/main/rtp_engine.c Mon Jan 26 08:49:32 2015
@@ -1948,7 +1948,7 @@
char sec[32];
char usec[32];
snprintf(sec, sizeof(sec), "%lu", payload->report->sender_information.ntp_timestamp.tv_sec);
- snprintf(usec, sizeof(usec), "%lu", payload->report->sender_information.ntp_timestamp.tv_usec);
+ snprintf(usec, sizeof(usec), "%lu", (unsigned long)payload->report->sender_information.ntp_timestamp.tv_usec);
json_rtcp_sender_info = ast_json_pack("{s: s, s: s, s: i, s: i, s: i}",
"ntp_timestamp_sec", sec,
"ntp_timestamp_usec", usec,
Modified: branches/13/main/sem.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/main/sem.c?view=diff&rev=431092&r1=431091&r2=431092
==============================================================================
--- branches/13/main/sem.c (original)
+++ branches/13/main/sem.c Mon Jan 26 08:49:32 2015
@@ -85,6 +85,7 @@
int ast_sem_wait(struct ast_sem *sem)
{
+ int res;
SCOPED_MUTEX(lock, &sem->mutex);
ast_assert(sem->count >= 0);
@@ -92,7 +93,37 @@
/* Wait for a non-zero count */
++sem->waiters;
while (sem->count == 0) {
- ast_cond_wait(&sem->cond, &sem->mutex);
+ res = ast_cond_wait(&sem->cond, &sem->mutex);
+ /* Give up on error */
+ if (res != 0) {
+ --sem->waiters;
+ return res;
+ }
+ }
+ --sem->waiters;
+
+ /* Take it! */
+ --sem->count;
+
+ return 0;
+}
+
+int ast_sem_timedwait(struct ast_sem *sem, const struct timespec *abs_timeout)
+{
+ int res;
+ SCOPED_MUTEX(lock, &sem->mutex);
+
+ ast_assert(sem->count >= 0);
+
+ /* Wait for a non-zero count */
+ ++sem->waiters;
+ while (sem->count == 0) {
+ res = ast_cond_timedwait(&sem->cond, &sem->mutex, abs_timeout);
+ /* Give up on error */
+ if (res != 0) {
+ --sem->waiters;
+ return res;
+ }
}
--sem->waiters;
Modified: branches/13/res/res_timing_kqueue.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/res/res_timing_kqueue.c?view=diff&rev=431092&r1=431091&r2=431092
==============================================================================
--- branches/13/res/res_timing_kqueue.c (original)
+++ branches/13/res/res_timing_kqueue.c Mon Jan 26 08:49:32 2015
@@ -91,12 +91,12 @@
if (!(timer = ao2_alloc(sizeof(*timer), timer_destroy))) {
ast_log(LOG_ERROR, "Could not allocate memory for kqueue_timer structure\n");
- return -1;
+ return NULL;
}
if ((timer->handle = kqueue()) < 0) {
ast_log(LOG_ERROR, "Failed to create kqueue timer: %s\n", strerror(errno));
ao2_ref(timer, -1);
- return -1;
+ return NULL;
}
return timer;
@@ -201,6 +201,8 @@
if (timer->unacked == 0) {
if (kevent(timer->handle, NULL, 0, &kev, 1, &sixty_seconds) > 0) {
timer->unacked += kev.data;
+ } else {
+ perror("kevent");
}
}
@@ -250,7 +252,7 @@
}
do {
- pfd.fd = ast_timer_fd(kt);
+ pfd.fd = kqueue_timer_fd(kt);
if (kqueue_timer_set_rate(kt, 1000)) {
ast_test_status_update(test, "Cannot set timer rate to 1000/s\n");
res = AST_TEST_FAIL;
@@ -271,13 +273,12 @@
res = AST_TEST_FAIL;
break;
}
-#if 0
if (kt->unacked == 0) {
ast_test_status_update(test, "Unacked events is 0, but there should be at least 1.\n");
res = AST_TEST_FAIL;
break;
}
-#endif
+
kqueue_timer_enable_continuous(kt);
start = ast_tvnow();
for (i = 0; i < 100; i++) {
More information about the asterisk-commits
mailing list