changeset 1704:e584e946e198

move condition declarations inside blocks where they are used
author Igor Sysoev <igor@sysoev.ru>
date Mon, 10 Dec 2007 12:09:51 +0000
parents 43747661804d
children d22095839d86
files src/core/nginx.c src/core/ngx_cycle.c src/core/ngx_file.c src/event/modules/ngx_select_module.c src/event/ngx_event.c src/http/modules/ngx_http_referer_module.c src/http/modules/ngx_http_ssi_filter_module.c src/http/ngx_http.c src/http/ngx_http_core_module.c src/http/ngx_http_request.c src/mail/ngx_mail_handler.c src/mail/ngx_mail_imap_handler.c src/mail/ngx_mail_pop3_handler.c src/mail/ngx_mail_smtp_handler.c src/os/unix/ngx_process_cycle.c
diffstat 15 files changed, 70 insertions(+), 88 deletions(-) [+]
line wrap: on
line diff
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -758,12 +758,6 @@ ngx_core_module_init_conf(ngx_cycle_t *c
 {
     ngx_core_conf_t  *ccf = conf;
 
-#if !(NGX_WIN32)
-    ngx_str_t       lock_file;
-    struct group   *grp;
-    struct passwd  *pwd;
-#endif
-
     ngx_conf_init_value(ccf->daemon, 1);
     ngx_conf_init_value(ccf->master, 1);
     ngx_conf_init_msec_value(ccf->timer_resolution, 0);
@@ -796,6 +790,8 @@ ngx_core_module_init_conf(ngx_cycle_t *c
 #if !(NGX_WIN32)
 
     if (ccf->user == (uid_t) NGX_CONF_UNSET_UINT && geteuid() == 0) {
+        struct group   *grp;
+        struct passwd  *pwd;
 
         ngx_set_errno(0);
         pwd = getpwnam(NGX_USER);
@@ -848,6 +844,9 @@ ngx_core_module_init_conf(ngx_cycle_t *c
         return NGX_CONF_ERROR;
     }
 
+    {
+    ngx_str_t  lock_file;
+
     lock_file = cycle->old_cycle->lock_file;
 
     if (lock_file.len) {
@@ -881,6 +880,7 @@ ngx_core_module_init_conf(ngx_cycle_t *c
                               ccf->lock_file.len),
                    ".accept", sizeof(".accept"));
     }
+    }
 
 #endif
 
--- a/src/core/ngx_cycle.c
+++ b/src/core/ngx_cycle.c
@@ -938,9 +938,6 @@ ngx_reopen_files(ngx_cycle_t *cycle, ngx
     ngx_uint_t        i;
     ngx_list_part_t  *part;
     ngx_open_file_t  *file;
-#if !(NGX_WIN32)
-    ngx_file_info_t   fi;
-#endif
 
     part = &cycle->open_files.part;
     file = part->elts;
@@ -996,6 +993,7 @@ ngx_reopen_files(ngx_cycle_t *cycle, ngx
         }
 #else
         if (user != (ngx_uid_t) NGX_CONF_UNSET_UINT) {
+            ngx_file_info_t  fi;
 
             if (ngx_file_info((const char *) file[i].name.data, &fi) == -1) {
                 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
--- a/src/core/ngx_file.c
+++ b/src/core/ngx_file.c
@@ -425,9 +425,6 @@ ngx_create_pathes(ngx_cycle_t *cycle, ng
     ngx_err_t         err;
     ngx_uint_t        i;
     ngx_path_t      **path;
-#if !(NGX_WIN32)
-    ngx_file_info_t   fi;
-#endif
 
     path = cycle->pathes.elts;
     for (i = 0; i < cycle->pathes.nelts; i++) {
@@ -447,6 +444,8 @@ ngx_create_pathes(ngx_cycle_t *cycle, ng
         }
 
 #if !(NGX_WIN32)
+        {
+        ngx_file_info_t   fi;
 
         if (ngx_file_info((const char *) path[i]->name.data, &fi) == -1) {
             ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
@@ -474,7 +473,7 @@ ngx_create_pathes(ngx_cycle_t *cycle, ng
                 return NGX_ERROR;
             }
         }
-
+        }
 #endif
     }
 
--- a/src/event/modules/ngx_select_module.c
+++ b/src/event/modules/ngx_select_module.c
@@ -254,9 +254,6 @@ ngx_select_process_events(ngx_cycle_t *c
     ngx_event_t        *ev, **queue;
     ngx_connection_t   *c;
     struct timeval      tv, *tp;
-#if !(NGX_WIN32)
-    ngx_uint_t          level;
-#endif
 
 #if !(NGX_WIN32)
 
@@ -348,6 +345,8 @@ ngx_select_process_events(ngx_cycle_t *c
 #else
 
     if (err) {
+        ngx_uint_t  level;
+
         if (err == NGX_EINTR) {
 
             if (ngx_event_timer_alarm) {
--- a/src/event/ngx_event.c
+++ b/src/event/ngx_event.c
@@ -428,13 +428,9 @@ ngx_event_module_init(ngx_cycle_t *cycle
     void              ***cf;
     u_char              *shared;
     size_t               size, cl;
-    ngx_event_conf_t    *ecf;
+    ngx_shm_t            shm;
     ngx_core_conf_t     *ccf;
-    ngx_shm_t            shm;
-#if !(NGX_WIN32)
-    ngx_int_t            limit;
-    struct rlimit        rlmt;
-#endif
+    ngx_event_conf_t    *ecf;
 
     cf = ngx_get_conf(cycle->conf_ctx, ngx_events_module);
 
@@ -456,6 +452,9 @@ ngx_event_module_init(ngx_cycle_t *cycle
     ngx_timer_resolution = ccf->timer_resolution;
 
 #if !(NGX_WIN32)
+    {
+    ngx_int_t      limit;
+    struct rlimit  rlmt;
 
     if (getrlimit(RLIMIT_NOFILE, &rlmt) == -1) {
         ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
@@ -475,7 +474,7 @@ ngx_event_module_init(ngx_cycle_t *cycle
                           ecf->connections, limit);
         }
     }
-
+    }
 #endif /* !(NGX_WIN32) */
 
 
@@ -573,13 +572,6 @@ ngx_event_process_init(ngx_cycle_t *cycl
     ngx_core_conf_t     *ccf;
     ngx_event_conf_t    *ecf;
     ngx_event_module_t  *module;
-#if (NGX_WIN32)
-    ngx_iocp_conf_t     *iocpcf;
-#else
-    struct rlimit        rlmt;
-    struct sigaction     sa;
-    struct itimerval     itv;
-#endif
 
     ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
     ecf = ngx_event_get_conf(cycle->conf_ctx, ngx_event_core_module);
@@ -625,6 +617,8 @@ ngx_event_process_init(ngx_cycle_t *cycl
 #if !(NGX_WIN32)
 
     if (ngx_timer_resolution && !(ngx_event_flags & NGX_USE_TIMER_EVENT)) {
+        struct sigaction  sa;
+        struct itimerval  itv;
 
         ngx_memzero(&sa, sizeof(struct sigaction));
         sa.sa_handler = ngx_timer_signal_handler;
@@ -648,6 +642,7 @@ ngx_event_process_init(ngx_cycle_t *cycl
     }
 
     if (ngx_event_flags & NGX_USE_FD_EVENT) {
+        struct rlimit  rlmt;
 
         if (getrlimit(RLIMIT_NOFILE, &rlmt) == -1) {
             ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
@@ -774,6 +769,8 @@ ngx_event_process_init(ngx_cycle_t *cycl
 #if (NGX_WIN32)
 
         if (ngx_event_flags & NGX_USE_IOCP_EVENT) {
+            ngx_iocp_conf_t  *iocpcf;
+
             rev->handler = ngx_event_acceptex;
 
             if (ngx_add_event(rev, 0, NGX_IOCP_ACCEPT) == NGX_ERROR) {
--- a/src/http/modules/ngx_http_referer_module.c
+++ b/src/http/modules/ngx_http_referer_module.c
@@ -106,11 +106,6 @@ ngx_http_referer_variable(ngx_http_reque
     ngx_uint_t                 i, key;
     ngx_http_referer_conf_t   *rlcf;
     u_char                     buf[256];
-#if (NGX_PCRE)
-    ngx_int_t                  n;
-    ngx_str_t                  referer;
-    ngx_http_referer_regex_t  *regex;
-#endif
 
     rlcf = ngx_http_get_module_loc_conf(r, ngx_http_referer_module);
 
@@ -173,6 +168,9 @@ ngx_http_referer_variable(ngx_http_reque
 #if (NGX_PCRE)
 
     if (rlcf->regex) {
+        ngx_int_t                  n;
+        ngx_str_t                  referer;
+        ngx_http_referer_regex_t  *regex;
 
         referer.len = len - 7;
         referer.data = ref;
--- a/src/http/modules/ngx_http_ssi_filter_module.c
+++ b/src/http/modules/ngx_http_ssi_filter_module.c
@@ -2373,11 +2373,6 @@ ngx_http_ssi_if(ngx_http_request_t *r, n
     ngx_str_t    *expr, left, right;
     ngx_int_t     rc;
     ngx_uint_t    negative, noregex, flags;
-#if (NGX_PCRE)
-    ngx_str_t     err;
-    ngx_regex_t  *regex;
-    u_char        errstr[NGX_MAX_CONF_ERRSTR];
-#endif
 
     if (ctx->command.len == 2) {
         if (ctx->conditional) {
@@ -2511,6 +2506,10 @@ ngx_http_ssi_if(ngx_http_request_t *r, n
 
     } else {
 #if (NGX_PCRE)
+        ngx_str_t     err;
+        ngx_regex_t  *regex;
+        u_char        errstr[NGX_MAX_CONF_ERRSTR];
+
         err.len = NGX_MAX_CONF_ERRSTR;
         err.data = errstr;
 
--- a/src/http/ngx_http.c
+++ b/src/http/ngx_http.c
@@ -101,9 +101,6 @@ ngx_http_block(ngx_conf_t *cf, ngx_comma
 #if (NGX_PCRE)
     ngx_uint_t                   regex;
 #endif
-#if (NGX_WIN32)
-    ngx_iocp_conf_t             *iocpcf;
-#endif
 
     /* the main http context */
 
@@ -821,10 +818,14 @@ ngx_http_block(ngx_conf_t *cf, ngx_comma
             ls->log.handler = ngx_accept_log_error;
 
 #if (NGX_WIN32)
+            {
+            ngx_iocp_conf_t  *iocpcf;
+
             iocpcf = ngx_event_get_conf(cf->cycle->conf_ctx, ngx_iocp_module);
             if (iocpcf->acceptex_read) {
                 ls->post_accept_buffer_size = cscf->client_header_buffer_size;
             }
+            }
 #endif
 
             ls->backlog = in_addr[a].listen_conf->backlog;
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -1803,10 +1803,6 @@ ngx_http_core_location(ngx_conf_t *cf, n
     ngx_http_conf_ctx_t       *ctx, *pctx;
     ngx_http_core_srv_conf_t  *cscf;
     ngx_http_core_loc_conf_t  *clcf, *pclcf, **clcfp;
-#if (NGX_PCRE)
-    ngx_str_t                  err;
-    u_char                     errstr[NGX_MAX_CONF_ERRSTR];
-#endif
 
     ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
     if (ctx == NULL) {
@@ -1861,6 +1857,9 @@ ngx_http_core_location(ngx_conf_t *cf, n
                        && value[1].data[1] == '*'))
         {
 #if (NGX_PCRE)
+            ngx_str_t  err;
+            u_char     errstr[NGX_MAX_CONF_ERRSTR];
+
             err.len = NGX_MAX_CONF_ERRSTR;
             err.data = errstr;
 
@@ -2803,10 +2802,6 @@ ngx_http_core_server_name(ngx_conf_t *cf
     ngx_str_t               *value, name;
     ngx_uint_t               i;
     ngx_http_server_name_t  *sn;
-#if (NGX_PCRE)
-    ngx_str_t                err;
-    u_char                   errstr[NGX_MAX_CONF_ERRSTR];
-#endif
 
     value = cf->args->elts;
 
@@ -2882,6 +2877,10 @@ ngx_http_core_server_name(ngx_conf_t *cf
         }
 
 #if (NGX_PCRE)
+        {
+        ngx_str_t  err;
+        u_char     errstr[NGX_MAX_CONF_ERRSTR];
+
         err.len = NGX_MAX_CONF_ERRSTR;
         err.data = errstr;
 
@@ -2898,7 +2897,7 @@ ngx_http_core_server_name(ngx_conf_t *cf
 
         sn->name.len = value[i].len;
         sn->name.data = value[i].data;
-
+        }
 #else
         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                            "the using of the regex \"%V\" "
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -232,9 +232,6 @@ ngx_http_init_request(ngx_event_t *rev)
     ngx_http_core_srv_conf_t   *cscf;
     ngx_http_core_loc_conf_t   *clcf;
     ngx_http_core_main_conf_t  *cmcf;
-#if (NGX_HTTP_SSL)
-    ngx_http_ssl_srv_conf_t    *sscf;
-#endif
 
 #if (NGX_STAT_STUB)
     ngx_atomic_fetch_add(ngx_stat_reading, -1);
@@ -354,6 +351,9 @@ ngx_http_init_request(ngx_event_t *rev)
 
 #if (NGX_HTTP_SSL)
 
+    {
+    ngx_http_ssl_srv_conf_t  *sscf;
+
     sscf = ngx_http_get_module_srv_conf(r, ngx_http_ssl_module);
     if (sscf->enable) {
 
@@ -370,6 +370,7 @@ ngx_http_init_request(ngx_event_t *rev)
 
         r->main_filter_need_in_memory = 1;
     }
+    }
 
 #endif
 
@@ -1398,11 +1399,7 @@ ngx_http_process_request_header(ngx_http
 static void
 ngx_http_process_request(ngx_http_request_t *r)
 {
-    ngx_connection_t         *c;
-#if (NGX_HTTP_SSL)
-    long                      rc;
-    ngx_http_ssl_srv_conf_t  *sscf;
-#endif
+    ngx_connection_t  *c;
 
     c = r->connection;
 
@@ -1416,6 +1413,9 @@ ngx_http_process_request(ngx_http_reques
 #if (NGX_HTTP_SSL)
 
     if (c->ssl) {
+        long                      rc;
+        ngx_http_ssl_srv_conf_t  *sscf;
+
         sscf = ngx_http_get_module_srv_conf(r, ngx_http_ssl_module);
 
         if (sscf->verify) {
@@ -1469,12 +1469,6 @@ ngx_http_find_virtual_server(ngx_http_re
 {
     ngx_http_core_loc_conf_t  *clcf;
     ngx_http_core_srv_conf_t  *cscf;
-#if (NGX_PCRE)
-    ngx_int_t                  n;
-    ngx_uint_t                 i;
-    ngx_str_t                  name;
-    ngx_http_server_name_t    *sn;
-#endif
 
     cscf = ngx_hash_find_combined(&r->virtual_names->names, hash, host, len);
 
@@ -1485,6 +1479,10 @@ ngx_http_find_virtual_server(ngx_http_re
 #if (NGX_PCRE)
 
     if (r->virtual_names->nregex) {
+        ngx_int_t                n;
+        ngx_uint_t               i;
+        ngx_str_t                name;
+        ngx_http_server_name_t  *sn;
 
         name.len = len;
         name.data = host;
--- a/src/mail/ngx_mail_handler.c
+++ b/src/mail/ngx_mail_handler.c
@@ -29,10 +29,6 @@ ngx_mail_init_connection(ngx_connection_
     ngx_mail_in_port_t   *imip;
     ngx_mail_in_addr_t   *imia;
     ngx_mail_session_t   *s;
-#if (NGX_MAIL_SSL)
-    ngx_mail_ssl_conf_t  *sslcf;
-#endif
-
 
     /* find the server configuration for the address:port */
 
@@ -116,6 +112,8 @@ ngx_mail_init_connection(ngx_connection_
     c->log_error = NGX_ERROR_INFO;
 
 #if (NGX_MAIL_SSL)
+    {
+    ngx_mail_ssl_conf_t  *sslcf;
 
     sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module);
 
@@ -123,7 +121,7 @@ ngx_mail_init_connection(ngx_connection_
         ngx_mail_ssl_init_connection(&sslcf->ssl, c);
         return;
     }
-
+    }
 #endif
 
     ngx_mail_init_session(c);
--- a/src/mail/ngx_mail_imap_handler.c
+++ b/src/mail/ngx_mail_imap_handler.c
@@ -302,7 +302,7 @@ ngx_mail_imap_auth_state(ngx_event_t *re
 static ngx_int_t
 ngx_mail_imap_login(ngx_mail_session_t *s, ngx_connection_t *c)
 {
-    ngx_str_t            *arg;
+    ngx_str_t  *arg;
 
 #if (NGX_MAIL_SSL)
     if (ngx_mail_starttls_only(s, c)) {
@@ -410,15 +410,14 @@ static ngx_int_t
 ngx_mail_imap_capability(ngx_mail_session_t *s, ngx_connection_t *c)
 {
     ngx_mail_imap_srv_conf_t  *iscf;
-#if (NGX_MAIL_SSL)
-    ngx_mail_ssl_conf_t       *sslcf;
-#endif
 
     iscf = ngx_mail_get_module_srv_conf(s, ngx_mail_imap_module);
 
 #if (NGX_MAIL_SSL)
 
     if (c->ssl == NULL) {
+        ngx_mail_ssl_conf_t  *sslcf;
+
         sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module);
 
         if (sslcf->starttls == NGX_MAIL_STARTTLS_ON) {
--- a/src/mail/ngx_mail_pop3_handler.c
+++ b/src/mail/ngx_mail_pop3_handler.c
@@ -283,7 +283,7 @@ ngx_mail_pop3_auth_state(ngx_event_t *re
 static ngx_int_t
 ngx_mail_pop3_user(ngx_mail_session_t *s, ngx_connection_t *c)
 {
-    ngx_str_t            *arg;
+    ngx_str_t  *arg;
 
 #if (NGX_MAIL_SSL)
     if (ngx_mail_starttls_only(s, c)) {
@@ -344,15 +344,14 @@ static ngx_int_t
 ngx_mail_pop3_capa(ngx_mail_session_t *s, ngx_connection_t *c, ngx_int_t stls)
 {
     ngx_mail_pop3_srv_conf_t  *pscf;
-#if (NGX_MAIL_SSL)
-    ngx_mail_ssl_conf_t       *sslcf;
-#endif
 
     pscf = ngx_mail_get_module_srv_conf(s, ngx_mail_pop3_module);
 
 #if (NGX_MAIL_SSL)
 
     if (stls && c->ssl == NULL) {
+        ngx_mail_ssl_conf_t  *sslcf;
+
         sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module);
 
         if (sslcf->starttls == NGX_MAIL_STARTTLS_ON) {
--- a/src/mail/ngx_mail_smtp_handler.c
+++ b/src/mail/ngx_mail_smtp_handler.c
@@ -319,9 +319,6 @@ ngx_mail_smtp_helo(ngx_mail_session_t *s
 {
     ngx_str_t                 *arg;
     ngx_mail_smtp_srv_conf_t  *sscf;
-#if (NGX_MAIL_SSL)
-    ngx_mail_ssl_conf_t       *sslcf;
-#endif
 
     if (s->args.nelts != 1) {
         s->out.len = sizeof(smtp_invalid_argument) - 1;
@@ -352,6 +349,8 @@ ngx_mail_smtp_helo(ngx_mail_session_t *s
 #if (NGX_MAIL_SSL)
 
         if (c->ssl == NULL) {
+            ngx_mail_ssl_conf_t  *sslcf;
+
             sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module);
 
             if (sslcf->starttls == NGX_MAIL_STARTTLS_ON) {
--- a/src/os/unix/ngx_process_cycle.c
+++ b/src/os/unix/ngx_process_cycle.c
@@ -687,17 +687,16 @@ ngx_worker_process_cycle(ngx_cycle_t *cy
 {
     ngx_uint_t         i;
     ngx_connection_t  *c;
-#if (NGX_THREADS)
-    ngx_int_t          n;
-    ngx_err_t          err;
-    ngx_core_conf_t   *ccf;
-#endif
 
     ngx_worker_process_init(cycle, 1);
 
     ngx_setproctitle("worker process");
 
 #if (NGX_THREADS)
+    {
+    ngx_int_t         n;
+    ngx_err_t         err;
+    ngx_core_conf_t  *ccf;
 
     ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
 
@@ -736,7 +735,7 @@ ngx_worker_process_cycle(ngx_cycle_t *cy
             }
         }
     }
-
+    }
 #endif
 
     for ( ;; ) {