Mercurial > hg > nginx
comparison src/core/ngx_conf_file.c @ 6776:1bf4f21b1b72
Core: show file contents only once while dumping configuration.
Files are considered the same if the path used by nginx during parsing matches.
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Tue, 18 Oct 2016 16:33:38 +0300 |
parents | 9cf2dce316e5 |
children | 577628e6b6a6 |
comparison
equal
deleted
inserted
replaced
6775:8081e1f3ab8b | 6776:1bf4f21b1b72 |
---|---|
8 #include <ngx_config.h> | 8 #include <ngx_config.h> |
9 #include <ngx_core.h> | 9 #include <ngx_core.h> |
10 | 10 |
11 #define NGX_CONF_BUFFER 4096 | 11 #define NGX_CONF_BUFFER 4096 |
12 | 12 |
13 static ngx_int_t ngx_conf_add_dump(ngx_conf_t *cf, ngx_str_t *filename); | |
13 static ngx_int_t ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last); | 14 static ngx_int_t ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last); |
14 static ngx_int_t ngx_conf_read_token(ngx_conf_t *cf); | 15 static ngx_int_t ngx_conf_read_token(ngx_conf_t *cf); |
15 static void ngx_conf_flush_files(ngx_cycle_t *cycle); | 16 static void ngx_conf_flush_files(ngx_cycle_t *cycle); |
16 | 17 |
17 | 18 |
95 | 96 |
96 return rv; | 97 return rv; |
97 } | 98 } |
98 | 99 |
99 | 100 |
101 static ngx_int_t | |
102 ngx_conf_add_dump(ngx_conf_t *cf, ngx_str_t *filename) | |
103 { | |
104 off_t size; | |
105 u_char *p; | |
106 uint32_t hash; | |
107 ngx_buf_t *buf; | |
108 ngx_str_node_t *sn; | |
109 ngx_conf_dump_t *cd; | |
110 | |
111 hash = ngx_crc32_long(filename->data, filename->len); | |
112 | |
113 sn = ngx_str_rbtree_lookup(&cf->cycle->config_dump_rbtree, filename, hash); | |
114 | |
115 if (sn) { | |
116 cf->conf_file->dump = NULL; | |
117 return NGX_OK; | |
118 } | |
119 | |
120 p = ngx_pstrdup(cf->cycle->pool, filename); | |
121 if (p == NULL) { | |
122 return NGX_ERROR; | |
123 } | |
124 | |
125 cd = ngx_array_push(&cf->cycle->config_dump); | |
126 if (cd == NULL) { | |
127 return NGX_ERROR; | |
128 } | |
129 | |
130 size = ngx_file_size(&cf->conf_file->file.info); | |
131 | |
132 buf = ngx_create_temp_buf(cf->cycle->pool, (size_t) size); | |
133 if (buf == NULL) { | |
134 return NGX_ERROR; | |
135 } | |
136 | |
137 cd->name.data = p; | |
138 cd->name.len = filename->len; | |
139 cd->buffer = buf; | |
140 | |
141 cf->conf_file->dump = buf; | |
142 | |
143 sn = ngx_palloc(cf->temp_pool, sizeof(ngx_str_node_t)); | |
144 if (sn == NULL) { | |
145 return NGX_ERROR; | |
146 } | |
147 | |
148 sn->node.key = hash; | |
149 sn->str = cd->name; | |
150 | |
151 ngx_rbtree_insert(&cf->cycle->config_dump_rbtree, &sn->node); | |
152 | |
153 return NGX_OK; | |
154 } | |
155 | |
156 | |
100 char * | 157 char * |
101 ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) | 158 ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) |
102 { | 159 { |
103 char *rv; | 160 char *rv; |
104 u_char *p; | |
105 off_t size; | |
106 ngx_fd_t fd; | 161 ngx_fd_t fd; |
107 ngx_int_t rc; | 162 ngx_int_t rc; |
108 ngx_buf_t buf, *tbuf; | 163 ngx_buf_t buf; |
109 ngx_conf_file_t *prev, conf_file; | 164 ngx_conf_file_t *prev, conf_file; |
110 ngx_conf_dump_t *cd; | |
111 enum { | 165 enum { |
112 parse_file = 0, | 166 parse_file = 0, |
113 parse_block, | 167 parse_block, |
114 parse_param | 168 parse_param |
115 } type; | 169 } type; |
165 #if (NGX_DEBUG) | 219 #if (NGX_DEBUG) |
166 || 1 | 220 || 1 |
167 #endif | 221 #endif |
168 ) | 222 ) |
169 { | 223 { |
170 p = ngx_pstrdup(cf->cycle->pool, filename); | 224 if (ngx_conf_add_dump(cf, filename) != NGX_OK) { |
171 if (p == NULL) { | |
172 goto failed; | 225 goto failed; |
173 } | 226 } |
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 | 227 |
193 } else { | 228 } else { |
194 cf->conf_file->dump = NULL; | 229 cf->conf_file->dump = NULL; |
195 } | 230 } |
196 | 231 |