ПРОЕКТЫ 


  АРХИВ 


Apache-Talk @lexa.ru 

Inet-Admins @info.east.ru 

Filmscanners @halftone.co.uk 

Security-alerts @yandex-team.ru 

nginx-ru @sysoev.ru 


  СТАТЬИ 


  ПЕРСОНАЛЬНОЕ 


  ПРОГРАММЫ 



ПИШИТЕ
ПИСЬМА












     АРХИВ :: nginx-ru
Nginx-ru mailing list archive (nginx-ru@sysoev.ru)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: фича реквест



2010/9/26 Kirill A. Korinskiy <catap@xxxxxxxx>
2010/9/25 Igor Sysoev <igor@xxxxxxxxx>

On Sat, Sep 25, 2010 at 02:37:26PM +0300, Vladislav V. Prodan wrote:

> 25.09.2010 12:57, Igor Sysoev пишет:
> > On Fri, Sep 24, 2010 at 10:55:20PM +0300, Vladislav V. Prodan wrote:
> >
> >>    Enable debug log (--with-debug)
> >
> > Ставим для error_log уровень info и выше.
> >
> >
>
> не помогает.
> ставлю info и весь [debug] по-прежнему сыпется в логи...

Обычно помогает такое:
nginx -t
grep error_log nginx.conf


Либо наложите патч из attach и запустите nginx с опцией -d, и посмотрите, и посмотрите где ставится log.

Кстати, если кому-то надо, можно этот патч переделать для отдачи конфига по http...


Забыл приложить патч. 


--
wbr, Kirill

diff --git a/src/core/nginx.c b/src/core/nginx.c
index 62cea75..bcba8d6 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -186,6 +186,7 @@ ngx_uint_t          ngx_max_module;
 static ngx_uint_t   ngx_show_help;
 static ngx_uint_t   ngx_show_version;
 static ngx_uint_t   ngx_show_configure;
+static ngx_uint_t   ngx_show_config;
 static u_char      *ngx_prefix;
 static u_char      *ngx_conf_file;
 static u_char      *ngx_conf_params;
@@ -220,6 +221,7 @@ main(int argc, char *const *argv)
                 "  -V            : show version and configure options then 
exit"
                                    CRLF
                 "  -t            : test configuration and exit" CRLF
+                "  -d            : dump configuration and exit" CRLF
                 "  -q            : suppress non-error messages "
                                    "during configuration testing" CRLF
                 "  -s signal     : send signal to a master process: "
@@ -342,6 +344,12 @@ main(int argc, char *const *argv)
         return 0;
     }
 
+    if (ngx_show_config) {
+        ngx_conf_dump(cycle);
+
+        return 0;
+    }
+
     if (ngx_signal) {
         return ngx_signal_process(cycle, ngx_signal);
     }
@@ -690,6 +698,10 @@ ngx_get_options(int argc, char *const *argv)
                 ngx_test_config = 1;
                 break;
 
+            case 'd':
+                ngx_show_config = 1;
+                break;
+
             case 'q':
                 ngx_quiet_mode = 1;
                 break;
diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c
index 83c1073..b63c437 100644
--- a/src/core/ngx_conf_file.c
+++ b/src/core/ngx_conf_file.c
@@ -435,12 +435,15 @@ ngx_conf_read_token(ngx_conf_t *cf)
 {
     u_char      *start, ch, *src, *dst;
     off_t        file_size;
-    size_t       len;
+    size_t       i, len;
     ssize_t      n, size;
     ngx_uint_t   found, need_space, last_space, sharp_comment, variable;
     ngx_uint_t   quoted, s_quoted, d_quoted, start_line;
-    ngx_str_t   *word;
+    ngx_str_t   *word, *w;
     ngx_buf_t   *b;
+    ngx_int_t    ret;
+
+    ngx_conf_dump_elm_t *delm;
 
     found = 0;
     need_space = 0;
@@ -470,16 +473,19 @@ ngx_conf_read_token(ngx_conf_t *cf)
                         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                                            "unexpected end of parameter, "
                                            "expecting \";\"");
-                        return NGX_ERROR;
+                        ret = NGX_ERROR;
+                        goto out;
                     }
 
                     ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                                   "unexpected end of file, "
                                   "expecting \";\" or \"}\"");
-                    return NGX_ERROR;
+                    ret = NGX_ERROR;
+                    goto out;
                 }
 
-                return NGX_CONF_FILE_DONE;
+                ret = NGX_CONF_FILE_DONE;
+                goto out;
             }
 
             len = b->pos - start;
@@ -497,13 +503,15 @@ ngx_conf_read_token(ngx_conf_t *cf)
                     ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                                        "too long parameter \"%*s...\" started",
                                        10, start);
-                    return NGX_ERROR;
+                    ret = NGX_ERROR;
+                    goto out;
                 }
 
                 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                                    "too long parameter, probably "
                                    "missing terminating \"%c\" character", ch);
-                return NGX_ERROR;
+                ret = NGX_ERROR;
+                goto out;
             }
 
             if (len) {
@@ -520,7 +528,8 @@ ngx_conf_read_token(ngx_conf_t *cf)
                               cf->conf_file->file.offset);
 
             if (n == NGX_ERROR) {
-                return NGX_ERROR;
+                ret = NGX_ERROR;
+                goto out;
             }
 
             if (n != size) {
@@ -528,7 +537,8 @@ ngx_conf_read_token(ngx_conf_t *cf)
                                    ngx_read_file_n " returned "
                                    "only %z bytes instead of %z",
                                    n, size);
-                return NGX_ERROR;
+                ret = NGX_ERROR;
+                goto out;
             }
 
             b->pos = b->start + len;
@@ -563,11 +573,13 @@ ngx_conf_read_token(ngx_conf_t *cf)
             }
 
             if (ch == ';') {
-                return NGX_OK;
+                ret = NGX_OK;
+                goto out;
             }
 
             if (ch == '{') {
-                return NGX_CONF_BLOCK_START;
+                ret = NGX_CONF_BLOCK_START;
+                goto out;
             }
 
             if (ch == ')') {
@@ -577,7 +589,8 @@ ngx_conf_read_token(ngx_conf_t *cf)
             } else {
                  ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                                     "unexpected \"%c\"", ch);
-                 return NGX_ERROR;
+                 ret = NGX_ERROR;
+                 goto out;
             }
         }
 
@@ -596,23 +609,28 @@ ngx_conf_read_token(ngx_conf_t *cf)
                 if (cf->args->nelts == 0) {
                     ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                                        "unexpected \"%c\"", ch);
-                    return NGX_ERROR;
+                    ret = NGX_ERROR;
+                    goto out;
                 }
 
                 if (ch == '{') {
-                    return NGX_CONF_BLOCK_START;
+                    ret = NGX_CONF_BLOCK_START;
+                    goto out;
                 }
 
-                return NGX_OK;
+                ret = NGX_OK;
+                goto out;
 
             case '}':
                 if (cf->args->nelts != 0) {
                     ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                                        "unexpected \"}\"");
-                    return NGX_ERROR;
+                    ret = NGX_ERROR;
+                    goto out;
                 }
 
-                return NGX_CONF_BLOCK_DONE;
+                ret = NGX_CONF_BLOCK_DONE;
+                goto out;
 
             case '#':
                 sharp_comment = 1;
@@ -680,12 +698,14 @@ ngx_conf_read_token(ngx_conf_t *cf)
             if (found) {
                 word = ngx_array_push(cf->args);
                 if (word == NULL) {
-                    return NGX_ERROR;
+                    ret = NGX_ERROR;
+                    goto out;
                 }
 
                 word->data = ngx_pnalloc(cf->pool, b->pos - start + 1);
                 if (word->data == NULL) {
-                    return NGX_ERROR;
+                    ret = NGX_ERROR;
+                    goto out;
                 }
 
                 for (dst = word->data, src = start, len = 0;
@@ -723,17 +743,65 @@ ngx_conf_read_token(ngx_conf_t *cf)
                 word->len = len;
 
                 if (ch == ';') {
-                    return NGX_OK;
+                    ret = NGX_OK;
+                    goto out;
                 }
 
                 if (ch == '{') {
-                    return NGX_CONF_BLOCK_START;
+                    ret = NGX_CONF_BLOCK_START;
+                    goto out;
                 }
 
                 found = 0;
             }
         }
     }
+
+out:
+    if (ret == NGX_ERROR ||
+       (ret != NGX_CONF_BLOCK_DONE &&
+        !cf->args->nelts)) {
+        return ret;
+    }
+
+    delm = ngx_list_push(&cf->cycle->conf_dump);
+
+    if (ret == NGX_CONF_BLOCK_START) {
+        delm->type = dump_elm_start_block;
+    } else if (ret == NGX_CONF_BLOCK_DONE) {
+        delm->type = dump_elm_end_block;
+    } else if (ret == NGX_OK) {
+        delm->type = dump_elm_param;
+    }
+
+    if (cf->args->nelts > 0) {
+        if (ngx_array_init(&delm->args, cf->cycle->pool,
+                           cf->args->nelts, sizeof(ngx_str_t))
+            != NGX_OK) {
+            return NGX_ERROR;
+        }
+
+        for (i = 0; i < cf->args->nelts; i++) {
+            word = &(((ngx_str_t*)cf->args->elts)[i]);
+
+            if (word->len) {
+                w = ngx_array_push(&delm->args);
+                if (w == NULL) {
+                    return NGX_ERROR;
+                }
+
+                w->len = word->len;
+                w->data = ngx_pnalloc(cf->cycle->dump_pool, w->len);
+                if (w->data == NULL) {
+                    return NGX_ERROR;
+                }
+
+                ngx_memcpy(w->data, word->data, w->len);
+            }
+        }
+    }
+
+    return ret;
 }
 
 
@@ -1503,3 +1571,60 @@ ngx_conf_check_num_bounds(ngx_conf_t *cf, void *post, 
void *data)
 
     return NGX_CONF_ERROR;
 }
+
+
+void ngx_conf_dump(ngx_cycle_t *cycle)
+{
+    size_t               deep = 0;
+    ngx_str_t           *word;
+    ngx_uint_t           i, j;
+    ngx_list_part_t     *part;
+    ngx_conf_dump_elm_t *delm;
+
+    part = &cycle->conf_dump.part;
+    delm = part->elts;
+
+    for (i = 0 ;;i++) {
+        if (i >= part->nelts) {
+            if (part->next == NULL) {
+                break;
+            }
+
+            part = part->next;
+            delm = part->elts;
+            i = 0;
+        }
+
+       if (delm[i].args.nelts) {
+           for (j = 0; j < deep; j++) {
+               ngx_write_console(ngx_stdout, "  ", 2);
+           }
+       }
+
+       word = (ngx_str_t *)delm[i].args.elts;
+       for (j = 0; j < delm[i].args.nelts; j++) {
+
+           ngx_write_console(ngx_stdout, word[j].data, word[j].len);
+
+           if (j + 1 < delm[i].args.nelts) {
+               ngx_write_console(ngx_stdout, " ", 1);
+           }
+       }
+
+
+       if (delm[i].type == dump_elm_param) {
+           ngx_write_console(ngx_stdout, ";\n", 2);
+
+       } else if (delm[i].type == dump_elm_start_block) {
+           ngx_write_console(ngx_stdout, " {\n", 3);
+           deep++;
+
+       } else if (delm[i].type == dump_elm_end_block) {
+            deep--;
+            for (j = 0; j < deep; j++) {
+                ngx_write_console(ngx_stdout, "  ", 2);
+            }
+            ngx_write_console(ngx_stdout, "}\n", 2);
+        }
+    }
+}
diff --git a/src/core/ngx_conf_file.h b/src/core/ngx_conf_file.h
index 86c60a4..81d87d3 100644
--- a/src/core/ngx_conf_file.h
+++ b/src/core/ngx_conf_file.h
@@ -73,6 +73,9 @@
 
 #define NGX_MAX_CONF_ERRSTR  1024
 
+#ifndef NGX_CONF_DUMP_POOL_SIZE
+#define NGX_CONF_DUMP_POOL_SIZE     16384
+#endif
 
 struct ngx_command_s {
     ngx_str_t             name;
@@ -216,6 +219,16 @@ typedef struct {
     ngx_uint_t                mask;
 } ngx_conf_bitmask_t;
 
+typedef struct {
+    enum {
+        dump_elm_start_block,  /* the token terminated by "{" */
+       dump_elm_end_block,     /* the "}" */
+        dump_elm_param         /* the token terminated by ";" */
+    } type;
+
+    ngx_array_t   args;
+} ngx_conf_dump_elm_t;
+
 
 
 char * ngx_conf_deprecated(ngx_conf_t *cf, void *post, void *data);
@@ -339,6 +352,8 @@ char *ngx_conf_set_bufs_slot(ngx_conf_t *cf, ngx_command_t 
*cmd, void *conf);
 char *ngx_conf_set_enum_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
 char *ngx_conf_set_bitmask_slot(ngx_conf_t *cf, ngx_command_t *cmd, void 
*conf);
 
+void ngx_conf_dump(ngx_cycle_t *cycle);
+
 
 extern ngx_uint_t     ngx_max_module;
 extern ngx_module_t  *ngx_modules[];
diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c
index 357c6b2..9caa785 100644
--- a/src/core/ngx_cycle.c
+++ b/src/core/ngx_cycle.c
@@ -255,6 +255,20 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
     log->log_level = NGX_LOG_DEBUG_ALL;
 #endif
 
+    cycle->dump_pool = ngx_create_pool(NGX_CONF_DUMP_POOL_SIZE, log);
+    if (cycle->dump_pool == NULL) {
+        ngx_destroy_pool(pool);
+        ngx_destroy_pool(conf.temp_pool);
+        return NULL;
+    }
+
+    if (ngx_list_init(&cycle->conf_dump, cycle->dump_pool, 64,
+                      sizeof(ngx_conf_dump_elm_t))
+        != NGX_OK) {
+        ngx_destroy_cycle_pools(&conf);
+        return NULL;
+    }
+
     if (ngx_conf_param(&conf) != NGX_CONF_OK) {
         environ = senv;
         ngx_destroy_cycle_pools(&conf);
@@ -844,6 +858,8 @@ ngx_destroy_cycle_pools(ngx_conf_t *conf)
 {
     ngx_destroy_pool(conf->temp_pool);
     ngx_destroy_pool(conf->pool);
+    ngx_destroy_pool(conf->cycle->pool);
+    ngx_destroy_pool(conf->cycle->dump_pool);
 }
 
 
diff --git a/src/core/ngx_cycle.h b/src/core/ngx_cycle.h
index 3f2e222..a24b5b6 100644
--- a/src/core/ngx_cycle.h
+++ b/src/core/ngx_cycle.h
@@ -36,6 +36,7 @@ struct ngx_shm_zone_s {
 struct ngx_cycle_s {
     void                  ****conf_ctx;
     ngx_pool_t               *pool;
+    ngx_pool_t               *dump_pool;
 
     ngx_log_t                *log;
     ngx_log_t                 new_log;
@@ -61,6 +62,7 @@ struct ngx_cycle_s {
     ngx_str_t                 conf_file;
     ngx_str_t                 conf_param;
     ngx_str_t                 conf_prefix;
+    ngx_list_t                conf_dump;
     ngx_str_t                 prefix;
     ngx_str_t                 lock_file;
     ngx_str_t                 hostname;
diff --git a/src/os/unix/ngx_files.h b/src/os/unix/ngx_files.h
index b7bfff1..0c84672 100644
--- a/src/os/unix/ngx_files.h
+++ b/src/os/unix/ngx_files.h
@@ -324,6 +324,8 @@ size_t ngx_fs_bsize(u_char *name);
 #define ngx_set_stderr(fd)       dup2(fd, STDERR_FILENO)
 #define ngx_set_stderr_n         "dup2(STDERR_FILENO)"
 
+#define ngx_stdout               STDOUT_FILENO
+
 
 #if (NGX_HAVE_FILE_AIO)
 
_______________________________________________
nginx-ru mailing list
nginx-ru@xxxxxxxxx
http://nginx.org/mailman/listinfo/nginx-ru


 




Copyright © Lexa Software, 1996-2009.