[asterisk-commits] mjordan: branch mjordan/1.8_instrumented r366295 - /team/mjordan/1.8_instrume...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri May 11 16:10:51 CDT 2012
Author: mjordan
Date: Fri May 11 16:10:47 2012
New Revision: 366295
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=366295
Log:
Address race condition in listener
Well, valgrind keeps complaining about it anyway
Modified:
team/mjordan/1.8_instrumented/main/asterisk.c
Modified: team/mjordan/1.8_instrumented/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/1.8_instrumented/main/asterisk.c?view=diff&rev=366295&r1=366294&r2=366295
==============================================================================
--- team/mjordan/1.8_instrumented/main/asterisk.c (original)
+++ team/mjordan/1.8_instrumented/main/asterisk.c Fri May 11 16:10:47 2012
@@ -190,6 +190,7 @@
/* XXX tmpdir is a subdir of the spool directory, and no way to remap it */
char record_cache_dir[AST_CACHE_DIR_LEN] = DEFAULT_TMP_DIR;
+AST_MUTEX_DEFINE_STATIC(listener_lock);
static int ast_socket = -1; /*!< UNIX Socket for allowing remote control */
static int ast_consock = -1; /*!< UNIX Socket for controlling another asterisk */
pid_t ast_mainpid;
@@ -1322,19 +1323,25 @@
int flags;
struct pollfd fds[1];
for (;;) {
- if (ast_socket < 0)
+ ast_mutex_lock(&listener_lock);
+ if (ast_socket < 0) {
+ ast_mutex_unlock(&listener_lock);
return NULL;
+ }
fds[0].fd = ast_socket;
fds[0].events = POLLIN;
s = ast_poll(fds, 1, -1);
pthread_testcancel();
if (s < 0) {
- if (errno != EINTR)
+ if (errno != EINTR) {
ast_log(LOG_WARNING, "poll returned error: %s\n", strerror(errno));
+ }
+ ast_mutex_unlock(&listener_lock);
continue;
}
len = sizeof(sunaddr);
s = accept(ast_socket, (struct sockaddr *)&sunaddr, &len);
+ ast_mutex_unlock(&listener_lock);
if (s < 0) {
if (errno != EINTR)
ast_log(LOG_WARNING, "Accept returned %d: %s\n", s, strerror(errno));
@@ -1739,10 +1746,12 @@
ast_debug(1, "Asterisk ending (%d).\n", num);
manager_event(EVENT_FLAG_SYSTEM, "Shutdown", "Shutdown: %s\r\nRestart: %s\r\n", ast_active_channels() ? "Uncleanly" : "Cleanly", restart ? "True" : "False");
if (ast_socket > -1) {
- pthread_cancel(lthread);
+ ast_mutex_lock(&listener_lock);
close(ast_socket);
ast_socket = -1;
unlink(ast_config_AST_SOCKET);
+ ast_mutex_unlock(&listener_lock);
+ pthread_cancel(lthread);
}
if (ast_consock > -1)
close(ast_consock);
More information about the asterisk-commits
mailing list