diff 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
line wrap: on
line diff
--- a/src/core/ngx_conf_file.c
+++ b/src/core/ngx_conf_file.c
@@ -98,8 +98,8 @@ ngx_conf_parse(ngx_conf_t *cf, ngx_str_t
     char             *rv;
     ngx_fd_t          fd;
     ngx_int_t         rc;
-    ngx_buf_t        *b;
-    ngx_conf_file_t  *prev;
+    ngx_buf_t         buf;
+    ngx_conf_file_t  *prev, conf_file;
     enum {
         parse_file = 0,
         parse_block,
@@ -125,32 +125,24 @@ ngx_conf_parse(ngx_conf_t *cf, ngx_str_t
 
         prev = cf->conf_file;
 
-        cf->conf_file = ngx_palloc(cf->pool, sizeof(ngx_conf_file_t));
-        if (cf->conf_file == NULL) {
-            return NGX_CONF_ERROR;
-        }
+        cf->conf_file = &conf_file;
 
         if (ngx_fd_info(fd, &cf->conf_file->file.info) == -1) {
             ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno,
                           ngx_fd_info_n " \"%s\" failed", filename->data);
         }
 
-        b = ngx_calloc_buf(cf->pool);
-        if (b == NULL) {
-            return NGX_CONF_ERROR;
+        cf->conf_file->buffer = &buf;
+
+        buf.start = ngx_alloc(NGX_CONF_BUFFER, cf->log);
+        if (buf.start == NULL) {
+            goto failed;
         }
 
-        cf->conf_file->buffer = b;
-
-        b->start = ngx_alloc(NGX_CONF_BUFFER, cf->log);
-        if (b->start == NULL) {
-            return NGX_CONF_ERROR;
-        }
-
-        b->pos = b->start;
-        b->last = b->start;
-        b->end = b->last + NGX_CONF_BUFFER;
-        b->temporary = 1;
+        buf.pos = buf.start;
+        buf.last = buf.start;
+        buf.end = buf.last + NGX_CONF_BUFFER;
+        buf.temporary = 1;
 
         cf->conf_file->file.fd = fd;
         cf->conf_file->file.name.len = filename->len;
@@ -256,9 +248,9 @@ failed:
 done:
 
     if (filename) {
-        ngx_free(cf->conf_file->buffer->start);
-
-        cf->conf_file = prev;
+        if (cf->conf_file->buffer->start) {
+            ngx_free(cf->conf_file->buffer->start);
+        }
 
         if (ngx_close_file(fd) == NGX_FILE_ERROR) {
             ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno,
@@ -266,6 +258,8 @@ done:
                           cf->conf_file->file.name.data);
             return NGX_CONF_ERROR;
         }
+
+        cf->conf_file = prev;
     }
 
     if (rc == NGX_ERROR) {
@@ -834,7 +828,7 @@ ngx_conf_full_name(ngx_cycle_t *cycle, n
     name->len = len + old.len;
     name->data = ngx_pnalloc(cycle->pool, name->len + 1);
     if (name->data == NULL) {
-        return  NGX_ERROR;
+        return NGX_ERROR;
     }
 
     p = ngx_cpymem(name->data, prefix, len);
@@ -959,31 +953,47 @@ void ngx_cdecl
 ngx_conf_log_error(ngx_uint_t level, ngx_conf_t *cf, ngx_err_t err,
     char *fmt, ...)
 {
-    u_char   errstr[NGX_MAX_CONF_ERRSTR], *buf, *last;
+    u_char   errstr[NGX_MAX_CONF_ERRSTR], *p, *last;
     va_list  args;
 
     last = errstr + NGX_MAX_CONF_ERRSTR;
 
     va_start(args, fmt);
-    buf = ngx_vsnprintf(errstr, last - errstr, fmt, args);
+    p = ngx_vsnprintf(errstr, last - errstr, fmt, args);
     va_end(args);
 
-    *buf = '\0';
+    if (err) {
+
+        if (p > last - 50) {
+
+            /* leave a space for an error code */
 
-    if (err) {
-        buf = ngx_snprintf(buf, last - buf - 1, " (%d: ", err);
-        buf = ngx_strerror_r(err, buf, last - buf - 1);
-        *buf++ = ')';
-        *buf = '\0';
+            p = last - 50;
+            *p++ = '.';
+            *p++ = '.';
+            *p++ = '.';
+        }
+
+#if (NGX_WIN32)
+        p = ngx_snprintf(p, last - p, ((unsigned) err < 0x80000000)
+                                           ? " (%d: " : " (%Xd: ", err);
+#else
+        p = ngx_snprintf(p, last - p, " (%d: ", err);
+#endif
+
+        p = ngx_strerror_r(err, p, last - p);
+
+        *p++ = ')';
     }
 
     if (cf->conf_file == NULL) {
-        ngx_log_error(level, cf->log, 0, "%s", errstr);
+        ngx_log_error(level, cf->log, 0, "%*s", p - errstr, errstr);
         return;
     }
 
-    ngx_log_error(level, cf->log, 0, "%s in %s:%ui",
-                  errstr, cf->conf_file->file.name.data, cf->conf_file->line);
+    ngx_log_error(level, cf->log, 0, "%*s in %s:%ui",
+                  p - errstr, errstr,
+                  cf->conf_file->file.name.data, cf->conf_file->line);
 }