move condition declarations inside blocks where they are used
Igor Sysoev
14 years ago
757 | 757 | { |
758 | 758 | ngx_core_conf_t *ccf = conf; |
759 | 759 | |
760 | #if !(NGX_WIN32) | |
761 | ngx_str_t lock_file; | |
762 | struct group *grp; | |
763 | struct passwd *pwd; | |
764 | #endif | |
765 | ||
766 | 760 | ngx_conf_init_value(ccf->daemon, 1); |
767 | 761 | ngx_conf_init_value(ccf->master, 1); |
768 | 762 | ngx_conf_init_msec_value(ccf->timer_resolution, 0); |
795 | 789 | #if !(NGX_WIN32) |
796 | 790 | |
797 | 791 | if (ccf->user == (uid_t) NGX_CONF_UNSET_UINT && geteuid() == 0) { |
792 | struct group *grp; | |
793 | struct passwd *pwd; | |
798 | 794 | |
799 | 795 | ngx_set_errno(0); |
800 | 796 | pwd = getpwnam(NGX_USER); |
847 | 843 | return NGX_CONF_ERROR; |
848 | 844 | } |
849 | 845 | |
846 | { | |
847 | ngx_str_t lock_file; | |
848 | ||
850 | 849 | lock_file = cycle->old_cycle->lock_file; |
851 | 850 | |
852 | 851 | if (lock_file.len) { |
880 | 879 | ccf->lock_file.len), |
881 | 880 | ".accept", sizeof(".accept")); |
882 | 881 | } |
882 | } | |
883 | 883 | |
884 | 884 | #endif |
885 | 885 |
937 | 937 | ngx_uint_t i; |
938 | 938 | ngx_list_part_t *part; |
939 | 939 | ngx_open_file_t *file; |
940 | #if !(NGX_WIN32) | |
941 | ngx_file_info_t fi; | |
942 | #endif | |
943 | 940 | |
944 | 941 | part = &cycle->open_files.part; |
945 | 942 | file = part->elts; |
995 | 992 | } |
996 | 993 | #else |
997 | 994 | if (user != (ngx_uid_t) NGX_CONF_UNSET_UINT) { |
995 | ngx_file_info_t fi; | |
998 | 996 | |
999 | 997 | if (ngx_file_info((const char *) file[i].name.data, &fi) == -1) { |
1000 | 998 | ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
424 | 424 | ngx_err_t err; |
425 | 425 | ngx_uint_t i; |
426 | 426 | ngx_path_t **path; |
427 | #if !(NGX_WIN32) | |
428 | ngx_file_info_t fi; | |
429 | #endif | |
430 | 427 | |
431 | 428 | path = cycle->pathes.elts; |
432 | 429 | for (i = 0; i < cycle->pathes.nelts; i++) { |
446 | 443 | } |
447 | 444 | |
448 | 445 | #if !(NGX_WIN32) |
446 | { | |
447 | ngx_file_info_t fi; | |
449 | 448 | |
450 | 449 | if (ngx_file_info((const char *) path[i]->name.data, &fi) == -1) { |
451 | 450 | ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
473 | 472 | return NGX_ERROR; |
474 | 473 | } |
475 | 474 | } |
476 | ||
475 | } | |
477 | 476 | #endif |
478 | 477 | } |
479 | 478 |
253 | 253 | ngx_event_t *ev, **queue; |
254 | 254 | ngx_connection_t *c; |
255 | 255 | struct timeval tv, *tp; |
256 | #if !(NGX_WIN32) | |
257 | ngx_uint_t level; | |
258 | #endif | |
259 | 256 | |
260 | 257 | #if !(NGX_WIN32) |
261 | 258 | |
347 | 344 | #else |
348 | 345 | |
349 | 346 | if (err) { |
347 | ngx_uint_t level; | |
348 | ||
350 | 349 | if (err == NGX_EINTR) { |
351 | 350 | |
352 | 351 | if (ngx_event_timer_alarm) { |
427 | 427 | void ***cf; |
428 | 428 | u_char *shared; |
429 | 429 | size_t size, cl; |
430 | ngx_shm_t shm; | |
431 | ngx_core_conf_t *ccf; | |
430 | 432 | ngx_event_conf_t *ecf; |
431 | ngx_core_conf_t *ccf; | |
432 | ngx_shm_t shm; | |
433 | #if !(NGX_WIN32) | |
434 | ngx_int_t limit; | |
435 | struct rlimit rlmt; | |
436 | #endif | |
437 | 433 | |
438 | 434 | cf = ngx_get_conf(cycle->conf_ctx, ngx_events_module); |
439 | 435 | |
455 | 451 | ngx_timer_resolution = ccf->timer_resolution; |
456 | 452 | |
457 | 453 | #if !(NGX_WIN32) |
454 | { | |
455 | ngx_int_t limit; | |
456 | struct rlimit rlmt; | |
458 | 457 | |
459 | 458 | if (getrlimit(RLIMIT_NOFILE, &rlmt) == -1) { |
460 | 459 | ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
474 | 473 | ecf->connections, limit); |
475 | 474 | } |
476 | 475 | } |
477 | ||
476 | } | |
478 | 477 | #endif /* !(NGX_WIN32) */ |
479 | 478 | |
480 | 479 | |
572 | 571 | ngx_core_conf_t *ccf; |
573 | 572 | ngx_event_conf_t *ecf; |
574 | 573 | ngx_event_module_t *module; |
575 | #if (NGX_WIN32) | |
576 | ngx_iocp_conf_t *iocpcf; | |
577 | #else | |
578 | struct rlimit rlmt; | |
579 | struct sigaction sa; | |
580 | struct itimerval itv; | |
581 | #endif | |
582 | 574 | |
583 | 575 | ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); |
584 | 576 | ecf = ngx_event_get_conf(cycle->conf_ctx, ngx_event_core_module); |
624 | 616 | #if !(NGX_WIN32) |
625 | 617 | |
626 | 618 | if (ngx_timer_resolution && !(ngx_event_flags & NGX_USE_TIMER_EVENT)) { |
619 | struct sigaction sa; | |
620 | struct itimerval itv; | |
627 | 621 | |
628 | 622 | ngx_memzero(&sa, sizeof(struct sigaction)); |
629 | 623 | sa.sa_handler = ngx_timer_signal_handler; |
647 | 641 | } |
648 | 642 | |
649 | 643 | if (ngx_event_flags & NGX_USE_FD_EVENT) { |
644 | struct rlimit rlmt; | |
650 | 645 | |
651 | 646 | if (getrlimit(RLIMIT_NOFILE, &rlmt) == -1) { |
652 | 647 | ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
773 | 768 | #if (NGX_WIN32) |
774 | 769 | |
775 | 770 | if (ngx_event_flags & NGX_USE_IOCP_EVENT) { |
771 | ngx_iocp_conf_t *iocpcf; | |
772 | ||
776 | 773 | rev->handler = ngx_event_acceptex; |
777 | 774 | |
778 | 775 | if (ngx_add_event(rev, 0, NGX_IOCP_ACCEPT) == NGX_ERROR) { |
105 | 105 | ngx_uint_t i, key; |
106 | 106 | ngx_http_referer_conf_t *rlcf; |
107 | 107 | u_char buf[256]; |
108 | #if (NGX_PCRE) | |
109 | ngx_int_t n; | |
110 | ngx_str_t referer; | |
111 | ngx_http_referer_regex_t *regex; | |
112 | #endif | |
113 | 108 | |
114 | 109 | rlcf = ngx_http_get_module_loc_conf(r, ngx_http_referer_module); |
115 | 110 | |
172 | 167 | #if (NGX_PCRE) |
173 | 168 | |
174 | 169 | if (rlcf->regex) { |
170 | ngx_int_t n; | |
171 | ngx_str_t referer; | |
172 | ngx_http_referer_regex_t *regex; | |
175 | 173 | |
176 | 174 | referer.len = len - 7; |
177 | 175 | referer.data = ref; |
2372 | 2372 | ngx_str_t *expr, left, right; |
2373 | 2373 | ngx_int_t rc; |
2374 | 2374 | ngx_uint_t negative, noregex, flags; |
2375 | #if (NGX_PCRE) | |
2376 | ngx_str_t err; | |
2377 | ngx_regex_t *regex; | |
2378 | u_char errstr[NGX_MAX_CONF_ERRSTR]; | |
2379 | #endif | |
2380 | 2375 | |
2381 | 2376 | if (ctx->command.len == 2) { |
2382 | 2377 | if (ctx->conditional) { |
2510 | 2505 | |
2511 | 2506 | } else { |
2512 | 2507 | #if (NGX_PCRE) |
2508 | ngx_str_t err; | |
2509 | ngx_regex_t *regex; | |
2510 | u_char errstr[NGX_MAX_CONF_ERRSTR]; | |
2511 | ||
2513 | 2512 | err.len = NGX_MAX_CONF_ERRSTR; |
2514 | 2513 | err.data = errstr; |
2515 | 2514 |
100 | 100 | #if (NGX_PCRE) |
101 | 101 | ngx_uint_t regex; |
102 | 102 | #endif |
103 | #if (NGX_WIN32) | |
104 | ngx_iocp_conf_t *iocpcf; | |
105 | #endif | |
106 | 103 | |
107 | 104 | /* the main http context */ |
108 | 105 | |
820 | 817 | ls->log.handler = ngx_accept_log_error; |
821 | 818 | |
822 | 819 | #if (NGX_WIN32) |
820 | { | |
821 | ngx_iocp_conf_t *iocpcf; | |
822 | ||
823 | 823 | iocpcf = ngx_event_get_conf(cf->cycle->conf_ctx, ngx_iocp_module); |
824 | 824 | if (iocpcf->acceptex_read) { |
825 | 825 | ls->post_accept_buffer_size = cscf->client_header_buffer_size; |
826 | } | |
826 | 827 | } |
827 | 828 | #endif |
828 | 829 |
1802 | 1802 | ngx_http_conf_ctx_t *ctx, *pctx; |
1803 | 1803 | ngx_http_core_srv_conf_t *cscf; |
1804 | 1804 | ngx_http_core_loc_conf_t *clcf, *pclcf, **clcfp; |
1805 | #if (NGX_PCRE) | |
1806 | ngx_str_t err; | |
1807 | u_char errstr[NGX_MAX_CONF_ERRSTR]; | |
1808 | #endif | |
1809 | 1805 | |
1810 | 1806 | ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)); |
1811 | 1807 | if (ctx == NULL) { |
1860 | 1856 | && value[1].data[1] == '*')) |
1861 | 1857 | { |
1862 | 1858 | #if (NGX_PCRE) |
1859 | ngx_str_t err; | |
1860 | u_char errstr[NGX_MAX_CONF_ERRSTR]; | |
1861 | ||
1863 | 1862 | err.len = NGX_MAX_CONF_ERRSTR; |
1864 | 1863 | err.data = errstr; |
1865 | 1864 | |
2802 | 2801 | ngx_str_t *value, name; |
2803 | 2802 | ngx_uint_t i; |
2804 | 2803 | ngx_http_server_name_t *sn; |
2805 | #if (NGX_PCRE) | |
2806 | ngx_str_t err; | |
2807 | u_char errstr[NGX_MAX_CONF_ERRSTR]; | |
2808 | #endif | |
2809 | 2804 | |
2810 | 2805 | value = cf->args->elts; |
2811 | 2806 | |
2881 | 2876 | } |
2882 | 2877 | |
2883 | 2878 | #if (NGX_PCRE) |
2879 | { | |
2880 | ngx_str_t err; | |
2881 | u_char errstr[NGX_MAX_CONF_ERRSTR]; | |
2882 | ||
2884 | 2883 | err.len = NGX_MAX_CONF_ERRSTR; |
2885 | 2884 | err.data = errstr; |
2886 | 2885 | |
2897 | 2896 | |
2898 | 2897 | sn->name.len = value[i].len; |
2899 | 2898 | sn->name.data = value[i].data; |
2900 | ||
2899 | } | |
2901 | 2900 | #else |
2902 | 2901 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2903 | 2902 | "the using of the regex \"%V\" " |
231 | 231 | ngx_http_core_srv_conf_t *cscf; |
232 | 232 | ngx_http_core_loc_conf_t *clcf; |
233 | 233 | ngx_http_core_main_conf_t *cmcf; |
234 | #if (NGX_HTTP_SSL) | |
235 | ngx_http_ssl_srv_conf_t *sscf; | |
236 | #endif | |
237 | 234 | |
238 | 235 | #if (NGX_STAT_STUB) |
239 | 236 | ngx_atomic_fetch_add(ngx_stat_reading, -1); |
353 | 350 | |
354 | 351 | #if (NGX_HTTP_SSL) |
355 | 352 | |
353 | { | |
354 | ngx_http_ssl_srv_conf_t *sscf; | |
355 | ||
356 | 356 | sscf = ngx_http_get_module_srv_conf(r, ngx_http_ssl_module); |
357 | 357 | if (sscf->enable) { |
358 | 358 | |
368 | 368 | } |
369 | 369 | |
370 | 370 | r->main_filter_need_in_memory = 1; |
371 | } | |
371 | 372 | } |
372 | 373 | |
373 | 374 | #endif |
1397 | 1398 | static void |
1398 | 1399 | ngx_http_process_request(ngx_http_request_t *r) |
1399 | 1400 | { |
1400 | ngx_connection_t *c; | |
1401 | #if (NGX_HTTP_SSL) | |
1402 | long rc; | |
1403 | ngx_http_ssl_srv_conf_t *sscf; | |
1404 | #endif | |
1401 | ngx_connection_t *c; | |
1405 | 1402 | |
1406 | 1403 | c = r->connection; |
1407 | 1404 | |
1415 | 1412 | #if (NGX_HTTP_SSL) |
1416 | 1413 | |
1417 | 1414 | if (c->ssl) { |
1415 | long rc; | |
1416 | ngx_http_ssl_srv_conf_t *sscf; | |
1417 | ||
1418 | 1418 | sscf = ngx_http_get_module_srv_conf(r, ngx_http_ssl_module); |
1419 | 1419 | |
1420 | 1420 | if (sscf->verify) { |
1468 | 1468 | { |
1469 | 1469 | ngx_http_core_loc_conf_t *clcf; |
1470 | 1470 | ngx_http_core_srv_conf_t *cscf; |
1471 | #if (NGX_PCRE) | |
1472 | ngx_int_t n; | |
1473 | ngx_uint_t i; | |
1474 | ngx_str_t name; | |
1475 | ngx_http_server_name_t *sn; | |
1476 | #endif | |
1477 | 1471 | |
1478 | 1472 | cscf = ngx_hash_find_combined(&r->virtual_names->names, hash, host, len); |
1479 | 1473 | |
1484 | 1478 | #if (NGX_PCRE) |
1485 | 1479 | |
1486 | 1480 | if (r->virtual_names->nregex) { |
1481 | ngx_int_t n; | |
1482 | ngx_uint_t i; | |
1483 | ngx_str_t name; | |
1484 | ngx_http_server_name_t *sn; | |
1487 | 1485 | |
1488 | 1486 | name.len = len; |
1489 | 1487 | name.data = host; |
28 | 28 | ngx_mail_in_port_t *imip; |
29 | 29 | ngx_mail_in_addr_t *imia; |
30 | 30 | ngx_mail_session_t *s; |
31 | #if (NGX_MAIL_SSL) | |
32 | ngx_mail_ssl_conf_t *sslcf; | |
33 | #endif | |
34 | ||
35 | 31 | |
36 | 32 | /* find the server configuration for the address:port */ |
37 | 33 | |
115 | 111 | c->log_error = NGX_ERROR_INFO; |
116 | 112 | |
117 | 113 | #if (NGX_MAIL_SSL) |
114 | { | |
115 | ngx_mail_ssl_conf_t *sslcf; | |
118 | 116 | |
119 | 117 | sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module); |
120 | 118 | |
122 | 120 | ngx_mail_ssl_init_connection(&sslcf->ssl, c); |
123 | 121 | return; |
124 | 122 | } |
125 | ||
123 | } | |
126 | 124 | #endif |
127 | 125 | |
128 | 126 | ngx_mail_init_session(c); |
301 | 301 | static ngx_int_t |
302 | 302 | ngx_mail_imap_login(ngx_mail_session_t *s, ngx_connection_t *c) |
303 | 303 | { |
304 | ngx_str_t *arg; | |
304 | ngx_str_t *arg; | |
305 | 305 | |
306 | 306 | #if (NGX_MAIL_SSL) |
307 | 307 | if (ngx_mail_starttls_only(s, c)) { |
409 | 409 | ngx_mail_imap_capability(ngx_mail_session_t *s, ngx_connection_t *c) |
410 | 410 | { |
411 | 411 | ngx_mail_imap_srv_conf_t *iscf; |
412 | ||
413 | iscf = ngx_mail_get_module_srv_conf(s, ngx_mail_imap_module); | |
414 | ||
412 | 415 | #if (NGX_MAIL_SSL) |
413 | ngx_mail_ssl_conf_t *sslcf; | |
414 | #endif | |
415 | ||
416 | iscf = ngx_mail_get_module_srv_conf(s, ngx_mail_imap_module); | |
417 | ||
418 | #if (NGX_MAIL_SSL) | |
419 | 416 | |
420 | 417 | if (c->ssl == NULL) { |
418 | ngx_mail_ssl_conf_t *sslcf; | |
419 | ||
421 | 420 | sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module); |
422 | 421 | |
423 | 422 | if (sslcf->starttls == NGX_MAIL_STARTTLS_ON) { |
282 | 282 | static ngx_int_t |
283 | 283 | ngx_mail_pop3_user(ngx_mail_session_t *s, ngx_connection_t *c) |
284 | 284 | { |
285 | ngx_str_t *arg; | |
285 | ngx_str_t *arg; | |
286 | 286 | |
287 | 287 | #if (NGX_MAIL_SSL) |
288 | 288 | if (ngx_mail_starttls_only(s, c)) { |
343 | 343 | ngx_mail_pop3_capa(ngx_mail_session_t *s, ngx_connection_t *c, ngx_int_t stls) |
344 | 344 | { |
345 | 345 | ngx_mail_pop3_srv_conf_t *pscf; |
346 | ||
347 | pscf = ngx_mail_get_module_srv_conf(s, ngx_mail_pop3_module); | |
348 | ||
346 | 349 | #if (NGX_MAIL_SSL) |
347 | ngx_mail_ssl_conf_t *sslcf; | |
348 | #endif | |
349 | ||
350 | pscf = ngx_mail_get_module_srv_conf(s, ngx_mail_pop3_module); | |
351 | ||
352 | #if (NGX_MAIL_SSL) | |
353 | 350 | |
354 | 351 | if (stls && c->ssl == NULL) { |
352 | ngx_mail_ssl_conf_t *sslcf; | |
353 | ||
355 | 354 | sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module); |
356 | 355 | |
357 | 356 | if (sslcf->starttls == NGX_MAIL_STARTTLS_ON) { |
318 | 318 | { |
319 | 319 | ngx_str_t *arg; |
320 | 320 | ngx_mail_smtp_srv_conf_t *sscf; |
321 | #if (NGX_MAIL_SSL) | |
322 | ngx_mail_ssl_conf_t *sslcf; | |
323 | #endif | |
324 | 321 | |
325 | 322 | if (s->args.nelts != 1) { |
326 | 323 | s->out.len = sizeof(smtp_invalid_argument) - 1; |
351 | 348 | #if (NGX_MAIL_SSL) |
352 | 349 | |
353 | 350 | if (c->ssl == NULL) { |
351 | ngx_mail_ssl_conf_t *sslcf; | |
352 | ||
354 | 353 | sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module); |
355 | 354 | |
356 | 355 | if (sslcf->starttls == NGX_MAIL_STARTTLS_ON) { |
686 | 686 | { |
687 | 687 | ngx_uint_t i; |
688 | 688 | ngx_connection_t *c; |
689 | ||
690 | ngx_worker_process_init(cycle, 1); | |
691 | ||
692 | ngx_setproctitle("worker process"); | |
693 | ||
689 | 694 | #if (NGX_THREADS) |
690 | ngx_int_t n; | |
691 | ngx_err_t err; | |
692 | ngx_core_conf_t *ccf; | |
693 | #endif | |
694 | ||
695 | ngx_worker_process_init(cycle, 1); | |
696 | ||
697 | ngx_setproctitle("worker process"); | |
698 | ||
699 | #if (NGX_THREADS) | |
695 | { | |
696 | ngx_int_t n; | |
697 | ngx_err_t err; | |
698 | ngx_core_conf_t *ccf; | |
700 | 699 | |
701 | 700 | ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); |
702 | 701 | |
735 | 734 | } |
736 | 735 | } |
737 | 736 | } |
738 | ||
737 | } | |
739 | 738 | #endif |
740 | 739 | |
741 | 740 | for ( ;; ) { |