Mercurial > hg > nginx
comparison src/core/nginx.c @ 113:d7f606e25b99
nginx-0.0.1-2003-07-04-19:10:33 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 04 Jul 2003 15:10:33 +0000 |
parents | 1c002f2b77ed |
children | ac69ab96328d |
comparison
equal
deleted
inserted
replaced
112:da763a85be66 | 113:d7f606e25b99 |
---|---|
13 | 13 |
14 | 14 |
15 ngx_os_io_t ngx_io; | 15 ngx_os_io_t ngx_io; |
16 | 16 |
17 | 17 |
18 ngx_cycle_t *cycle; | 18 ngx_cycle_t ngx_cycle; |
19 | 19 |
20 int ngx_max_module; | 20 int ngx_max_module; |
21 | 21 |
22 int ngx_connection_counter; | 22 int ngx_connection_counter; |
23 | 23 |
28 | 28 |
29 int main(int argc, char *const *argv) | 29 int main(int argc, char *const *argv) |
30 { | 30 { |
31 int i; | 31 int i; |
32 ngx_log_t *log; | 32 ngx_log_t *log; |
33 ngx_cycle_t *new_cycle; | 33 ngx_cycle_t *cycle; |
34 | 34 |
35 /* TODO */ ngx_max_sockets = -1; | 35 /* TODO */ ngx_max_sockets = -1; |
36 | 36 |
37 log = ngx_log_init_errlog(); | 37 log = ngx_log_init_errlog(); |
38 | 38 |
48 cycle = ngx_init_cycle(NULL, log); | 48 cycle = ngx_init_cycle(NULL, log); |
49 if (cycle == NULL) { | 49 if (cycle == NULL) { |
50 return 1; | 50 return 1; |
51 } | 51 } |
52 | 52 |
53 ngx_cycle = *cycle; | |
54 | |
53 /* daemon */ | 55 /* daemon */ |
54 | 56 |
55 /* life cycle */ | 57 /* life cycle */ |
56 | 58 |
57 for ( ;; ) { | 59 for ( ;; ) { |
58 /* STUB */ cycle->log->file->fd = log->file->fd; | 60 /* STUB */ ngx_cycle.log->log_level = NGX_LOG_DEBUG; |
59 /* STUB */ cycle->log->log_level = NGX_LOG_DEBUG; | |
60 | |
61 /* STUB */ | |
62 ngx_io = ngx_os_io; | |
63 | 61 |
64 /* forks */ | 62 /* forks */ |
65 | 63 |
66 ngx_init_temp_number(); | 64 ngx_init_temp_number(); |
67 | 65 |
68 /* STUB */ | 66 for (i = 0; ngx_modules[i]; i++) { |
69 ngx_pre_thread(&cycle->listening, cycle->pool, cycle->log); | 67 if (ngx_modules[i]->init_child) { |
68 if (ngx_modules[i]->init_child(&ngx_cycle) == NGX_ERROR) { | |
69 /* fatal */ | |
70 exit(1); | |
71 } | |
72 } | |
73 } | |
70 | 74 |
71 /* threads */ | 75 /* threads */ |
72 | 76 |
73 restart = 0; | 77 restart = 0; |
74 rotate = 0; | 78 rotate = 0; |
75 | 79 |
76 for ( ;; ) { | 80 for ( ;; ) { |
77 | 81 |
78 for ( ;; ) { | 82 for ( ;; ) { |
79 ngx_log_debug(cycle->log, "worker cycle"); | 83 ngx_log_debug(ngx_cycle.log, "worker cycle"); |
80 | 84 |
81 ngx_process_events(cycle->log); | 85 ngx_process_events(ngx_cycle.log); |
82 | 86 |
83 if (rotate) { | 87 if (rotate) { |
84 ngx_log_debug(cycle->log, "rotate"); | 88 ngx_log_debug(ngx_cycle.log, "rotate"); |
85 } | 89 } |
86 | 90 |
87 if (restart) { | 91 if (restart) { |
88 ngx_log_debug(cycle->log, "restart"); | 92 ngx_log_debug(ngx_cycle.log, "restart"); |
89 break; | 93 break; |
90 } | 94 } |
91 | 95 |
92 } | 96 } |
93 | 97 |
94 new_cycle = ngx_init_cycle(cycle, cycle->log); | 98 cycle = ngx_init_cycle(&ngx_cycle, ngx_cycle.log); |
95 if (new_cycle == NULL) { | 99 if (cycle == NULL) { |
96 continue; | 100 continue; |
97 } | 101 } |
98 | 102 |
99 cycle = new_cycle; | 103 ngx_log_debug(ngx_cycle.log, "OPEN: %d" _ cycle->log->file->fd); |
104 ngx_cycle = *cycle; | |
105 ngx_log_debug(ngx_cycle.log, "OPEN: %d" _ ngx_cycle.log->file->fd); | |
100 break; | 106 break; |
101 } | 107 } |
102 } | 108 } |
103 | 109 |
104 return 0; | 110 return 0; |
185 return NULL; | 191 return NULL; |
186 } | 192 } |
187 | 193 |
188 failed = 0; | 194 failed = 0; |
189 | 195 |
190 for (i = 0; ngx_modules[i]; i++) { | 196 ngx_log_debug(log, "OPEN: %d" _ cycle->log->file->fd); |
191 if (ngx_modules[i]->init_module) { | 197 |
192 if (ngx_modules[i]->init_module(cycle, log) == NGX_ERROR) | 198 file = cycle->open_files.elts; |
193 { | 199 for (i = 0; i < cycle->open_files.nelts; i++) { |
194 failed = 1; | 200 if (file->name.data == NULL) { |
195 break; | 201 continue; |
196 } | 202 } |
197 } | 203 |
198 } | 204 file->fd = ngx_open_file(file->name.data, |
199 | 205 NGX_FILE_RDWR, |
200 if (!failed) { | 206 NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND); |
201 file = cycle->open_files.elts; | 207 |
202 for (i = 0; i < cycle->open_files.nelts; i++) { | 208 if (file->fd == NGX_INVALID_FILE) { |
203 if (file->name.data == NULL) { | 209 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, |
204 continue; | 210 ngx_open_file_n " \"%s\" failed", |
205 } | 211 file->name.data); |
206 | 212 failed = 1; |
207 file->fd = ngx_open_file(file->name.data, | 213 break; |
208 NGX_FILE_RDWR, | 214 } |
209 NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND); | 215 |
210 | 216 /* TODO: Win32 append */ |
211 if (file->fd == NGX_INVALID_FILE) { | 217 } |
212 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, | 218 |
213 ngx_open_file_n " \"%s\" failed", | 219 ngx_log_debug(log, "OPEN: %d" _ cycle->log->file->fd); |
214 file->name.data); | 220 /* STUB */ cycle->log->log_level = NGX_LOG_DEBUG; |
215 failed = 1; | 221 ngx_log_debug(cycle->log, "TEST"); |
216 break; | |
217 } | |
218 | |
219 /* TODO: Win32 append */ | |
220 } | |
221 } | |
222 | 222 |
223 if (!failed) { | 223 if (!failed) { |
224 if (old_cycle) { | 224 if (old_cycle) { |
225 ls = old_cycle->listening.elts; | 225 ls = old_cycle->listening.elts; |
226 for (i = 0; i < old_cycle->listening.nelts; i++) { | 226 for (i = 0; i < old_cycle->listening.nelts; i++) { |
252 | 252 |
253 if (failed) { | 253 if (failed) { |
254 | 254 |
255 /* rollback the new cycle configuration */ | 255 /* rollback the new cycle configuration */ |
256 | 256 |
257 for (i = 0; ngx_modules[i]; i++) { | |
258 if (ngx_modules[i]->rollback_module) { | |
259 ngx_modules[i]->rollback_module(cycle, log); | |
260 } | |
261 } | |
262 | |
263 file = cycle->open_files.elts; | 257 file = cycle->open_files.elts; |
264 for (i = 0; i < cycle->open_files.nelts; i++) { | 258 for (i = 0; i < cycle->open_files.nelts; i++) { |
265 if (file->fd == NGX_INVALID_FILE) { | 259 if (file->fd == NGX_INVALID_FILE) { |
266 continue; | 260 continue; |
267 } | 261 } |
290 return NULL; | 284 return NULL; |
291 } | 285 } |
292 | 286 |
293 /* commit the new cycle configuration */ | 287 /* commit the new cycle configuration */ |
294 | 288 |
289 pool->log = cycle->log; | |
290 | |
295 for (i = 0; ngx_modules[i]; i++) { | 291 for (i = 0; ngx_modules[i]; i++) { |
296 if (ngx_modules[i]->commit_module) { | 292 if (ngx_modules[i]->init_module) { |
297 ngx_modules[i]->commit_module(cycle, log); | 293 if (ngx_modules[i]->init_module(cycle) == NGX_ERROR) { |
298 } | 294 /* fatal */ |
299 } | 295 exit(1); |
300 | 296 } |
301 pool->log = cycle->log; | 297 } |
298 } | |
302 | 299 |
303 if (old_cycle == NULL) { | 300 if (old_cycle == NULL) { |
304 return cycle; | 301 return cycle; |
305 } | 302 } |
306 | 303 |