comparison src/core/ngx_conf_file.c @ 422:88d3e895bdf9 NGINX_0_7_23

nginx 0.7.23 *) Feature: the "delete" and "ranges" parameters in the "geo" directive. *) Feature: speeding up loading of geo base with large number of values. *) Feature: decrease of memory required for geo base load.
author Igor Sysoev <http://sysoev.ru>
date Thu, 27 Nov 2008 00:00:00 +0300
parents ff86d646f9df
children a8424ffa495c
comparison
equal deleted inserted replaced
421:10e4013f5f54 422:88d3e895bdf9
96 ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) 96 ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
97 { 97 {
98 char *rv; 98 char *rv;
99 ngx_fd_t fd; 99 ngx_fd_t fd;
100 ngx_int_t rc; 100 ngx_int_t rc;
101 ngx_buf_t *b; 101 ngx_buf_t buf;
102 ngx_conf_file_t *prev; 102 ngx_conf_file_t *prev, conf_file;
103 enum { 103 enum {
104 parse_file = 0, 104 parse_file = 0,
105 parse_block, 105 parse_block,
106 parse_param 106 parse_param
107 } type; 107 } type;
123 return NGX_CONF_ERROR; 123 return NGX_CONF_ERROR;
124 } 124 }
125 125
126 prev = cf->conf_file; 126 prev = cf->conf_file;
127 127
128 cf->conf_file = ngx_palloc(cf->pool, sizeof(ngx_conf_file_t)); 128 cf->conf_file = &conf_file;
129 if (cf->conf_file == NULL) {
130 return NGX_CONF_ERROR;
131 }
132 129
133 if (ngx_fd_info(fd, &cf->conf_file->file.info) == -1) { 130 if (ngx_fd_info(fd, &cf->conf_file->file.info) == -1) {
134 ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, 131 ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno,
135 ngx_fd_info_n " \"%s\" failed", filename->data); 132 ngx_fd_info_n " \"%s\" failed", filename->data);
136 } 133 }
137 134
138 b = ngx_calloc_buf(cf->pool); 135 cf->conf_file->buffer = &buf;
139 if (b == NULL) { 136
140 return NGX_CONF_ERROR; 137 buf.start = ngx_alloc(NGX_CONF_BUFFER, cf->log);
141 } 138 if (buf.start == NULL) {
142 139 goto failed;
143 cf->conf_file->buffer = b; 140 }
144 141
145 b->start = ngx_alloc(NGX_CONF_BUFFER, cf->log); 142 buf.pos = buf.start;
146 if (b->start == NULL) { 143 buf.last = buf.start;
147 return NGX_CONF_ERROR; 144 buf.end = buf.last + NGX_CONF_BUFFER;
148 } 145 buf.temporary = 1;
149
150 b->pos = b->start;
151 b->last = b->start;
152 b->end = b->last + NGX_CONF_BUFFER;
153 b->temporary = 1;
154 146
155 cf->conf_file->file.fd = fd; 147 cf->conf_file->file.fd = fd;
156 cf->conf_file->file.name.len = filename->len; 148 cf->conf_file->file.name.len = filename->len;
157 cf->conf_file->file.name.data = filename->data; 149 cf->conf_file->file.name.data = filename->data;
158 cf->conf_file->file.offset = 0; 150 cf->conf_file->file.offset = 0;
254 rc = NGX_ERROR; 246 rc = NGX_ERROR;
255 247
256 done: 248 done:
257 249
258 if (filename) { 250 if (filename) {
259 ngx_free(cf->conf_file->buffer->start); 251 if (cf->conf_file->buffer->start) {
260 252 ngx_free(cf->conf_file->buffer->start);
261 cf->conf_file = prev; 253 }
262 254
263 if (ngx_close_file(fd) == NGX_FILE_ERROR) { 255 if (ngx_close_file(fd) == NGX_FILE_ERROR) {
264 ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno, 256 ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno,
265 ngx_close_file_n " %s failed", 257 ngx_close_file_n " %s failed",
266 cf->conf_file->file.name.data); 258 cf->conf_file->file.name.data);
267 return NGX_CONF_ERROR; 259 return NGX_CONF_ERROR;
268 } 260 }
261
262 cf->conf_file = prev;
269 } 263 }
270 264
271 if (rc == NGX_ERROR) { 265 if (rc == NGX_ERROR) {
272 return NGX_CONF_ERROR; 266 return NGX_CONF_ERROR;
273 } 267 }
832 } 826 }
833 827
834 name->len = len + old.len; 828 name->len = len + old.len;
835 name->data = ngx_pnalloc(cycle->pool, name->len + 1); 829 name->data = ngx_pnalloc(cycle->pool, name->len + 1);
836 if (name->data == NULL) { 830 if (name->data == NULL) {
837 return NGX_ERROR; 831 return NGX_ERROR;
838 } 832 }
839 833
840 p = ngx_cpymem(name->data, prefix, len); 834 p = ngx_cpymem(name->data, prefix, len);
841 ngx_cpystrn(p, old.data, old.len + 1); 835 ngx_cpystrn(p, old.data, old.len + 1);
842 836
957 951
958 void ngx_cdecl 952 void ngx_cdecl
959 ngx_conf_log_error(ngx_uint_t level, ngx_conf_t *cf, ngx_err_t err, 953 ngx_conf_log_error(ngx_uint_t level, ngx_conf_t *cf, ngx_err_t err,
960 char *fmt, ...) 954 char *fmt, ...)
961 { 955 {
962 u_char errstr[NGX_MAX_CONF_ERRSTR], *buf, *last; 956 u_char errstr[NGX_MAX_CONF_ERRSTR], *p, *last;
963 va_list args; 957 va_list args;
964 958
965 last = errstr + NGX_MAX_CONF_ERRSTR; 959 last = errstr + NGX_MAX_CONF_ERRSTR;
966 960
967 va_start(args, fmt); 961 va_start(args, fmt);
968 buf = ngx_vsnprintf(errstr, last - errstr, fmt, args); 962 p = ngx_vsnprintf(errstr, last - errstr, fmt, args);
969 va_end(args); 963 va_end(args);
970 964
971 *buf = '\0';
972
973 if (err) { 965 if (err) {
974 buf = ngx_snprintf(buf, last - buf - 1, " (%d: ", err); 966
975 buf = ngx_strerror_r(err, buf, last - buf - 1); 967 if (p > last - 50) {
976 *buf++ = ')'; 968
977 *buf = '\0'; 969 /* leave a space for an error code */
970
971 p = last - 50;
972 *p++ = '.';
973 *p++ = '.';
974 *p++ = '.';
975 }
976
977 #if (NGX_WIN32)
978 p = ngx_snprintf(p, last - p, ((unsigned) err < 0x80000000)
979 ? " (%d: " : " (%Xd: ", err);
980 #else
981 p = ngx_snprintf(p, last - p, " (%d: ", err);
982 #endif
983
984 p = ngx_strerror_r(err, p, last - p);
985
986 *p++ = ')';
978 } 987 }
979 988
980 if (cf->conf_file == NULL) { 989 if (cf->conf_file == NULL) {
981 ngx_log_error(level, cf->log, 0, "%s", errstr); 990 ngx_log_error(level, cf->log, 0, "%*s", p - errstr, errstr);
982 return; 991 return;
983 } 992 }
984 993
985 ngx_log_error(level, cf->log, 0, "%s in %s:%ui", 994 ngx_log_error(level, cf->log, 0, "%*s in %s:%ui",
986 errstr, cf->conf_file->file.name.data, cf->conf_file->line); 995 p - errstr, errstr,
996 cf->conf_file->file.name.data, cf->conf_file->line);
987 } 997 }
988 998
989 999
990 char * 1000 char *
991 ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 1001 ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)