Mercurial > hg > nginx-vendor-current
comparison src/core/ngx_cycle.c @ 10:46833bd150cb NGINX_0_1_5
nginx 0.1.5
*) Bugfix: on Solaris and Linux there may be too many "recvmsg()
returned not enough data" alerts.
*) Bugfix: there were the "writev() failed (22: Invalid argument)"
errors on Solaris in proxy mode without sendfile. On other platforms
that do not support sendfile at all the process got caught in an
endless loop.
*) Bugfix: segmentation fault on Solaris in proxy mode and using
sendfile.
*) Bugfix: segmentation fault on Solaris.
*) Bugfix: on-line upgrade did not work on Linux.
*) Bugfix: the ngx_http_autoindex_module module did not escape the
spaces, the quotes, and the percent signs in the directory listing.
*) Change: the decrease of the copy operations.
*) Feature: the userid_p3p directive.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Thu, 11 Nov 2004 00:00:00 +0300 |
parents | 4b2dafa26fe2 |
children | 74b1868dd3cd |
comparison
equal
deleted
inserted
replaced
9:77eee314ddbd | 10:46833bd150cb |
---|---|
7 #include <ngx_config.h> | 7 #include <ngx_config.h> |
8 #include <ngx_core.h> | 8 #include <ngx_core.h> |
9 #include <ngx_event.h> | 9 #include <ngx_event.h> |
10 | 10 |
11 | 11 |
12 static ngx_int_t ngx_cmp_sockaddr(struct sockaddr *s1, struct sockaddr *s2); | |
12 static void ngx_clean_old_cycles(ngx_event_t *ev); | 13 static void ngx_clean_old_cycles(ngx_event_t *ev); |
13 | 14 |
14 | 15 |
15 volatile ngx_cycle_t *ngx_cycle; | 16 volatile ngx_cycle_t *ngx_cycle; |
16 ngx_array_t ngx_old_cycles; | 17 ngx_array_t ngx_old_cycles; |
193 | 194 |
194 | 195 |
195 failed = 0; | 196 failed = 0; |
196 | 197 |
197 | 198 |
198 #if !(WIN32) | 199 #if !(NGX_WIN32) |
199 if (ngx_create_pidfile(cycle, old_cycle) == NGX_ERROR) { | 200 if (ngx_create_pidfile(cycle, old_cycle) == NGX_ERROR) { |
200 failed = 1; | 201 failed = 1; |
201 } | 202 } |
202 #endif | 203 #endif |
203 | 204 |
204 | 205 |
205 if (!failed) { | 206 if (!failed) { |
207 | |
208 /* open the new files */ | |
206 | 209 |
207 part = &cycle->open_files.part; | 210 part = &cycle->open_files.part; |
208 file = part->elts; | 211 file = part->elts; |
209 | 212 |
210 for (i = 0; /* void */ ; i++) { | 213 for (i = 0; /* void */ ; i++) { |
225 file[i].fd = ngx_open_file(file[i].name.data, | 228 file[i].fd = ngx_open_file(file[i].name.data, |
226 NGX_FILE_RDWR, | 229 NGX_FILE_RDWR, |
227 NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND); | 230 NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND); |
228 | 231 |
229 ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0, | 232 ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0, |
230 "log: %0X %d \"%s\"", | 233 "log: %p %d \"%s\"", |
231 &file[i], file[i].fd, file[i].name.data); | 234 &file[i], file[i].fd, file[i].name.data); |
232 | 235 |
233 if (file[i].fd == NGX_INVALID_FILE) { | 236 if (file[i].fd == NGX_INVALID_FILE) { |
234 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, | 237 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, |
235 ngx_open_file_n " \"%s\" failed", | 238 ngx_open_file_n " \"%s\" failed", |
236 file[i].name.data); | 239 file[i].name.data); |
237 failed = 1; | 240 failed = 1; |
238 break; | 241 break; |
239 } | 242 } |
240 | 243 |
241 #if (WIN32) | 244 #if (NGX_WIN32) |
242 if (ngx_file_append_mode(file[i].fd) == NGX_ERROR) { | 245 if (ngx_file_append_mode(file[i].fd) == NGX_ERROR) { |
243 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, | 246 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, |
244 ngx_file_append_mode_n " \"%s\" failed", | 247 ngx_file_append_mode_n " \"%s\" failed", |
245 file[i].name.data); | 248 file[i].name.data); |
246 failed = 1; | 249 failed = 1; |
264 if (cycle->log->log_level == 0) { | 267 if (cycle->log->log_level == 0) { |
265 cycle->log->log_level = NGX_LOG_ERR; | 268 cycle->log->log_level = NGX_LOG_ERR; |
266 } | 269 } |
267 | 270 |
268 if (!failed) { | 271 if (!failed) { |
272 | |
273 /* handle the listening sockets */ | |
274 | |
269 if (old_cycle->listening.nelts) { | 275 if (old_cycle->listening.nelts) { |
270 ls = old_cycle->listening.elts; | 276 ls = old_cycle->listening.elts; |
271 for (i = 0; i < old_cycle->listening.nelts; i++) { | 277 for (i = 0; i < old_cycle->listening.nelts; i++) { |
272 ls[i].remain = 0; | 278 ls[i].remain = 0; |
273 } | 279 } |
274 | 280 |
275 nls = cycle->listening.elts; | 281 nls = cycle->listening.elts; |
276 for (n = 0; n < cycle->listening.nelts; n++) { | 282 for (n = 0; n < cycle->listening.nelts; n++) { |
283 | |
277 for (i = 0; i < old_cycle->listening.nelts; i++) { | 284 for (i = 0; i < old_cycle->listening.nelts; i++) { |
278 if (ls[i].ignore) { | 285 if (ls[i].ignore) { |
279 continue; | 286 continue; |
280 } | 287 } |
281 | 288 |
282 if (ngx_memcmp(nls[n].sockaddr, | 289 if (ngx_cmp_sockaddr(nls[n].sockaddr, ls[i].sockaddr) |
283 ls[i].sockaddr, ls[i].socklen) == 0) | 290 == NGX_OK) |
284 { | 291 { |
285 fd = ls[i].fd; | 292 fd = ls[i].fd; |
286 #if (WIN32) | 293 #if (NGX_WIN32) |
287 /* | 294 /* |
288 * Winsock assignes a socket number divisible by 4 so | 295 * Winsock assignes a socket number divisible by 4 so |
289 * to find a connection we divide a socket number by 4. | 296 * to find a connection we divide a socket number by 4. |
290 */ | 297 */ |
291 | 298 |
292 fd /= 4; | 299 fd /= 4; |
293 #endif | 300 #endif |
294 if (fd >= (ngx_socket_t) cycle->connection_n) { | 301 if (fd >= (ngx_socket_t) cycle->connection_n) { |
295 ngx_log_error(NGX_LOG_EMERG, log, 0, | 302 ngx_log_error(NGX_LOG_EMERG, log, 0, |
296 "%d connections is not enough to hold " | 303 "%d connections is not enough to hold " |
297 "an open listening socket on %s, " | 304 "an open listening socket on %V, " |
298 "required at least %d connections", | 305 "required at least %d connections", |
299 cycle->connection_n, | 306 cycle->connection_n, |
300 ls[i].addr_text.data, fd); | 307 &ls[i].addr_text, fd); |
301 failed = 1; | 308 failed = 1; |
302 break; | 309 break; |
303 } | 310 } |
304 | 311 |
305 nls[n].fd = ls[i].fd; | 312 nls[n].fd = ls[i].fd; |
370 continue; | 377 continue; |
371 } | 378 } |
372 | 379 |
373 if (ngx_close_socket(ls[i].fd) == -1) { | 380 if (ngx_close_socket(ls[i].fd) == -1) { |
374 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, | 381 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, |
375 ngx_close_socket_n " %s failed", | 382 ngx_close_socket_n " %V failed", |
376 ls[i].addr_text.data); | 383 &ls[i].addr_text); |
377 } | 384 } |
378 } | 385 } |
379 | 386 |
380 ngx_destroy_pool(pool); | 387 ngx_destroy_pool(pool); |
381 return NULL; | 388 return NULL; |
382 } | 389 } |
383 | 390 |
384 | 391 |
385 /* commit the new cycle configuration */ | 392 /* commit the new cycle configuration */ |
386 | 393 |
387 #if !(WIN32) | 394 #if !(NGX_WIN32) |
388 | 395 |
389 if (!ngx_test_config && cycle->log->file->fd != STDERR_FILENO) { | 396 if (!ngx_test_config && cycle->log->file->fd != STDERR_FILENO) { |
390 | 397 |
391 ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0, | 398 ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0, |
392 "dup2: %0X %d \"%s\"", | 399 "dup2: %p %d \"%s\"", |
393 cycle->log->file, | 400 cycle->log->file, |
394 cycle->log->file->fd, cycle->log->file->name.data); | 401 cycle->log->file->fd, cycle->log->file->name.data); |
395 | 402 |
396 if (dup2(cycle->log->file->fd, STDERR_FILENO) == NGX_ERROR) { | 403 if (dup2(cycle->log->file->fd, STDERR_FILENO) == NGX_ERROR) { |
397 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, | 404 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, |
424 continue; | 431 continue; |
425 } | 432 } |
426 | 433 |
427 if (ngx_close_socket(ls[i].fd) == -1) { | 434 if (ngx_close_socket(ls[i].fd) == -1) { |
428 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, | 435 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, |
429 ngx_close_socket_n " %s failed", | 436 ngx_close_socket_n " %V failed", |
430 ls[i].addr_text.data); | 437 &ls[i].addr_text); |
431 } | 438 } |
432 } | 439 } |
433 | 440 |
434 | 441 |
435 /* close the unneeded open files */ | 442 /* close the unneeded open files */ |
510 | 517 |
511 return cycle; | 518 return cycle; |
512 } | 519 } |
513 | 520 |
514 | 521 |
515 #if !(WIN32) | 522 static ngx_int_t ngx_cmp_sockaddr(struct sockaddr *s1, struct sockaddr *s2) |
523 { | |
524 struct sockaddr_in *sin1, *sin2; | |
525 | |
526 /* AF_INET only */ | |
527 | |
528 if (s1->sa_family != AF_INET || s2->sa_family != AF_INET) { | |
529 return NGX_DECLINED; | |
530 } | |
531 | |
532 sin1 = (struct sockaddr_in *) s1; | |
533 sin2 = (struct sockaddr_in *) s2; | |
534 | |
535 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr) { | |
536 return NGX_DECLINED; | |
537 } | |
538 | |
539 if (sin1->sin_port != sin2->sin_port) { | |
540 return NGX_DECLINED; | |
541 } | |
542 | |
543 return NGX_OK; | |
544 } | |
545 | |
546 | |
547 #if !(NGX_WIN32) | |
516 | 548 |
517 ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle) | 549 ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle) |
518 { | 550 { |
519 ngx_uint_t trunc; | 551 ngx_uint_t trunc; |
520 size_t len; | 552 size_t len; |
521 u_char *name, pid[NGX_INT64_LEN + 1]; | 553 u_char *name, pid[NGX_INT64_LEN]; |
522 ngx_file_t file; | 554 ngx_file_t file; |
523 ngx_core_conf_t *ccf, *old_ccf; | 555 ngx_core_conf_t *ccf, *old_ccf; |
524 | 556 |
525 if (!ngx_test_config && old_cycle && old_cycle->conf_ctx == NULL) { | 557 if (!ngx_test_config && old_cycle && old_cycle->conf_ctx == NULL) { |
526 | 558 |
546 | 578 |
547 return NGX_OK; | 579 return NGX_OK; |
548 } | 580 } |
549 } | 581 } |
550 | 582 |
551 len = ngx_snprintf((char *) pid, NGX_INT64_LEN + 1, PID_T_FMT, ngx_pid); | |
552 | |
553 ngx_memzero(&file, sizeof(ngx_file_t)); | 583 ngx_memzero(&file, sizeof(ngx_file_t)); |
554 file.name = (ngx_inherited && getppid() > 1) ? ccf->newpid : ccf->pid; | 584 file.name = (ngx_inherited && getppid() > 1) ? ccf->newpid : ccf->pid; |
555 file.log = cycle->log; | 585 file.log = cycle->log; |
556 | 586 |
557 trunc = ngx_test_config ? 0: NGX_FILE_TRUNCATE; | 587 trunc = ngx_test_config ? 0: NGX_FILE_TRUNCATE; |
564 ngx_open_file_n " \"%s\" failed", file.name.data); | 594 ngx_open_file_n " \"%s\" failed", file.name.data); |
565 return NGX_ERROR; | 595 return NGX_ERROR; |
566 } | 596 } |
567 | 597 |
568 if (!ngx_test_config) { | 598 if (!ngx_test_config) { |
599 len = ngx_sprintf(pid, "%P", ngx_pid) - pid; | |
600 | |
569 if (ngx_write_file(&file, pid, len, 0) == NGX_ERROR) { | 601 if (ngx_write_file(&file, pid, len, 0) == NGX_ERROR) { |
570 return NGX_ERROR; | 602 return NGX_ERROR; |
571 } | 603 } |
572 } | 604 } |
573 | 605 |
613 { | 645 { |
614 ngx_fd_t fd; | 646 ngx_fd_t fd; |
615 ngx_uint_t i; | 647 ngx_uint_t i; |
616 ngx_list_part_t *part; | 648 ngx_list_part_t *part; |
617 ngx_open_file_t *file; | 649 ngx_open_file_t *file; |
618 #if !(WIN32) | 650 #if !(NGX_WIN32) |
619 ngx_file_info_t fi; | 651 ngx_file_info_t fi; |
620 #endif | 652 #endif |
621 | 653 |
622 part = &cycle->open_files.part; | 654 part = &cycle->open_files.part; |
623 file = part->elts; | 655 file = part->elts; |
647 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | 679 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
648 ngx_open_file_n " \"%s\" failed", file[i].name.data); | 680 ngx_open_file_n " \"%s\" failed", file[i].name.data); |
649 continue; | 681 continue; |
650 } | 682 } |
651 | 683 |
652 #if (WIN32) | 684 #if (NGX_WIN32) |
653 if (ngx_file_append_mode(fd) == NGX_ERROR) { | 685 if (ngx_file_append_mode(fd) == NGX_ERROR) { |
654 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | 686 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
655 ngx_file_append_mode_n " \"%s\" failed", | 687 ngx_file_append_mode_n " \"%s\" failed", |
656 file[i].name.data); | 688 file[i].name.data); |
657 | 689 |
728 } | 760 } |
729 | 761 |
730 file[i].fd = fd; | 762 file[i].fd = fd; |
731 } | 763 } |
732 | 764 |
733 #if !(WIN32) | 765 #if !(NGX_WIN32) |
734 | 766 |
735 if (cycle->log->file->fd != STDERR_FILENO) { | 767 if (cycle->log->file->fd != STDERR_FILENO) { |
736 if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) { | 768 if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) { |
737 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | 769 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
738 "dup2(STDERR) failed"); | 770 "dup2(STDERR) failed"); |