summaryrefslogtreecommitdiff
path: root/channels/chan_sip.c
diff options
context:
space:
mode:
authorMichael Kuron <m.kuron@gmx.de>2016-11-26 17:57:03 +0100
committerMichael Kuron <m.kuron@gmx.de>2016-11-26 18:20:06 +0100
commit0b588778c0d2400e53e7dff6a3a270579acd51d6 (patch)
tree83414bb2d4f5b14e6200962b13454833e3fcdbdb /channels/chan_sip.c
parentd9b24cce0add96061a0b1e0f135b3148789af5ac (diff)
chan_sip: Fix segfault during module unload
If a TCP/TLS connection was pending (not accepted and not timed out) during unload of chan_sip, Asterisk would segfault when trying to send a signal to a thread whose thread ID hadn't been recorded yet. This commit fixes that by recording the thread ID before calling the blocking connect() syscall. This was a regression introduced by 776a14386a55b5425c7e9617eff8af8b45427144. The above wasn't enough to fix the segfault, which was now delayed to the point where connect() timed out. Therefore, it was necessary to also remove the SA_RESTART flag from the SIGURG sigaction so that pthread_kill() could be used to interruput the connect() syscall. This was a regression introduced by 5d313f51b982a18f7321adcf7c7a4e822d8b2714. ASTERISK-26586 #close Change-Id: I76fd9d47d56e4264e2629bce8ec15fecba673e7b
Diffstat (limited to 'channels/chan_sip.c')
-rw-r--r--channels/chan_sip.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 870b53edf..16d84af6c 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -2957,6 +2957,7 @@ static void *_sip_tcp_helper_thread(struct ast_tcptls_session_instance *tcptls_s
if (!(me = sip_threadinfo_create(tcptls_session, ast_iostream_get_ssl(tcptls_session->stream) ? AST_TRANSPORT_TLS : AST_TRANSPORT_TCP))) {
goto cleanup;
}
+ me->threadid = pthread_self();
ao2_t_ref(me, +1, "Adding threadinfo ref for tcp_helper_thread");
} else {
struct sip_threadinfo tmp = {
@@ -2964,8 +2965,13 @@ static void *_sip_tcp_helper_thread(struct ast_tcptls_session_instance *tcptls_s
};
if ((!(ca = tcptls_session->parent)) ||
- (!(me = ao2_t_find(threadt, &tmp, OBJ_POINTER, "ao2_find, getting sip_threadinfo in tcp helper thread"))) ||
- (!(tcptls_session = ast_tcptls_client_start(tcptls_session)))) {
+ (!(me = ao2_t_find(threadt, &tmp, OBJ_POINTER, "ao2_find, getting sip_threadinfo in tcp helper thread")))) {
+ goto cleanup;
+ }
+
+ me->threadid = pthread_self();
+
+ if (!(tcptls_session = ast_tcptls_client_start(tcptls_session))) {
goto cleanup;
}
}
@@ -2976,7 +2982,6 @@ static void *_sip_tcp_helper_thread(struct ast_tcptls_session_instance *tcptls_s
goto cleanup;
}
- me->threadid = pthread_self();
ast_debug(2, "Starting thread for %s server\n", ast_iostream_get_ssl(tcptls_session->stream) ? "TLS" : "TCP");
/* set up pollfd to watch for reads on both the socket and the alert_pipe */