Mercurial > hg > nginx
comparison src/core/nginx.c @ 461:a88a3e4e158f release-0.1.5
nginx-0.1.5-RELEASE import
*) 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 <igor@sysoev.ru> |
---|---|
date | Thu, 11 Nov 2004 14:07:14 +0000 |
parents | 295d97d70c69 |
children | 2ff194b74f1e |
comparison
equal
deleted
inserted
replaced
460:5f8319142dfc | 461:a88a3e4e158f |
---|---|
16 static void *ngx_core_module_create_conf(ngx_cycle_t *cycle); | 16 static void *ngx_core_module_create_conf(ngx_cycle_t *cycle); |
17 static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf); | 17 static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf); |
18 static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 18 static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
19 | 19 |
20 | 20 |
21 static ngx_conf_enum_t ngx_debug_points[] = { | |
22 { ngx_string("stop"), NGX_DEBUG_POINTS_STOP }, | |
23 { ngx_string("abort"), NGX_DEBUG_POINTS_ABORT }, | |
24 { ngx_null_string, 0 } | |
25 }; | |
26 | |
27 | |
21 static ngx_command_t ngx_core_commands[] = { | 28 static ngx_command_t ngx_core_commands[] = { |
22 | 29 |
23 { ngx_string("daemon"), | 30 { ngx_string("daemon"), |
24 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1, | 31 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1, |
25 ngx_conf_set_flag_slot, | 32 ngx_conf_set_flag_slot, |
38 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1, | 45 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1, |
39 ngx_conf_set_num_slot, | 46 ngx_conf_set_num_slot, |
40 0, | 47 0, |
41 offsetof(ngx_core_conf_t, worker_processes), | 48 offsetof(ngx_core_conf_t, worker_processes), |
42 NULL }, | 49 NULL }, |
50 | |
51 { ngx_string("debug_points"), | |
52 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1, | |
53 ngx_conf_set_enum_slot, | |
54 0, | |
55 offsetof(ngx_core_conf_t, debug_points), | |
56 &ngx_debug_points }, | |
43 | 57 |
44 #if (NGX_THREADS) | 58 #if (NGX_THREADS) |
45 | 59 |
46 { ngx_string("worker_threads"), | 60 { ngx_string("worker_threads"), |
47 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1, | 61 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1, |
95 | 109 |
96 | 110 |
97 ngx_uint_t ngx_max_module; | 111 ngx_uint_t ngx_max_module; |
98 | 112 |
99 | 113 |
114 | |
100 int main(int argc, char *const *argv, char *const *envp) | 115 int main(int argc, char *const *argv, char *const *envp) |
101 { | 116 { |
102 ngx_int_t i; | 117 ngx_int_t i; |
103 ngx_log_t *log; | 118 ngx_log_t *log; |
104 ngx_cycle_t *cycle, init_cycle; | 119 ngx_cycle_t *cycle, init_cycle; |
116 ngx_regex_init(); | 131 ngx_regex_init(); |
117 #endif | 132 #endif |
118 | 133 |
119 ngx_pid = ngx_getpid(); | 134 ngx_pid = ngx_getpid(); |
120 | 135 |
121 if (!(log = ngx_log_init_stderr())) { | 136 if (!(log = ngx_log_init())) { |
122 return 1; | 137 return 1; |
123 } | 138 } |
124 | 139 |
125 #if (NGX_OPENSSL) | 140 #if (NGX_OPENSSL) |
126 ngx_ssl_init(log); | 141 ngx_ssl_init(log); |
163 | 178 |
164 cycle = ngx_init_cycle(&init_cycle); | 179 cycle = ngx_init_cycle(&init_cycle); |
165 if (cycle == NULL) { | 180 if (cycle == NULL) { |
166 if (ngx_test_config) { | 181 if (ngx_test_config) { |
167 ngx_log_error(NGX_LOG_EMERG, log, 0, | 182 ngx_log_error(NGX_LOG_EMERG, log, 0, |
168 "the configuration file %s test failed", | 183 "the configuration file \"%s\" test failed", |
169 init_cycle.conf_file.data); | 184 init_cycle.conf_file.data); |
170 } | 185 } |
171 | 186 |
172 return 1; | 187 return 1; |
173 } | 188 } |
174 | 189 |
175 if (ngx_test_config) { | 190 if (ngx_test_config) { |
176 ngx_log_error(NGX_LOG_INFO, log, 0, | 191 ngx_log_error(NGX_LOG_INFO, log, 0, |
177 "the configuration file %s was tested successfully", | 192 "the configuration file \"%s\" was tested successfully", |
178 cycle->conf_file.data); | 193 cycle->conf_file.data); |
179 return 0; | 194 return 0; |
180 } | 195 } |
181 | 196 |
182 ngx_os_status(cycle->log); | 197 ngx_os_status(cycle->log); |
185 | 200 |
186 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); | 201 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); |
187 | 202 |
188 ngx_process = ccf->master ? NGX_PROCESS_MASTER : NGX_PROCESS_SINGLE; | 203 ngx_process = ccf->master ? NGX_PROCESS_MASTER : NGX_PROCESS_SINGLE; |
189 | 204 |
190 #if (WIN32) | 205 #if (NGX_WIN32) |
191 | 206 |
192 #if 0 | 207 #if 0 |
193 | 208 |
194 TODO: | 209 TODO: |
195 | 210 |
239 | 254 |
240 if (inherited == NULL) { | 255 if (inherited == NULL) { |
241 return NGX_OK; | 256 return NGX_OK; |
242 } | 257 } |
243 | 258 |
244 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, | 259 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, |
245 "using inherited sockets from \"%s\"", inherited); | 260 "using inherited sockets from \"%s\"", inherited); |
246 | 261 |
247 ngx_init_array(cycle->listening, cycle->pool, | 262 if (ngx_array_init(&cycle->listening, cycle->pool, 10, |
248 10, sizeof(ngx_listening_t), NGX_ERROR); | 263 sizeof(ngx_listening_t)) == NGX_ERROR) |
264 { | |
265 return NGX_ERROR; | |
266 } | |
249 | 267 |
250 for (p = inherited, v = p; *p; p++) { | 268 for (p = inherited, v = p; *p; p++) { |
251 if (*p == ':' || *p == ';') { | 269 if (*p == ':' || *p == ';') { |
252 s = ngx_atoi(v, p - v); | 270 s = ngx_atoi(v, p - v); |
253 if (s == NGX_ERROR) { | 271 if (s == NGX_ERROR) { |
258 break; | 276 break; |
259 } | 277 } |
260 | 278 |
261 v = p + 1; | 279 v = p + 1; |
262 | 280 |
263 if (!(ls = ngx_push_array(&cycle->listening))) { | 281 if (!(ls = ngx_array_push(&cycle->listening))) { |
264 return NGX_ERROR; | 282 return NGX_ERROR; |
265 } | 283 } |
266 | 284 |
267 ls->fd = s; | 285 ls->fd = s; |
268 } | 286 } |
274 } | 292 } |
275 | 293 |
276 | 294 |
277 ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv) | 295 ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv) |
278 { | 296 { |
279 char *env[3], *var, *p; | 297 char *env[3], *var; |
298 u_char *p; | |
280 ngx_uint_t i; | 299 ngx_uint_t i; |
281 ngx_pid_t pid; | 300 ngx_pid_t pid; |
282 ngx_exec_ctx_t ctx; | 301 ngx_exec_ctx_t ctx; |
283 ngx_listening_t *ls; | 302 ngx_listening_t *ls; |
284 | 303 |
288 | 307 |
289 var = ngx_alloc(sizeof(NGINX_VAR) | 308 var = ngx_alloc(sizeof(NGINX_VAR) |
290 + cycle->listening.nelts * (NGX_INT32_LEN + 1) + 2, | 309 + cycle->listening.nelts * (NGX_INT32_LEN + 1) + 2, |
291 cycle->log); | 310 cycle->log); |
292 | 311 |
293 p = (char *) ngx_cpymem(var, NGINX_VAR "=", sizeof(NGINX_VAR)); | 312 p = ngx_cpymem(var, NGINX_VAR "=", sizeof(NGINX_VAR)); |
294 | 313 |
295 ls = cycle->listening.elts; | 314 ls = cycle->listening.elts; |
296 for (i = 0; i < cycle->listening.nelts; i++) { | 315 for (i = 0; i < cycle->listening.nelts; i++) { |
297 p += ngx_snprintf(p, NGX_INT32_LEN + 2, "%u;", ls[i].fd); | 316 p = ngx_sprintf(p, "%ud;", ls[i].fd); |
298 } | 317 } |
318 | |
319 *p = '\0'; | |
299 | 320 |
300 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, "inherited: %s", var); | 321 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, "inherited: %s", var); |
301 | 322 |
302 env[0] = var; | 323 env[0] = var; |
303 | 324 |
304 #if (NGX_SETPROCTITLE_USES_ENV) | 325 #if (NGX_SETPROCTITLE_USES_ENV) |
305 | 326 |
306 /* allocate spare 300 bytes for the new binary process title */ | 327 /* allocate the spare 300 bytes for the new binary process title */ |
307 | 328 |
308 env[1] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | 329 env[1] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" |
309 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | 330 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" |
310 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | 331 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" |
311 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | 332 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" |
428 * ccf->newpid = NULL; | 449 * ccf->newpid = NULL; |
429 */ | 450 */ |
430 ccf->daemon = NGX_CONF_UNSET; | 451 ccf->daemon = NGX_CONF_UNSET; |
431 ccf->master = NGX_CONF_UNSET; | 452 ccf->master = NGX_CONF_UNSET; |
432 ccf->worker_processes = NGX_CONF_UNSET; | 453 ccf->worker_processes = NGX_CONF_UNSET; |
454 ccf->debug_points = NGX_CONF_UNSET; | |
455 ccf->user = (ngx_uid_t) NGX_CONF_UNSET; | |
456 ccf->group = (ngx_gid_t) NGX_CONF_UNSET; | |
433 #if (NGX_THREADS) | 457 #if (NGX_THREADS) |
434 ccf->worker_threads = NGX_CONF_UNSET; | 458 ccf->worker_threads = NGX_CONF_UNSET; |
435 ccf->thread_stack_size = NGX_CONF_UNSET; | 459 ccf->thread_stack_size = NGX_CONF_UNSET_SIZE; |
436 #endif | 460 #endif |
437 ccf->user = (ngx_uid_t) NGX_CONF_UNSET; | |
438 ccf->group = (ngx_gid_t) NGX_CONF_UNSET; | |
439 | 461 |
440 return ccf; | 462 return ccf; |
441 } | 463 } |
442 | 464 |
443 | 465 |
444 static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf) | 466 static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf) |
445 { | 467 { |
446 ngx_core_conf_t *ccf = conf; | 468 ngx_core_conf_t *ccf = conf; |
447 | 469 |
448 #if !(WIN32) | 470 #if !(NGX_WIN32) |
449 struct passwd *pwd; | 471 struct passwd *pwd; |
450 struct group *grp; | 472 struct group *grp; |
451 #endif | 473 #endif |
452 | 474 |
453 ngx_conf_init_value(ccf->daemon, 1); | 475 ngx_conf_init_value(ccf->daemon, 1); |
454 ngx_conf_init_value(ccf->master, 1); | 476 ngx_conf_init_value(ccf->master, 1); |
455 ngx_conf_init_value(ccf->worker_processes, 1); | 477 ngx_conf_init_value(ccf->worker_processes, 1); |
478 ngx_conf_init_value(ccf->debug_points, 0); | |
456 | 479 |
457 #if (NGX_THREADS) | 480 #if (NGX_THREADS) |
458 ngx_conf_init_value(ccf->worker_threads, 0); | 481 ngx_conf_init_value(ccf->worker_threads, 0); |
459 ngx_threads_n = ccf->worker_threads; | 482 ngx_threads_n = ccf->worker_threads; |
460 ngx_conf_init_size_value(ccf->thread_stack_size, 2 * 1024 * 1024); | 483 ngx_conf_init_size_value(ccf->thread_stack_size, 2 * 1024 * 1024); |
461 #endif | 484 #endif |
462 | 485 |
463 #if !(WIN32) | 486 #if !(NGX_WIN32) |
464 | 487 |
465 if (ccf->user == (uid_t) NGX_CONF_UNSET) { | 488 if (ccf->user == (uid_t) NGX_CONF_UNSET && geteuid() == 0) { |
466 | 489 |
467 pwd = getpwnam(NGX_USER); | 490 pwd = getpwnam(NGX_USER); |
468 if (pwd == NULL) { | 491 if (pwd == NULL) { |
469 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | 492 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
470 "getpwnam(\"" NGX_USER "\") failed"); | 493 "getpwnam(\"" NGX_USER "\") failed"); |
507 } | 530 } |
508 | 531 |
509 | 532 |
510 static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 533 static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
511 { | 534 { |
512 #if (WIN32) | 535 #if (NGX_WIN32) |
513 | 536 |
514 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | 537 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
515 "\"user\" is not supported, ignored"); | 538 "\"user\" is not supported, ignored"); |
516 | 539 |
517 return NGX_CONF_OK; | 540 return NGX_CONF_OK; |