comparison src/os/unix/ngx_process_cycle.c @ 92:45945fa8b8ba NGINX_0_2_0

nginx 0.2.0 *) The pid-file names used during online upgrade was changed and now is not required a manual rename operation. The old master process adds the ".oldbin" suffix to its pid-file and executes a new binary file. The new master process creates usual pid-file without the ".newbin" suffix. If the master process exits, then old master process renames back its pid-file with the ".oldbin" suffix to the pid-file without suffix. *) Change: the "worker_connections" directive, new name of the "connections" directive; now the directive specifies maximum number of connections, but not maximum socket descriptor number. *) Feature: SSL supports the session cache inside one worker process. *) Feature: the "satisfy_any" directive. *) Change: the ngx_http_access_module and ngx_http_auth_basic_module do not run for subrequests. *) Feature: the "worker_rlimit_nofile" and "worker_rlimit_sigpending" directives. *) Bugfix: if all backend using in load-balancing failed after one error, then nginx did not try do connect to them during 60 seconds. *) Bugfix: in IMAP/POP3 command argument parsing. Thanks to Rob Mueller. *) Bugfix: errors while using SSL in IMAP/POP3 proxy. *) Bugfix: errors while using SSI and gzipping. *) Bugfix: the "Expires" and "Cache-Control" header lines were omitted from the 304 responses. Thanks to Alexandr Kukushkin.
author Igor Sysoev <http://sysoev.ru>
date Fri, 23 Sep 2005 00:00:00 +0400
parents 991c6e4c7654
children 45f7329b4bd0
comparison
equal deleted inserted replaced
91:c3eee83ea942 92:45945fa8b8ba
511 511
512 512
513 static ngx_uint_t 513 static ngx_uint_t
514 ngx_reap_childs(ngx_cycle_t *cycle) 514 ngx_reap_childs(ngx_cycle_t *cycle)
515 { 515 {
516 ngx_int_t i, n; 516 ngx_int_t i, n;
517 ngx_uint_t live; 517 ngx_uint_t live;
518 ngx_channel_t ch; 518 ngx_channel_t ch;
519 ngx_core_conf_t *ccf;
519 520
520 ch.command = NGX_CMD_CLOSE_CHANNEL; 521 ch.command = NGX_CMD_CLOSE_CHANNEL;
521 ch.fd = -1; 522 ch.fd = -1;
522 523
523 live = 0; 524 live = 0;
573 && !ngx_quit) 574 && !ngx_quit)
574 { 575 {
575 if (ngx_spawn_process(cycle, ngx_processes[i].proc, 576 if (ngx_spawn_process(cycle, ngx_processes[i].proc,
576 ngx_processes[i].data, 577 ngx_processes[i].data,
577 ngx_processes[i].name, i) 578 ngx_processes[i].name, i)
578 == NGX_ERROR) 579 == NGX_INVALID_PID)
579 { 580 {
580 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, 581 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
581 "can not respawn %s", ngx_processes[i].name); 582 "can not respawn %s", ngx_processes[i].name);
582 continue; 583 continue;
583 } 584 }
613 614
614 continue; 615 continue;
615 } 616 }
616 617
617 if (ngx_processes[i].pid == ngx_new_binary) { 618 if (ngx_processes[i].pid == ngx_new_binary) {
619
620 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx,
621 ngx_core_module);
622
623 if (ngx_rename_file((char *) ccf->oldpid.data,
624 (char *) ccf->pid.data)
625 != NGX_OK)
626 {
627 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
628 ngx_rename_file_n " %s back to %s failed "
629 "after the new binary process \"%s\" exited",
630 ccf->oldpid.data, ccf->pid.data, ngx_argv[0]);
631 }
632
618 ngx_new_binary = 0; 633 ngx_new_binary = 0;
619 if (ngx_noaccepting) { 634 if (ngx_noaccepting) {
620 ngx_restart = 1; 635 ngx_restart = 1;
621 ngx_noaccepting = 0; 636 ngx_noaccepting = 0;
622 } 637 }
793 ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority) 808 ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority)
794 { 809 {
795 sigset_t set; 810 sigset_t set;
796 ngx_int_t n; 811 ngx_int_t n;
797 ngx_uint_t i; 812 ngx_uint_t i;
813 struct rlimit rlmt;
798 struct timeval tv; 814 struct timeval tv;
799 ngx_core_conf_t *ccf; 815 ngx_core_conf_t *ccf;
800 ngx_listening_t *ls; 816 ngx_listening_t *ls;
801 817
802 ngx_gettimeofday(&tv); 818 ngx_gettimeofday(&tv);
815 if (setpriority(PRIO_PROCESS, 0, ccf->priority) == -1) { 831 if (setpriority(PRIO_PROCESS, 0, ccf->priority) == -1) {
816 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, 832 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
817 "setpriority(%d) failed", ccf->priority); 833 "setpriority(%d) failed", ccf->priority);
818 } 834 }
819 } 835 }
836
837 if (ccf->rlimit_nofile != NGX_CONF_UNSET) {
838 rlmt.rlim_cur = (rlim_t) ccf->rlimit_nofile;
839 rlmt.rlim_max = (rlim_t) ccf->rlimit_nofile;
840
841 if (setrlimit(RLIMIT_NOFILE, &rlmt) == -1) {
842 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
843 "setrlimit(RLIMIT_NOFILE, %i) failed",
844 ccf->rlimit_nofile);
845 }
846 }
847
848 #ifdef RLIMIT_SIGPENDING
849 if (ccf->rlimit_sigpending != NGX_CONF_UNSET) {
850 rlmt.rlim_cur = (rlim_t) ccf->rlimit_sigpending;
851 rlmt.rlim_max = (rlim_t) ccf->rlimit_sigpending;
852
853 if (setrlimit(RLIMIT_SIGPENDING, &rlmt) == -1) {
854 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
855 "setrlimit(RLIMIT_SIGPENDING, %i) failed",
856 ccf->rlimit_sigpending);
857 }
858 }
859 #endif
820 860
821 if (setgid(ccf->group) == -1) { 861 if (setgid(ccf->group) == -1) {
822 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, 862 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
823 "setgid(%d) failed", ccf->group); 863 "setgid(%d) failed", ccf->group);
824 /* fatal */ 864 /* fatal */
872 * disable deleting previous events for the listening sockets because 912 * disable deleting previous events for the listening sockets because
873 * in the worker processes there are no events at all at this point 913 * in the worker processes there are no events at all at this point
874 */ 914 */
875 ls = cycle->listening.elts; 915 ls = cycle->listening.elts;
876 for (i = 0; i < cycle->listening.nelts; i++) { 916 for (i = 0; i < cycle->listening.nelts; i++) {
877 ls[i].remain = 0; 917 ls[i].previous = NULL;
878 } 918 }
879 919
880 for (i = 0; ngx_modules[i]; i++) { 920 for (i = 0; ngx_modules[i]; i++) {
881 if (ngx_modules[i]->init_process) { 921 if (ngx_modules[i]->init_process) {
882 if (ngx_modules[i]->init_process(cycle) == NGX_ERROR) { 922 if (ngx_modules[i]->init_process(cycle) == NGX_ERROR) {
926 966
927 static void 967 static void
928 ngx_channel_handler(ngx_event_t *ev) 968 ngx_channel_handler(ngx_event_t *ev)
929 { 969 {
930 ngx_int_t n; 970 ngx_int_t n;
971 ngx_socket_t fd;
931 ngx_channel_t ch; 972 ngx_channel_t ch;
932 ngx_connection_t *c; 973 ngx_connection_t *c;
933 974
934 if (ev->timedout) { 975 if (ev->timedout) {
935 ev->timedout = 0; 976 ev->timedout = 0;
943 n = ngx_read_channel(c->fd, &ch, sizeof(ngx_channel_t), ev->log); 984 n = ngx_read_channel(c->fd, &ch, sizeof(ngx_channel_t), ev->log);
944 985
945 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, "channel: %i", n); 986 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, "channel: %i", n);
946 987
947 if (n == NGX_ERROR) { 988 if (n == NGX_ERROR) {
948 if (close(c->fd) == -1) { 989
990 ngx_free_connection(c);
991
992 fd = c->fd;
993 c->fd = (ngx_socket_t) -1;
994
995 if (close(fd) == -1) {
949 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno, 996 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
950 "close() channel failed"); 997 "close() channel failed");
951 } 998 }
952 999
953 c->fd = -1;
954 return; 1000 return;
955 } 1001 }
956 1002
957 if (n == NGX_AGAIN) { 1003 if (n == NGX_AGAIN) {
958 return; 1004 return;
1142 ngx_path_t **path; 1188 ngx_path_t **path;
1143 ngx_event_t *ev; 1189 ngx_event_t *ev;
1144 1190
1145 ngx_worker_process_init(cycle, 0); 1191 ngx_worker_process_init(cycle, 0);
1146 1192
1147 ev = &cycle->read_events[ngx_channel]; 1193 ev = &cycle->read_events0[ngx_channel];
1148 1194
1149 ngx_accept_mutex = NULL; 1195 ngx_accept_mutex = NULL;
1150 1196
1151 ngx_setproctitle("garbage collector"); 1197 ngx_setproctitle("garbage collector");
1152 1198