From 65c723a4263f4c6d7980bd5b5b99fed656f0ca76 Mon Sep 17 00:00:00 2001 From: chenwei Date: Thu, 1 Mar 2018 15:39:33 +0800 Subject: [PATCH] Nginx : bugfix, changing `listening socket type` in cycle may lead to errors. Uses a temporaty variable to hold of potentially changing socket type but does not modify `listening socket type` in cycle. --- app/nginx-1.11.10/src/core/ngx_connection.c | 24 +++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/app/nginx-1.11.10/src/core/ngx_connection.c b/app/nginx-1.11.10/src/core/ngx_connection.c index 46c0ebc0..40391870 100644 --- a/app/nginx-1.11.10/src/core/ngx_connection.c +++ b/app/nginx-1.11.10/src/core/ngx_connection.c @@ -14,8 +14,13 @@ extern int fstack_territory(int domain, int type, int protocol); extern int is_fstack_fd(int sockfd); +/* + * ngx_ff_skip_listening_socket() decides whether to skip `ls`. + * If the current process is NGX_PROCESS_WORKER and `ls` is belong to fstack, + * then `*type` will be ls->type|SOCK_FSTACK when `type` is not null. + */ static ngx_inline int -ngx_ff_skip_listening_socket(ngx_cycle_t *cycle, ngx_listening_t *ls) +ngx_ff_skip_listening_socket(ngx_cycle_t *cycle, const ngx_listening_t *ls, int *type) { if (ngx_process <= NGX_PROCESS_MASTER) { @@ -37,7 +42,9 @@ ngx_ff_skip_listening_socket(ngx_cycle_t *cycle, ngx_listening_t *ls) return 1; } - ls->type |= SOCK_FSTACK; + if(type) { + *type |= SOCK_FSTACK; + } } else { ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "unexpected process type: %d, ignored", @@ -426,6 +433,10 @@ ngx_open_listening_sockets(ngx_cycle_t *cycle) ngx_socket_t s; ngx_listening_t *ls; +#if (NGX_HAVE_FSTACK) + int type; +#endif + reuseaddr = 1; #if (NGX_SUPPRESS_WARN) failed = 0; @@ -445,7 +456,8 @@ ngx_open_listening_sockets(ngx_cycle_t *cycle) #if (NGX_HAVE_FSTACK) - if(ngx_ff_skip_listening_socket(cycle, &ls[i])){ + type = ls[i].type; + if(ngx_ff_skip_listening_socket(cycle, &ls[i], &type)){ continue; } @@ -493,7 +505,11 @@ ngx_open_listening_sockets(ngx_cycle_t *cycle) continue; } +#if (NGX_HAVE_FSTACK) + s = ngx_socket(ls[i].sockaddr->sa_family, type, 0); +#else s = ngx_socket(ls[i].sockaddr->sa_family, ls[i].type, 0); +#endif if (s == (ngx_socket_t) -1) { ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, @@ -709,7 +725,7 @@ ngx_configure_listening_sockets(ngx_cycle_t *cycle) #if (NGX_HAVE_FSTACK) - if(ngx_ff_skip_listening_socket(cycle, &ls[i])){ + if(ngx_ff_skip_listening_socket(cycle, &ls[i], NULL)){ continue; }