comparison src/core/ngx_conf_file.c @ 6187:1b7e246e6b38

Core: store and dump processed configuration. If the -T option is passed, additionally to configuration test, configuration files are output to stdout. In the debug mode, configuration files are kept in memory and can be accessed using a debugger.
author Vladimir Homutov <vl@nginx.com>
date Thu, 14 May 2015 18:54:27 +0300
parents 4e71788460fa
children cf5e822cf470
comparison
equal deleted inserted replaced
6186:db138b3b645e 6187:1b7e246e6b38
99 99
100 char * 100 char *
101 ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) 101 ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
102 { 102 {
103 char *rv; 103 char *rv;
104 u_char *p;
105 off_t size;
104 ngx_fd_t fd; 106 ngx_fd_t fd;
105 ngx_int_t rc; 107 ngx_int_t rc;
106 ngx_buf_t buf; 108 ngx_buf_t buf, *tbuf;
107 ngx_conf_file_t *prev, conf_file; 109 ngx_conf_file_t *prev, conf_file;
110 ngx_conf_dump_t *cd;
108 enum { 111 enum {
109 parse_file = 0, 112 parse_file = 0,
110 parse_block, 113 parse_block,
111 parse_param 114 parse_param
112 } type; 115 } type;
155 cf->conf_file->file.offset = 0; 158 cf->conf_file->file.offset = 0;
156 cf->conf_file->file.log = cf->log; 159 cf->conf_file->file.log = cf->log;
157 cf->conf_file->line = 1; 160 cf->conf_file->line = 1;
158 161
159 type = parse_file; 162 type = parse_file;
163
164 if (ngx_dump_config
165 #if (NGX_DEBUG)
166 || 1
167 #endif
168 )
169 {
170 p = ngx_pstrdup(cf->cycle->pool, filename);
171 if (p == NULL) {
172 goto failed;
173 }
174
175 size = ngx_file_size(&cf->conf_file->file.info);
176
177 tbuf = ngx_create_temp_buf(cf->cycle->pool, (size_t) size);
178 if (tbuf == NULL) {
179 goto failed;
180 }
181
182 cd = ngx_array_push(&cf->cycle->config_dump);
183 if (cd == NULL) {
184 goto failed;
185 }
186
187 cd->name.len = filename->len;
188 cd->name.data = p;
189 cd->buffer = tbuf;
190
191 cf->conf_file->dump = tbuf;
192
193 } else {
194 cf->conf_file->dump = NULL;
195 }
160 196
161 } else if (cf->conf_file->file.fd != NGX_INVALID_FILE) { 197 } else if (cf->conf_file->file.fd != NGX_INVALID_FILE) {
162 198
163 type = parse_block; 199 type = parse_block;
164 200
435 size_t len; 471 size_t len;
436 ssize_t n, size; 472 ssize_t n, size;
437 ngx_uint_t found, need_space, last_space, sharp_comment, variable; 473 ngx_uint_t found, need_space, last_space, sharp_comment, variable;
438 ngx_uint_t quoted, s_quoted, d_quoted, start_line; 474 ngx_uint_t quoted, s_quoted, d_quoted, start_line;
439 ngx_str_t *word; 475 ngx_str_t *word;
440 ngx_buf_t *b; 476 ngx_buf_t *b, *dump;
441 477
442 found = 0; 478 found = 0;
443 need_space = 0; 479 need_space = 0;
444 last_space = 1; 480 last_space = 1;
445 sharp_comment = 0; 481 sharp_comment = 0;
448 s_quoted = 0; 484 s_quoted = 0;
449 d_quoted = 0; 485 d_quoted = 0;
450 486
451 cf->args->nelts = 0; 487 cf->args->nelts = 0;
452 b = cf->conf_file->buffer; 488 b = cf->conf_file->buffer;
489 dump = cf->conf_file->dump;
453 start = b->pos; 490 start = b->pos;
454 start_line = cf->conf_file->line; 491 start_line = cf->conf_file->line;
455 492
456 file_size = ngx_file_size(&cf->conf_file->file.info); 493 file_size = ngx_file_size(&cf->conf_file->file.info);
457 494
529 } 566 }
530 567
531 b->pos = b->start + len; 568 b->pos = b->start + len;
532 b->last = b->pos + n; 569 b->last = b->pos + n;
533 start = b->start; 570 start = b->start;
571
572 if (dump) {
573 dump->last = ngx_cpymem(dump->last, b->pos, size);
574 }
534 } 575 }
535 576
536 ch = *b->pos++; 577 ch = *b->pos++;
537 578
538 if (ch == LF) { 579 if (ch == LF) {