Mercurial > hg > nginx-quic
comparison src/core/nginx.c @ 117:f6e3c5d019b6
nginx-0.0.1-2003-07-11-19:17:50 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 11 Jul 2003 15:17:50 +0000 |
parents | be27f922b9a2 |
children | 5bf52498665c |
comparison
equal
deleted
inserted
replaced
116:571bcbff82c5 | 117:f6e3c5d019b6 |
---|---|
7 | 7 |
8 static ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log); | 8 static ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log); |
9 static int ngx_open_listening_sockets(ngx_cycle_t *cycle, ngx_log_t *log); | 9 static int ngx_open_listening_sockets(ngx_cycle_t *cycle, ngx_log_t *log); |
10 static void ngx_clean_old_cycles(ngx_event_t *ev); | 10 static void ngx_clean_old_cycles(ngx_event_t *ev); |
11 | 11 |
12 | |
12 #if (NGX_DEBUG) && (__FreeBSD__) | 13 #if (NGX_DEBUG) && (__FreeBSD__) |
13 extern char *malloc_options; | 14 extern char *malloc_options; |
14 #endif | 15 #endif |
16 | |
17 | |
18 typedef struct { | |
19 int daemon; | |
20 } ngx_core_conf_t; | |
21 | |
22 | |
23 static ngx_str_t core_name = ngx_string("core"); | |
24 | |
25 static ngx_command_t ngx_core_commands[] = { | |
26 | |
27 {ngx_string("daemon"), | |
28 NGX_MAIN_CONF|NGX_CONF_TAKE1, | |
29 ngx_conf_set_core_flag_slot, | |
30 0, | |
31 offsetof(ngx_core_conf_t, daemon), | |
32 NULL}, | |
33 | |
34 ngx_null_command | |
35 }; | |
36 | |
37 | |
38 ngx_module_t ngx_core_module = { | |
39 NGX_MODULE, | |
40 &core_name, /* module context */ | |
41 ngx_core_commands, /* module directives */ | |
42 NGX_CORE_MODULE, /* module type */ | |
43 NULL, /* init module */ | |
44 NULL /* init child */ | |
45 }; | |
46 | |
15 | 47 |
16 int ngx_max_module; | 48 int ngx_max_module; |
17 ngx_os_io_t ngx_io; | 49 ngx_os_io_t ngx_io; |
18 | 50 |
19 ngx_cycle_t *ngx_cycle; | 51 ngx_cycle_t *ngx_cycle; |
31 int rotate; | 63 int rotate; |
32 | 64 |
33 | 65 |
34 int main(int argc, char *const *argv) | 66 int main(int argc, char *const *argv) |
35 { | 67 { |
36 int i; | 68 int i; |
37 ngx_log_t *log; | 69 ngx_log_t *log; |
38 ngx_cycle_t *cycle; | 70 ngx_cycle_t *cycle; |
71 ngx_core_conf_t *ccf; | |
39 | 72 |
40 #if (NGX_DEBUG) && (__FreeBSD__) | 73 #if (NGX_DEBUG) && (__FreeBSD__) |
41 malloc_options = "J"; | 74 malloc_options = "J"; |
42 #endif | 75 #endif |
43 | 76 |
61 | 94 |
62 ngx_cycle = cycle; | 95 ngx_cycle = cycle; |
63 | 96 |
64 #if !(WIN32) | 97 #if !(WIN32) |
65 | 98 |
66 if (0) { | 99 ccf = (ngx_core_conf_t *) ngx_get_conf(ngx_cycle->conf_ctx, |
67 if (ngx_daemon(cycle->log) == NGX_ERROR) { | 100 ngx_core_module); |
101 | |
102 if (ccf->daemon != 0) { | |
103 if (ngx_daemon(ngx_cycle->log) == NGX_ERROR) { | |
68 return 1; | 104 return 1; |
69 } | 105 } |
70 } | 106 } |
71 | 107 |
72 if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) { | 108 if (dup2(ngx_cycle->log->file->fd, STDERR_FILENO) == -1) { |
73 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "dup2(STDERR) failed"); | 109 ngx_log_error(NGX_LOG_EMERG, ngx_cycle->log, ngx_errno, |
110 "dup2(STDERR) failed"); | |
74 return 1; | 111 return 1; |
75 } | 112 } |
76 | 113 |
77 #endif | 114 #endif |
78 | 115 |
136 int i, n, failed; | 173 int i, n, failed; |
137 ngx_str_t conf_file; | 174 ngx_str_t conf_file; |
138 ngx_conf_t conf; | 175 ngx_conf_t conf; |
139 ngx_pool_t *pool; | 176 ngx_pool_t *pool; |
140 ngx_cycle_t *cycle, **old; | 177 ngx_cycle_t *cycle, **old; |
178 ngx_core_conf_t *ccf; | |
141 ngx_open_file_t *file; | 179 ngx_open_file_t *file; |
142 ngx_listening_t *ls, *nls; | 180 ngx_listening_t *ls, *nls; |
143 | 181 |
144 | 182 |
145 pool = ngx_create_pool(16 * 1024, log); | 183 pool = ngx_create_pool(16 * 1024, log); |
153 return NULL; | 191 return NULL; |
154 } | 192 } |
155 cycle->pool = pool; | 193 cycle->pool = pool; |
156 | 194 |
157 cycle->old_cycle = old_cycle; | 195 cycle->old_cycle = old_cycle; |
196 | |
158 | 197 |
159 n = old_cycle ? old_cycle->open_files.nelts : 20; | 198 n = old_cycle ? old_cycle->open_files.nelts : 20; |
160 cycle->open_files.elts = ngx_pcalloc(pool, n * sizeof(ngx_open_file_t)); | 199 cycle->open_files.elts = ngx_pcalloc(pool, n * sizeof(ngx_open_file_t)); |
161 if (cycle->open_files.elts == NULL) { | 200 if (cycle->open_files.elts == NULL) { |
162 ngx_destroy_pool(pool); | 201 ngx_destroy_pool(pool); |
165 cycle->open_files.nelts = 0; | 204 cycle->open_files.nelts = 0; |
166 cycle->open_files.size = sizeof(ngx_open_file_t); | 205 cycle->open_files.size = sizeof(ngx_open_file_t); |
167 cycle->open_files.nalloc = n; | 206 cycle->open_files.nalloc = n; |
168 cycle->open_files.pool = pool; | 207 cycle->open_files.pool = pool; |
169 | 208 |
209 | |
170 cycle->log = ngx_log_create_errlog(cycle, NULL); | 210 cycle->log = ngx_log_create_errlog(cycle, NULL); |
171 if (cycle->log == NULL) { | 211 if (cycle->log == NULL) { |
172 ngx_destroy_pool(pool); | 212 ngx_destroy_pool(pool); |
173 return NULL; | 213 return NULL; |
174 } | 214 } |
215 | |
175 | 216 |
176 n = old_cycle ? old_cycle->listening.nelts : 10; | 217 n = old_cycle ? old_cycle->listening.nelts : 10; |
177 cycle->listening.elts = ngx_pcalloc(pool, n * sizeof(ngx_listening_t)); | 218 cycle->listening.elts = ngx_pcalloc(pool, n * sizeof(ngx_listening_t)); |
178 if (cycle->listening.elts == NULL) { | 219 if (cycle->listening.elts == NULL) { |
179 ngx_destroy_pool(pool); | 220 ngx_destroy_pool(pool); |
182 cycle->listening.nelts = 0; | 223 cycle->listening.nelts = 0; |
183 cycle->listening.size = sizeof(ngx_listening_t); | 224 cycle->listening.size = sizeof(ngx_listening_t); |
184 cycle->listening.nalloc = n; | 225 cycle->listening.nalloc = n; |
185 cycle->listening.pool = pool; | 226 cycle->listening.pool = pool; |
186 | 227 |
228 | |
187 cycle->conf_ctx = ngx_pcalloc(pool, ngx_max_module * sizeof(void *)); | 229 cycle->conf_ctx = ngx_pcalloc(pool, ngx_max_module * sizeof(void *)); |
188 if (cycle->conf_ctx == NULL) { | 230 if (cycle->conf_ctx == NULL) { |
189 ngx_destroy_pool(pool); | 231 ngx_destroy_pool(pool); |
190 return NULL; | 232 return NULL; |
191 } | 233 } |
234 | |
235 | |
236 ccf = ngx_pcalloc(pool, sizeof(ngx_core_conf_t)); | |
237 if (ccf == NULL) { | |
238 ngx_destroy_pool(pool); | |
239 return NULL; | |
240 } | |
241 ccf->daemon = -1; | |
242 ((void **)(cycle->conf_ctx))[ngx_core_module.index] = ccf; | |
243 | |
192 | 244 |
193 ngx_memzero(&conf, sizeof(ngx_conf_t)); | 245 ngx_memzero(&conf, sizeof(ngx_conf_t)); |
194 /* STUB: init array ? */ | 246 /* STUB: init array ? */ |
195 conf.args = ngx_create_array(pool, 10, sizeof(ngx_str_t)); | 247 conf.args = ngx_create_array(pool, 10, sizeof(ngx_str_t)); |
196 if (conf.args == NULL) { | 248 if (conf.args == NULL) { |
210 | 262 |
211 if (ngx_conf_parse(&conf, &conf_file) != NGX_CONF_OK) { | 263 if (ngx_conf_parse(&conf, &conf_file) != NGX_CONF_OK) { |
212 ngx_destroy_pool(pool); | 264 ngx_destroy_pool(pool); |
213 return NULL; | 265 return NULL; |
214 } | 266 } |
267 | |
215 | 268 |
216 failed = 0; | 269 failed = 0; |
217 | 270 |
218 file = cycle->open_files.elts; | 271 file = cycle->open_files.elts; |
219 for (i = 0; i < cycle->open_files.nelts; i++) { | 272 for (i = 0; i < cycle->open_files.nelts; i++) { |