Mercurial > hg > nginx
comparison src/core/nginx.c @ 191:71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 19 Nov 2003 16:26:41 +0000 |
parents | 02a715e85df1 |
children | 2357fa41738a |
comparison
equal
deleted
inserted
replaced
190:02a715e85df1 | 191:71ce40b3c37b |
---|---|
48 NULL, /* init module */ | 48 NULL, /* init module */ |
49 NULL /* init child */ | 49 NULL /* init child */ |
50 }; | 50 }; |
51 | 51 |
52 | 52 |
53 int ngx_max_module; | 53 int ngx_max_module; |
54 ngx_os_io_t ngx_io; | 54 ngx_os_io_t ngx_io; |
55 | 55 |
56 ngx_cycle_t *ngx_cycle; | 56 volatile ngx_cycle_t *ngx_cycle; |
57 ngx_pool_t *ngx_temp_pool; | 57 ngx_array_t ngx_old_cycles; |
58 ngx_array_t ngx_old_cycles; | 58 |
59 ngx_event_t ngx_cleaner_event; | 59 static ngx_pool_t *ngx_temp_pool; |
60 static ngx_event_t ngx_cleaner_event; | |
60 | 61 |
61 /* STUB NAME */ | 62 /* STUB NAME */ |
62 ngx_connection_t dumb; | 63 static ngx_connection_t dumb; |
63 | 64 |
64 int ngx_connection_counter; | 65 u_int ngx_connection_counter; |
65 | 66 |
66 | 67 |
67 int restart; | 68 int restart; |
68 int rotate; | 69 int rotate; |
69 | 70 |
110 | 111 |
111 ngx_cycle = cycle; | 112 ngx_cycle = cycle; |
112 | 113 |
113 #if !(WIN32) | 114 #if !(WIN32) |
114 | 115 |
115 ccf = (ngx_core_conf_t *) ngx_get_conf(ngx_cycle->conf_ctx, | 116 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); |
116 ngx_core_module); | |
117 | 117 |
118 if (ccf->daemon != 0) { | 118 if (ccf->daemon != 0) { |
119 if (ngx_daemon(ngx_cycle->log) == NGX_ERROR) { | 119 if (ngx_daemon(cycle->log) == NGX_ERROR) { |
120 return 1; | 120 return 1; |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 if (dup2(ngx_cycle->log->file->fd, STDERR_FILENO) == -1) { | 124 if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) { |
125 ngx_log_error(NGX_LOG_EMERG, ngx_cycle->log, ngx_errno, | 125 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
126 "dup2(STDERR) failed"); | 126 "dup2(STDERR) failed"); |
127 return 1; | 127 return 1; |
128 } | 128 } |
129 | 129 |
130 #endif | 130 #endif |
131 | 131 |
132 /* life cycle */ | 132 /* life cycle */ |
133 | 133 |
134 for ( ;; ) { | 134 for ( ;; ) { |
135 /* STUB */ ngx_cycle->log->log_level = NGX_LOG_DEBUG; | 135 /* STUB */ cycle->log->log_level = NGX_LOG_DEBUG; |
136 | 136 |
137 /* forks */ | 137 #if 0 |
138 | |
139 #if !(WIN32) | |
140 ngx_spawn_process(cycle->log); | |
141 #endif | |
142 | |
143 stub_init(cycle); | |
144 #endif | |
145 | |
146 /* TODO: forks */ | |
138 | 147 |
139 ngx_init_temp_number(); | 148 ngx_init_temp_number(); |
140 | 149 |
141 for (i = 0; ngx_modules[i]; i++) { | 150 for (i = 0; ngx_modules[i]; i++) { |
142 if (ngx_modules[i]->init_child) { | 151 if (ngx_modules[i]->init_child) { |
143 if (ngx_modules[i]->init_child(ngx_cycle) == NGX_ERROR) { | 152 if (ngx_modules[i]->init_child(cycle) == NGX_ERROR) { |
144 /* fatal */ | 153 /* fatal */ |
145 exit(1); | 154 exit(1); |
146 } | 155 } |
147 } | 156 } |
148 } | 157 } |
149 | 158 |
150 /* threads */ | 159 /* TODO: threads */ |
151 | 160 |
152 restart = 0; | 161 restart = 0; |
153 rotate = 0; | 162 rotate = 0; |
154 | 163 |
155 for ( ;; ) { | 164 for ( ;; ) { |
156 | 165 |
157 for ( ;; ) { | 166 for ( ;; ) { |
158 ngx_log_debug(ngx_cycle->log, "worker cycle"); | 167 ngx_log_debug(cycle->log, "worker cycle"); |
159 | 168 |
160 ngx_process_events(ngx_cycle->log); | 169 ngx_process_events(cycle->log); |
161 | 170 |
162 if (rotate) { | 171 if (rotate) { |
163 ngx_log_debug(ngx_cycle->log, "rotate"); | 172 ngx_log_debug(cycle->log, "rotate"); |
164 | 173 |
165 file = cycle->open_files.elts; | 174 file = cycle->open_files.elts; |
166 for (i = 0; i < cycle->open_files.nelts; i++) { | 175 for (i = 0; i < cycle->open_files.nelts; i++) { |
167 if (file[i].name.data == NULL) { | 176 if (file[i].name.data == NULL) { |
168 continue; | 177 continue; |
174 | 183 |
175 ngx_log_debug(log, "REOPEN: %d:%d:%s" _ fd _ file[i].fd _ file[i].name.data); | 184 ngx_log_debug(log, "REOPEN: %d:%d:%s" _ fd _ file[i].fd _ file[i].name.data); |
176 | 185 |
177 if (fd == NGX_INVALID_FILE) { | 186 if (fd == NGX_INVALID_FILE) { |
178 ngx_log_error(NGX_LOG_EMERG, | 187 ngx_log_error(NGX_LOG_EMERG, |
179 ngx_cycle->log, ngx_errno, | 188 cycle->log, ngx_errno, |
180 ngx_open_file_n " \"%s\" failed", | 189 ngx_open_file_n " \"%s\" failed", |
181 file[i].name.data); | 190 file[i].name.data); |
182 continue; | 191 continue; |
183 } | 192 } |
184 | 193 |
185 #if (WIN32) | 194 #if (WIN32) |
186 if (ngx_file_append_mode(fd) == NGX_ERROR) { | 195 if (ngx_file_append_mode(fd) == NGX_ERROR) { |
187 ngx_log_error(NGX_LOG_EMERG, | 196 ngx_log_error(NGX_LOG_EMERG, |
188 ngx_cycle->log, ngx_errno, | 197 cycle->log, ngx_errno, |
189 ngx_file_append_mode_n | 198 ngx_file_append_mode_n |
190 " \"%s\" failed", | 199 " \"%s\" failed", |
191 file[i].name.data); | 200 file[i].name.data); |
192 | 201 |
193 if (ngx_close_file(fd) == NGX_FILE_ERROR) { | 202 if (ngx_close_file(fd) == NGX_FILE_ERROR) { |
194 ngx_log_error(NGX_LOG_EMERG, | 203 ngx_log_error(NGX_LOG_EMERG, |
195 ngx_cycle->log, ngx_errno, | 204 cycle->log, ngx_errno, |
196 ngx_close_file_n " \"%s\" failed", | 205 ngx_close_file_n " \"%s\" failed", |
197 file[i].name.data); | 206 file[i].name.data); |
198 } | 207 } |
199 | 208 |
200 continue; | 209 continue; |
201 } | 210 } |
202 #endif | 211 #endif |
203 | 212 |
204 if (ngx_close_file(file[i].fd) == NGX_FILE_ERROR) { | 213 if (ngx_close_file(file[i].fd) == NGX_FILE_ERROR) { |
205 ngx_log_error(NGX_LOG_EMERG, | 214 ngx_log_error(NGX_LOG_EMERG, |
206 ngx_cycle->log, ngx_errno, | 215 cycle->log, ngx_errno, |
207 ngx_close_file_n " \"%s\" failed", | 216 ngx_close_file_n " \"%s\" failed", |
208 file[i].name.data); | 217 file[i].name.data); |
209 } | 218 } |
210 | 219 |
211 file[i].fd = fd; | 220 file[i].fd = fd; |
212 } | 221 } |
213 } | 222 } |
214 | 223 |
215 if (restart) { | 224 if (restart) { |
216 ngx_log_debug(ngx_cycle->log, "restart"); | 225 ngx_log_debug(cycle->log, "restart"); |
217 break; | 226 break; |
218 } | 227 } |
219 | 228 |
220 } | 229 } |
221 | 230 |
222 cycle = ngx_init_cycle(ngx_cycle, ngx_cycle->log); | 231 cycle = ngx_init_cycle(cycle, cycle->log); |
223 if (cycle == NULL) { | 232 if (cycle == NULL) { |
233 cycle = (ngx_cycle_t*) ngx_cycle; | |
224 continue; | 234 continue; |
225 } | 235 } |
226 | 236 |
227 ngx_cycle = cycle; | 237 ngx_cycle = cycle; |
228 break; | 238 break; |
462 exit(1); | 472 exit(1); |
463 } | 473 } |
464 } | 474 } |
465 } | 475 } |
466 | 476 |
467 stub_init(cycle); | |
468 | |
469 if (old_cycle == NULL) { | 477 if (old_cycle == NULL) { |
470 return cycle; | 478 return cycle; |
471 } | 479 } |
472 | 480 |
473 ls = old_cycle->listening.elts; | 481 ls = old_cycle->listening.elts; |
679 | 687 |
680 | 688 |
681 static void ngx_clean_old_cycles(ngx_event_t *ev) | 689 static void ngx_clean_old_cycles(ngx_event_t *ev) |
682 { | 690 { |
683 int i, n, found, live; | 691 int i, n, found, live; |
692 ngx_log_t *log; | |
684 ngx_cycle_t **cycle; | 693 ngx_cycle_t **cycle; |
685 | 694 |
686 ngx_temp_pool->log = ngx_cycle->log; | 695 log = ngx_cycle->log; |
687 | 696 ngx_temp_pool->log = log; |
688 ngx_log_debug(ngx_cycle->log, "clean old cycles"); | 697 |
698 ngx_log_debug(log, "clean old cycles"); | |
689 | 699 |
690 live = 0; | 700 live = 0; |
691 | 701 |
692 cycle = ngx_old_cycles.elts; | 702 cycle = ngx_old_cycles.elts; |
693 for (i = 0; i < ngx_old_cycles.nelts; i++) { | 703 for (i = 0; i < ngx_old_cycles.nelts; i++) { |
699 found = 0; | 709 found = 0; |
700 | 710 |
701 for (n = 0; n < cycle[i]->connection_n; n++) { | 711 for (n = 0; n < cycle[i]->connection_n; n++) { |
702 if (cycle[i]->connections[n].fd != -1) { | 712 if (cycle[i]->connections[n].fd != -1) { |
703 found = 1; | 713 found = 1; |
704 ngx_log_debug(ngx_cycle->log, "live fd: %d" _ n); | 714 ngx_log_debug(log, "live fd: %d" _ n); |
705 break; | 715 break; |
706 } | 716 } |
707 } | 717 } |
708 | 718 |
709 if (found) { | 719 if (found) { |
710 live = 1; | 720 live = 1; |
711 continue; | 721 continue; |
712 } | 722 } |
713 | 723 |
714 ngx_log_debug(ngx_cycle->log, "clean old cycle: %d" _ i); | 724 ngx_log_debug(log, "clean old cycle: %d" _ i); |
715 ngx_destroy_pool(cycle[i]->pool); | 725 ngx_destroy_pool(cycle[i]->pool); |
716 cycle[i] = NULL; | 726 cycle[i] = NULL; |
717 } | 727 } |
718 | 728 |
719 ngx_log_debug(ngx_cycle->log, "old cycles status: %d" _ live); | 729 ngx_log_debug(log, "old cycles status: %d" _ live); |
720 | 730 |
721 if (live) { | 731 if (live) { |
722 ngx_log_debug(ngx_cycle->log, "TIMER"); | 732 ngx_log_debug(log, "TIMER"); |
723 ngx_add_timer(ev, 30000); | 733 ngx_add_timer(ev, 30000); |
724 | 734 |
725 } else { | 735 } else { |
726 ngx_destroy_pool(ngx_temp_pool); | 736 ngx_destroy_pool(ngx_temp_pool); |
727 ngx_temp_pool = NULL; | 737 ngx_temp_pool = NULL; |