Merge "thread safety: Don't use getprotobyname()"

pull/7/head
zuul 8 years ago committed by Gerrit Code Review
commit 24ada76408

@ -7639,7 +7639,6 @@ static void *accept_thread(void *ignore)
struct sockaddr_in sin; struct sockaddr_in sin;
socklen_t sinlen; socklen_t sinlen;
struct skinnysession *s; struct skinnysession *s;
struct protoent *p;
int arg = 1; int arg = 1;
for (;;) { for (;;) {
@ -7656,12 +7655,10 @@ static void *accept_thread(void *ignore)
continue; continue;
} }
p = getprotobyname("tcp"); if (setsockopt(as, IPPROTO_TCP, TCP_NODELAY, (char *) &arg, sizeof(arg)) < 0) {
if(p) { ast_log(LOG_WARNING, "Failed to set TCP_NODELAY on Skinny TCP connection: %s\n", strerror(errno));
if( setsockopt(as, p->p_proto, TCP_NODELAY, (char *)&arg, sizeof(arg) ) < 0 ) {
ast_log(LOG_WARNING, "Failed to set Skinny tcp connection to TCP_NODELAY mode: %s\n", strerror(errno));
}
} }
if (!(s = ast_calloc(1, sizeof(struct skinnysession)))) { if (!(s = ast_calloc(1, sizeof(struct skinnysession)))) {
close(as); close(as);
ast_atomic_fetchadd_int(&unauth_sessions, -1); ast_atomic_fetchadd_int(&unauth_sessions, -1);

@ -86,6 +86,11 @@ const char *ast_inet_ntoa(struct in_addr ia);
#endif #endif
#define inet_ntoa __dont__use__inet_ntoa__use__ast_inet_ntoa__instead__ #define inet_ntoa __dont__use__inet_ntoa__use__ast_inet_ntoa__instead__
#ifdef getprotobyname
#undef getprotobyname
#endif
#define getprotobyname __getprotobyname_is_not_threadsafe__do_not_use__
/*! \brief Compares the source address and port of two sockaddr_in */ /*! \brief Compares the source address and port of two sockaddr_in */
static force_inline int inaddrcmp(const struct sockaddr_in *sin1, const struct sockaddr_in *sin2) static force_inline int inaddrcmp(const struct sockaddr_in *sin1, const struct sockaddr_in *sin2)
{ {

@ -1917,9 +1917,8 @@ static void *httpd_helper_thread(void *data)
* This is necessary to prevent delays (caused by buffering) as we * This is necessary to prevent delays (caused by buffering) as we
* write to the socket in bits and pieces. * write to the socket in bits and pieces.
*/ */
if (setsockopt(ast_iostream_get_fd(ser->stream), IPPROTO_TCP, TCP_NODELAY, (char *) &arg, sizeof(arg) ) < 0) { if (setsockopt(ast_iostream_get_fd(ser->stream), IPPROTO_TCP, TCP_NODELAY, (char *) &arg, sizeof(arg)) < 0) {
ast_log(LOG_WARNING, "Failed to set TCP_NODELAY on HTTP connection: %s\n", strerror(errno)); ast_log(LOG_WARNING, "Failed to set TCP_NODELAY on HTTP connection: %s\n", strerror(errno));
ast_log(LOG_WARNING, "Some HTTP requests may be slow to respond.\n");
} }
ast_iostream_nonblock(ser->stream); ast_iostream_nonblock(ser->stream);

@ -6647,8 +6647,8 @@ static void *session_do(void *data)
/* here we set TCP_NODELAY on the socket to disable Nagle's algorithm. /* here we set TCP_NODELAY on the socket to disable Nagle's algorithm.
* This is necessary to prevent delays (caused by buffering) as we * This is necessary to prevent delays (caused by buffering) as we
* write to the socket in bits and pieces. */ * write to the socket in bits and pieces. */
if (setsockopt(ast_iostream_get_fd(ser->stream), IPPROTO_TCP, TCP_NODELAY, (char *)&arg, sizeof(arg) ) < 0) { if (setsockopt(ast_iostream_get_fd(ser->stream), IPPROTO_TCP, TCP_NODELAY, (char *) &arg, sizeof(arg)) < 0) {
ast_log(LOG_WARNING, "Failed to set manager tcp connection to TCP_NODELAY mode: %s\nSome manager actions may be slow to respond.\n", strerror(errno)); ast_log(LOG_WARNING, "Failed to set TCP_NODELAY on manager connection: %s\n", strerror(errno));
} }
ast_iostream_nonblock(ser->stream); ast_iostream_nonblock(ser->stream);

Loading…
Cancel
Save