]> git.kaiwu.me - nginx.git/commitdiff
*) refactor error_log processing: listen socket log might inherit built-in
authorIgor Sysoev <igor@sysoev.ru>
Thu, 30 Apr 2009 13:53:42 +0000 (13:53 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Thu, 30 Apr 2009 13:53:42 +0000 (13:53 +0000)
   error_log with zero level, and r2447, r2466, r2467 were not enough
*) remove bogus "stderr" level
*) some functions and fields renames

13 files changed:
src/core/ngx_conf_file.c
src/core/ngx_connection.c
src/core/ngx_connection.h
src/core/ngx_cycle.c
src/core/ngx_cycle.h
src/core/ngx_log.c
src/core/ngx_log.h
src/core/ngx_resolver.c
src/http/ngx_http.c
src/http/ngx_http_core_module.c
src/http/ngx_http_core_module.h
src/http/ngx_http_request.c
src/mail/ngx_mail.c

index 2662e5f6effa9695484cb44638397671925fad3c..644243781d78458491f58597db608950f92ae929 100644 (file)
@@ -858,7 +858,7 @@ ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name)
     full.data = NULL;
 #endif
 
-    if (name && name->len) {
+    if (name->len) {
         full = *name;
 
         if (ngx_conf_full_name(cycle, &full, 0) != NGX_OK) {
@@ -894,14 +894,13 @@ ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name)
         return NULL;
     }
 
-    if (name && name->len) {
+    if (name->len) {
         file->fd = NGX_INVALID_FILE;
         file->name = full;
 
     } else {
         file->fd = ngx_stderr;
-        file->name.len = 0;
-        file->name.data = NULL;
+        file->name = *name;
     }
 
     file->buffer = NULL;
index 2398d51619e3fb2ccf3830eb1821f1fbe51174d2..19344ab48344cbbf23cdf9056b48f5dccfe74cf7 100644 (file)
@@ -248,6 +248,8 @@ ngx_open_listening_sockets(ngx_cycle_t *cycle)
                 continue;
             }
 
+            ls[i].log = *ls[i].logp;
+
             if (ls[i].inherited) {
 
                 /* TODO: close on exit */
index cc6a92989f78156380e7a5e387350785d62ccc0a..de0ef41bec51dfa7e2ccea32d566740725c6a5f3 100644 (file)
@@ -34,6 +34,7 @@ struct ngx_listening_s {
     void               *servers;  /* array of ngx_http_in_addr_t, for example */
 
     ngx_log_t           log;
+    ngx_log_t          *logp;
 
     size_t              pool_size;
     /* should be here because of the AcceptEx() preread */
index 15f8e8d24b0e0f05c20f8e559197bd737feb3089..251892b74973f90d7db8ac677b1e1bc908b769c1 100644 (file)
@@ -82,6 +82,7 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
 
     cycle->pool = pool;
     cycle->log = log;
+    cycle->new_log.log_level = NGX_LOG_ERR;
     cycle->old_cycle = old_cycle;
 
     cycle->conf_prefix.len = old_cycle->conf_prefix.len;
@@ -165,14 +166,6 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
         return NULL;
     }
 
-
-    cycle->new_log = ngx_log_create_errlog(cycle, &error_log);
-    if (cycle->new_log == NULL) {
-        ngx_destroy_pool(pool);
-        return NULL;
-    }
-
-
     n = old_cycle->listening.nelts ? old_cycle->listening.nelts : 10;
 
     cycle->listening.elts = ngx_pcalloc(pool, n * sizeof(ngx_listening_t));
@@ -336,6 +329,13 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
     }
 
 
+    if (cycle->new_log.file == NULL) {
+        cycle->new_log.file = ngx_conf_open_file(cycle, &error_log);
+        if (cycle->new_log.file == NULL) {
+            goto failed;
+        }
+    }
+
     /* open the new files */
 
     part = &cycle->open_files.part;
@@ -382,12 +382,8 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
 #endif
     }
 
-    cycle->log = cycle->new_log;
-    pool->log = cycle->new_log;
-
-    if (cycle->log->log_level == 0) {
-        cycle->log->log_level = NGX_LOG_ERR;
-    }
+    cycle->log = &cycle->new_log;
+    pool->log = &cycle->new_log;
 
 
     /* create shared memory */
index b4007d4dc5c2ccd7b090107d338adc0bbe2e5141..e3905885d1f9e0de09414d400d5fa7762ee081bf 100644 (file)
@@ -38,7 +38,7 @@ struct ngx_cycle_s {
     ngx_pool_t               *pool;
 
     ngx_log_t                *log;
-    ngx_log_t                *new_log;
+    ngx_log_t                 new_log;
 
     ngx_connection_t        **files;
     ngx_connection_t         *free_connections;
index 924c81949c375286f639ee6a872c51ccca3b5db7..770a59084a0a0cda907d4c63ca55cc575bbde50c 100644 (file)
@@ -8,14 +8,14 @@
 #include <ngx_core.h>
 
 
-static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
+static char *ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
 
 
 static ngx_command_t  ngx_errlog_commands[] = {
 
     {ngx_string("error_log"),
      NGX_MAIN_CONF|NGX_CONF_1MORE,
-     ngx_set_error_log,
+     ngx_error_log,
      0,
      0,
      NULL},
@@ -53,7 +53,7 @@ ngx_uint_t              ngx_use_stderr = 1;
 
 
 static ngx_str_t err_levels[] = {
-    ngx_string("stderr"),
+    ngx_null_string,
     ngx_string("emerg"),
     ngx_string("alert"),
     ngx_string("crit"),
@@ -345,7 +345,7 @@ ngx_log_init(u_char *prefix)
 
 
 ngx_log_t *
-ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_str_t *name)
+ngx_log_create(ngx_cycle_t *cycle, ngx_str_t *name)
 {
     ngx_log_t  *log;
 
@@ -364,7 +364,7 @@ ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_str_t *name)
 
 
 char *
-ngx_set_error_log_levels(ngx_conf_t *cf, ngx_log_t *log)
+ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log)
 {
     ngx_uint_t   i, n, d;
     ngx_str_t   *value;
@@ -409,10 +409,7 @@ ngx_set_error_log_levels(ngx_conf_t *cf, ngx_log_t *log)
         }
     }
 
-    if (log->log_level == 0) {
-        log->log_level = NGX_LOG_ERR;
-
-    } else if (log->log_level == NGX_LOG_DEBUG) {
+    if (log->log_level == NGX_LOG_DEBUG) {
         log->log_level = NGX_LOG_DEBUG_ALL;
     }
 
@@ -421,26 +418,35 @@ ngx_set_error_log_levels(ngx_conf_t *cf, ngx_log_t *log)
 
 
 static char *
-ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 {
-    ngx_str_t  *value;
+    ngx_str_t  *value, name;
+
+    if (cf->cycle->new_log.file) {
+        return "is duplicate";
+    }
 
     value = cf->args->elts;
 
-    if (value[1].len == 6 && ngx_strcmp(value[1].data, "stderr") == 0) {
-        cf->cycle->new_log->file->fd = ngx_stderr;
-        cf->cycle->new_log->file->name.len = 0;
-        cf->cycle->new_log->file->name.data = NULL;
+    if (ngx_strcmp(value[1].data, "stderr") == 0) {
+        name.len = 0;
+        name.data = NULL;
 
     } else {
-        cf->cycle->new_log->file->name = value[1];
+        name = value[1];
+    }
 
-        if (ngx_conf_full_name(cf->cycle, &cf->cycle->new_log->file->name, 0)
-            != NGX_OK)
-        {
-            return NGX_CONF_ERROR;
-        }
+    cf->cycle->new_log.file = ngx_conf_open_file(cf->cycle, &name);
+    if (cf->cycle->new_log.file == NULL) {
+        return NULL;
     }
 
-    return ngx_set_error_log_levels(cf, cf->cycle->new_log);
+    if (cf->args->nelts == 2) {
+        cf->cycle->new_log.log_level = NGX_LOG_ERR;
+        return NGX_CONF_OK;
+    }
+
+    cf->cycle->new_log.log_level = 0;
+
+    return ngx_log_set_levels(cf, &cf->cycle->new_log);
 }
index f5335ba4713186b8785845903209a6eb887ad254..b736aa2eb9898fb20f86c4686eb5eccf5c26b5be 100644 (file)
@@ -196,8 +196,8 @@ void ngx_cdecl ngx_log_debug_core(ngx_log_t *log, ngx_err_t err,
 /*********************************/
 
 ngx_log_t *ngx_log_init(u_char *prefix);
-ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_str_t *name);
-char *ngx_set_error_log_levels(ngx_conf_t *cf, ngx_log_t *log);
+ngx_log_t *ngx_log_create(ngx_cycle_t *cycle, ngx_str_t *name);
+char *ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log);
 void ngx_cdecl ngx_log_abort(ngx_err_t err, const char *fmt, ...);
 void ngx_cdecl ngx_log_stderr(ngx_err_t err, const char *fmt, ...);
 u_char *ngx_log_errno(u_char *buf, u_char *last, ngx_err_t err);
index f58fb5ba7702f5247197bb07f5449d2bb54d2e2b..2b53ee07e59f2c81a363672859f7f44eec3ac5aa 100644 (file)
@@ -131,14 +131,14 @@ ngx_resolver_create(ngx_conf_t *cf, ngx_peer_addr_t *addr)
 
     r->event->handler = ngx_resolver_resend_handler;
     r->event->data = r;
-    r->event->log = cf->cycle->new_log;
+    r->event->log = &cf->cycle->new_log;
     r->ident = -1;
 
     r->resend_timeout = 5;
     r->expire = 30;
     r->valid = 300;
 
-    r->log = cf->cycle->new_log;
+    r->log = &cf->cycle->new_log;
     r->log_level = NGX_LOG_ALERT;
 
     if (addr) {
@@ -152,7 +152,7 @@ ngx_resolver_create(ngx_conf_t *cf, ngx_peer_addr_t *addr)
         uc->sockaddr = addr->sockaddr;
         uc->socklen = addr->socklen;
         uc->server = addr->name;
-        uc->log = cf->cycle->new_log;
+        uc->log = &cf->cycle->new_log;
     }
 
     return r;
index 5cd0ee1f83a37fa630fc8965f2d7d8a47515dfc6..5e487e75cbffbfa6d5ab26621c8c43cc587383c1 100644 (file)
@@ -1746,7 +1746,7 @@ ngx_http_add_listening(ngx_conf_t *cf, ngx_http_conf_addr_t *addr)
 
     clcf = cscf->ctx->loc_conf[ngx_http_core_module.ctx_index];
 
-    ls->log = *clcf->err_log;
+    ls->logp = clcf->error_log;
     ls->log.data = &ls->addr_text;
     ls->log.handler = ngx_accept_log_error;
 
index 825c8395ca0eb547b2616e5d037a5f0838836ce2..4b300dfd5e31b58e58fdcd9c472d4bb06bb8c6c8 100644 (file)
@@ -1292,10 +1292,10 @@ ngx_http_update_location_config(ngx_http_request_t *r)
     }
 
     if (r == r->main) {
-        r->connection->log->file = clcf->err_log->file;
+        r->connection->log->file = clcf->error_log->file;
 
         if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
-            r->connection->log->log_level = clcf->err_log->log_level;
+            r->connection->log->log_level = clcf->error_log->log_level;
         }
     }
 
@@ -2929,7 +2929,7 @@ ngx_http_core_create_loc_conf(ngx_conf_t *cf)
      *     lcf->post_action = { 0, NULL };
      *     lcf->types = NULL;
      *     lcf->default_type = { 0, NULL };
-     *     lcf->err_log = NULL;
+     *     lcf->error_log = NULL;
      *     lcf->error_pages = NULL;
      *     lcf->try_files = NULL;
      *     lcf->client_body_path = NULL;
@@ -3109,11 +3109,11 @@ ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
         }
     }
 
-    if (conf->err_log == NULL) {
-        if (prev->err_log) {
-            conf->err_log = prev->err_log;
+    if (conf->error_log == NULL) {
+        if (prev->error_log) {
+            conf->error_log = prev->error_log;
         } else {
-            conf->err_log = cf->cycle->new_log;
+            conf->error_log = &cf->cycle->new_log;
         }
     }
 
@@ -4104,14 +4104,23 @@ ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 
     ngx_str_t  *value;
 
+    if (lcf->error_log) {
+        return "is duplicate";
+    }
+
     value = cf->args->elts;
 
-    lcf->err_log = ngx_log_create_errlog(cf->cycle, &value[1]);
-    if (lcf->err_log == NULL) {
+    lcf->error_log = ngx_log_create(cf->cycle, &value[1]);
+    if (lcf->error_log == NULL) {
         return NGX_CONF_ERROR;
     }
 
-    return ngx_set_error_log_levels(cf, lcf->err_log);
+    if (cf->args->nelts == 2) {
+        lcf->error_log->log_level = NGX_LOG_ERR;
+        return NGX_CONF_OK;
+    }
+
+    return ngx_log_set_levels(cf, lcf->error_log);
 }
 
 
index 546ebbb563ce8a4c6b53835708767740aecce416..2c4e45acd2da5260654552ec05a306d9ac822fb0 100644 (file)
@@ -377,7 +377,7 @@ struct ngx_http_core_loc_conf_s {
     ngx_flag_t    open_file_cache_errors;
     ngx_flag_t    open_file_cache_events;
 
-    ngx_log_t    *err_log;
+    ngx_log_t    *error_log;
 
     ngx_uint_t    types_hash_max_size;
     ngx_uint_t    types_hash_bucket_size;
index d06c6dd3fb9c957f824a7665fe25ff77a19b4e40..9cdd92ddd59f7e479b7f1aed4a72a837fba494a0 100644 (file)
@@ -420,9 +420,9 @@ ngx_http_init_request(ngx_event_t *rev)
 #endif
 
     clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-    c->log->file = clcf->err_log->file;
+    c->log->file = clcf->error_log->file;
     if (!(c->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
-        c->log->log_level = clcf->err_log->log_level;
+        c->log->log_level = clcf->error_log->log_level;
     }
 
     if (c->buffer == NULL) {
@@ -1704,10 +1704,10 @@ found:
     r->loc_conf = cscf->ctx->loc_conf;
 
     clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-    r->connection->log->file = clcf->err_log->file;
+    r->connection->log->file = clcf->error_log->file;
 
     if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
-        r->connection->log->log_level = clcf->err_log->log_level;
+        r->connection->log->log_level = clcf->error_log->log_level;
     }
 
     return NGX_OK;
index aa77364dedfb38a7f4490fa96fb73b7c600cc3a5..1d6b78bdd40c95a9f67526a683560f2157fc93be 100644 (file)
@@ -313,11 +313,10 @@ ngx_mail_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
             ls->handler = ngx_mail_init_connection;
             ls->pool_size = 256;
 
-            /* STUB */
-            ls->log = *cf->cycle->new_log;
+            /* TODO: error_log directive */
+            ls->logp = &cf->cycle->new_log;
             ls->log.data = &ls->addr_text;
             ls->log.handler = ngx_accept_log_error;
-            /**/
 
             imip = ngx_palloc(cf->pool, sizeof(ngx_mail_in_port_t));
             if (imip == NULL) {