comparison src/core/ngx_connection.c @ 6462:fd4b52e74f96

Fixed socket inheritance on reload and binary upgrade. On nginx reload or binary upgrade, an attempt is made to inherit listen sockets from the previous configuration. Previously, no check for socket type was made and the inherited socket could have the wrong type. On binary upgrade, socket type was not detected at all. Wrong socket type could lead to errors on that socket due to different logic and unsupported syscalls. For example, a UDP socket, inherited as TCP, lead to the following error after arrival of a datagram: "accept() failed (102: Operation not supported on socket)".
author Roman Arutyunyan <arut@nginx.com>
date Fri, 25 Mar 2016 14:10:38 +0300
parents 8f038068f4bc
children 2cd019520210
comparison
equal deleted inserted replaced
6461:a01e315b3a78 6462:fd4b52e74f96
208 208
209 ls[i].backlog = NGX_LISTEN_BACKLOG; 209 ls[i].backlog = NGX_LISTEN_BACKLOG;
210 210
211 olen = sizeof(int); 211 olen = sizeof(int);
212 212
213 if (getsockopt(ls[i].fd, SOL_SOCKET, SO_TYPE, (void *) &ls[i].type,
214 &olen)
215 == -1)
216 {
217 ngx_log_error(NGX_LOG_CRIT, cycle->log, ngx_socket_errno,
218 "getsockopt(SO_TYPE) %V failed", &ls[i].addr_text);
219 ls[i].ignore = 1;
220 continue;
221 }
222
223 olen = sizeof(int);
224
213 if (getsockopt(ls[i].fd, SOL_SOCKET, SO_RCVBUF, (void *) &ls[i].rcvbuf, 225 if (getsockopt(ls[i].fd, SOL_SOCKET, SO_RCVBUF, (void *) &ls[i].rcvbuf,
214 &olen) 226 &olen)
215 == -1) 227 == -1)
216 { 228 {
217 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, 229 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
271 } else { 283 } else {
272 ls[i].reuseport = reuseport ? 1 : 0; 284 ls[i].reuseport = reuseport ? 1 : 0;
273 } 285 }
274 286
275 #endif 287 #endif
288
289 if (ls[i].type != SOCK_STREAM) {
290 continue;
291 }
276 292
277 #if (NGX_HAVE_TCP_FASTOPEN) 293 #if (NGX_HAVE_TCP_FASTOPEN)
278 294
279 olen = sizeof(int); 295 olen = sizeof(int);
280 296