[prev in list] [next in list] [prev in thread] [next in thread] 

List:       nginx
Subject:    Re: [Patch] add -p option to override prefix
From:       Jérôme Loyet <jerome () loyet ! net>
Date:       2009-03-31 20:34:51
Message-ID: 3bea96c40903311334h6d1952faw54e7a60239f3ccbe () mail ! gmail ! com
[Download RAW message or body]

2009/3/26 Igor Sysoev <is@rambler-co.ru>:
> On Thu, Mar 26, 2009 at 01:27:21PM +0100, J?r?me Loyet wrote:
>
>> > the previous patch (nginx-prefix-v2.patch) has to be applied after the
>> > first one.
>> >
>> > I attach here the full patch.
>> >
>> > ++ jerome
>>
>> In my path I use ngx_snprintf with "%s%s" but it seems not to work, I
>> have overflows using this function.
>>
>> I add tow logs to check the string content:
>> 2009/03/26 11:56:34 [notice] 22943#0: pid file: ./logs/nginx.pid appq
>> 2009/03/26 11:56:34 [notice] 22943#0: lock file: ./logs/nginx.lock =A0 Y
>>
>> The function ngx_s(n)printf does not work with "%s%s".
>> If I use sprintf instead, it works well. I was sure that ngx_sprintf
>> was an alias to sprintf it's but not. Why are those kind of basic
>> functions have been recoded ? Is there a reason not to use sprintf ?
>
> ngx_s(n)printf() does not add the trailing zero as nginx does not need
> it in general. Therefore instead of
>
> =A0 =A0 =A0 =A0 =A0 =A0ngx_snprintf(ccf->pid.data, ccf->pid.len, "%s%s",
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 cycle->root.data, NGX_PRE=
FIX_PID_PATH);
>
> you need
>
> =A0 =A0 =A0 =A0 =A0 =A0ngx_sprintf(ccf->pid.data, "%V%s%Z",
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0&cycle->root, NGX_PREFIX_P=
ID_PATH);
>
> As to reasons not to use sprintf(), it has no formats even for
> builtin types such as time_t, off_t, pid_t, rlim_t. And I do not want
> to convert them to "long long", since on 32-bit platforms %lld format
> calls procedures just for division and module, where simple
> CPU division/module opcode are enough. Besides, ngx_s(n)printf() supports
> some nginx types such as ngx_str_t.
>

Thanks you for the answer. It makes sense now :)
So here is the last version of the patch (for 0.7.46). ngx_sprintf are
handled correctly and I change a little something which was not great.

Before, I used the RUNTIME_PREFIX as a prefix for anything (pid, lock,
error_log, http log, include, ...). It's still the same but for the
include directive. Now there is a NGX_PREFIX_CONF_PREFIX in
auto/options which has the value "conf". And when include are used,
path are relative to "RUNTIME_PREFIX/NGX_PREFIX_CONF_PREFIX" (instead
of . RUNTIME_PREFIX before). This makes the patch working with the
default nginx.conf file.

All include are relative to RUNTIME_PREFIX except for the include
directives (and others relative to conf) which are relative to
RUNTIME_PREFIX/conf by default.

I made few tests but not so much.

++ Jerome

["nginx-prefix-v2.patch" (application/octet-stream)]

--- configure.orig	2009-03-30 22:13:28.000000000 +0200
+++ configure	2009-03-30 22:15:12.000000000 +0200
@@ -86,4 +86,14 @@
 have=NGX_USER value="\"$NGX_USER\"" . auto/define
 have=NGX_GROUP value="\"$NGX_GROUP\"" . auto/define
 
+have=NGX_PREFIX_CONF_PATH value="\"$NGX_PREFIX_CONF_PATH\"" . auto/define
+have=NGX_PREFIX_CONF_PREFIX value="\"$NGX_PREFIX_CONF_PREFIX\"" . auto/define
+have=NGX_PREFIX_HTTP_CLIENT_TEMP_PATH value="\"$NGX_PREFIX_HTTP_CLIENT_TEMP_PATH\"" . auto/define
+have=NGX_PREFIX_HTTP_PROXY_TEMP_PATH value="\"$NGX_PREFIX_HTTP_PROXY_TEMP_PATH\"" . auto/define
+have=NGX_PREFIX_HTTP_FASTCGI_TEMP_PATH value="\"$NGX_PREFIX_HTTP_FASTCGI_TEMP_PATH\"" . auto/define
+have=NGX_PREFIX_ERROR_LOG_PATH value="\"$NGX_PREFIX_ERROR_LOG_PATH\"" . auto/define
+have=NGX_PREFIX_HTTP_LOG_PATH value="\"$NGX_PREFIX_HTTP_LOG_PATH\"" . auto/define
+have=NGX_PREFIX_PID_PATH value="\"$NGX_PREFIX_PID_PATH\"" . auto/define
+have=NGX_PREFIX_LOCK_PATH value="\"$NGX_PREFIX_LOCK_PATH\"" . auto/define
+
 . auto/summary
--- auto/options.orig	2009-03-30 22:13:28.000000000 +0200
+++ auto/options	2009-03-30 22:15:12.000000000 +0200
@@ -14,6 +14,12 @@
 NGX_USER=
 NGX_GROUP=
 
+NGX_PREFIX_CONF_PREFIX=conf
+NGX_PREFIX_CONF_PATH=$NGX_PREFIX_CONF_PREFIX/nginx.conf
+NGX_PREFIX_ERROR_LOG_PATH=logs/error.log
+NGX_PREFIX_PID_PATH=logs/nginx.pid
+NGX_PREFIX_LOCK_PATH=logs/nginx.lock
+
 CC=${CC:-gcc}
 CPP=
 NGX_OBJS=objs
@@ -52,6 +58,11 @@
 NGX_HTTP_PROXY_TEMP_PATH=
 NGX_HTTP_FASTCGI_TEMP_PATH=
 
+NGX_PREFIX_HTTP_CLIENT_TEMP_PATH=client_body_temp
+NGX_PREFIX_HTTP_PROXY_TEMP_PATH=proxy_temp
+NGX_PREFIX_HTTP_FASTCGI_TEMP_PATH=proxy_temp
+NGX_PREFIX_HTTP_LOG_PATH=logs/access.log
+
 HTTP_CACHE=YES
 HTTP_CHARSET=YES
 HTTP_GZIP=YES
@@ -431,7 +442,7 @@
     ;;
 
     .)
-        NGX_CONF_PATH=$NGX_PREFIX/conf/nginx.conf
+        NGX_CONF_PATH=$NGX_PREFIX/$NGX_PREFIX_CONF_PATH
     ;;
 
     *)
@@ -448,7 +459,7 @@
     ;;
 
     .)
-        NGX_PID_PATH=$NGX_PREFIX/logs/nginx.pid
+        NGX_PID_PATH=$NGX_PREFIX/$NGX_PREFIX_PID_PATH
     ;;
 
     *)
@@ -462,7 +473,7 @@
     ;;
 
     .)
-        NGX_LOCK_PATH=$NGX_PREFIX/logs/nginx.lock
+        NGX_LOCK_PATH=$NGX_PREFIX/$NGX_PREFIX_LOCK_PATH
     ;;
 
     *)
@@ -476,7 +487,7 @@
     ;;
 
     .)
-        NGX_ERROR_LOG_PATH=$NGX_PREFIX/logs/error.log
+        NGX_ERROR_LOG_PATH=$NGX_PREFIX/$NGX_PREFIX_ERROR_LOG_PATH
     ;;
 
     .stderr)
@@ -494,7 +505,7 @@
     ;;
 
     .)
-        NGX_HTTP_LOG_PATH=$NGX_PREFIX/logs/access.log
+        NGX_HTTP_LOG_PATH=$NGX_PREFIX/$NGX_PREFIX_HTTP_LOG_PATH
     ;;
 
     *)
@@ -508,7 +519,7 @@
     ;;
 
     .)
-        NGX_HTTP_CLIENT_TEMP_PATH=$NGX_PREFIX/client_body_temp
+        NGX_HTTP_CLIENT_TEMP_PATH=$NGX_PREFIX/$NGX_PREFIX_HTTP_CLIENT_TEMP_PATH
     ;;
 
     *)
@@ -522,7 +533,7 @@
     ;;
 
     .)
-        NGX_HTTP_PROXY_TEMP_PATH=$NGX_PREFIX/proxy_temp
+        NGX_HTTP_PROXY_TEMP_PATH=$NGX_PREFIX/$NGX_PREFIX_HTTP_PROXY_TEMP_PATH
     ;;
 
     *)
@@ -536,7 +547,7 @@
     ;;
 
     .)
-        NGX_HTTP_FASTCGI_TEMP_PATH=$NGX_PREFIX/fastcgi_temp
+        NGX_HTTP_FASTCGI_TEMP_PATH=$NGX_PREFIX/$NGX_PREFIX_HTTP_FASTCGI_TEMP_PATH
     ;;
 
     *)
--- src/core/nginx.c.orig	2009-03-30 22:13:28.000000000 +0200
+++ src/core/nginx.c	2009-03-30 22:15:12.000000000 +0200
@@ -664,6 +664,30 @@
             cycle->conf_param.len = ngx_strlen(cycle->conf_param.data);
             break;
 
+        case 'p':
+            if (argv[i + 1] == NULL) {
+                ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
+                              "the option \"-p\" requires directory");
+                return NGX_ERROR;
+            }
+
+            i++;
+            cycle->root.len = ngx_strlen(argv[i]);
+            if (argv[i][cycle->root.len - 1] != '/') {
+                cycle->root.len++;
+
+                cycle->root.data = ngx_alloc(cycle->root.len + 1, cycle->log);
+                if (cycle->root.data == NULL) {
+                    return NGX_ERROR;
+                }
+                ngx_sprintf(cycle->root.data, "%s/%Z", argv[i]);
+            } else {
+                cycle->root.data = (u_char *) argv[i];
+            }
+            ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0,
+                          "prefix: \"%s\"", cycle->root.data);
+            break;
+
         default:
             ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
                           "invalid option: \"%s\"", argv[i]);
@@ -672,8 +696,22 @@
     }
 
     if (cycle->conf_file.data == NULL) {
-        cycle->conf_file.len = sizeof(NGX_CONF_PATH) - 1;
-        cycle->conf_file.data = (u_char *) NGX_CONF_PATH;
+        if (cycle->root.data == NULL) {
+            cycle->conf_file.len = sizeof(NGX_CONF_PATH) - 1;
+            cycle->conf_file.data = (u_char *) NGX_CONF_PATH;
+        } else {
+            cycle->conf_file.len = cycle->root.len +
+                                   sizeof(NGX_PREFIX_CONF_PATH) - 1;
+            cycle->conf_file.data = ngx_alloc(cycle->conf_file.len + 1,
+                                              cycle->log);
+            if (cycle->conf_file.data == NULL) {
+                return NGX_ERROR;
+            }
+            ngx_sprintf(cycle->conf_file.data,
+                        "%V%s%Z", &cycle->root, NGX_PREFIX_CONF_PATH);
+            ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0,
+                          "conf file: \"%s\"", cycle->conf_file.data);
+        }
     }
 
     return NGX_OK;
@@ -834,8 +872,20 @@
     }
 
     if (ccf->pid.len == 0) {
-        ccf->pid.len = sizeof(NGX_PID_PATH) - 1;
-        ccf->pid.data = (u_char *) NGX_PID_PATH;
+        if (cycle->root.len == 0) {
+            ccf->pid.len = sizeof(NGX_PID_PATH) - 1;
+            ccf->pid.data = NGX_PID_PATH;
+        } else {
+            ccf->pid.len = cycle->root.len +
+                           sizeof(NGX_PREFIX_PID_PATH) - 1;
+            ccf->pid.data = ngx_alloc(ccf->pid.len + 1, cycle->log);
+            if (ccf->pid.data == NULL) {
+                return NGX_CONF_ERROR;
+            }
+            ngx_sprintf(ccf->pid.data, "%V%s%Z", &cycle->root, NGX_PREFIX_PID_PATH);
+            ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0,
+                          "pid file: \"%s\"", ccf->pid.data);
+        }
     }
 
     if (ngx_conf_full_name(cycle, &ccf->pid, 0) != NGX_OK) {
@@ -854,8 +904,20 @@
 
 
     if (ccf->lock_file.len == 0) {
-        ccf->lock_file.len = sizeof(NGX_LOCK_PATH) - 1;
-        ccf->lock_file.data = (u_char *) NGX_LOCK_PATH;
+        if (cycle->root.len == 0) {
+            ccf->lock_file.len = sizeof(NGX_LOCK_PATH) - 1;
+            ccf->lock_file.data = NGX_LOCK_PATH;
+        } else {
+            ccf->lock_file.len = cycle->root.len +
+                                 sizeof(NGX_PREFIX_LOCK_PATH) - 1;
+            ccf->lock_file.data = ngx_alloc(ccf->lock_file.len + 1, cycle->log);
+            if (ccf->lock_file.data == NULL) {
+                return NGX_CONF_ERROR;
+            }
+            ngx_sprintf(ccf->lock_file.data, "%V%s%Z", &cycle->root, NGX_PREFIX_LOCK_PATH);
+            ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0,
+                          "lock file: \"%s\"", ccf->lock_file.data);
+        }
     }
 
     if (ngx_conf_full_name(cycle, &ccf->lock_file, 0) != NGX_OK) {
--- src/core/ngx_cycle.c.orig	2009-03-30 22:13:28.000000000 +0200
+++ src/core/ngx_cycle.c	2009-03-30 22:15:12.000000000 +0200
@@ -32,12 +32,6 @@
 static ngx_connection_t  dumb;
 /* STUB */
 
-#ifdef NGX_ERROR_LOG_PATH
-static ngx_str_t  error_log = ngx_string(NGX_ERROR_LOG_PATH);
-#else
-static ngx_str_t  error_log = ngx_null_string;
-#endif
-
 
 ngx_cycle_t *
 ngx_init_cycle(ngx_cycle_t *old_cycle)
@@ -87,9 +81,20 @@
     cycle->pool = pool;
     cycle->log = log;
     cycle->old_cycle = old_cycle;
-    cycle->root.len = sizeof(NGX_PREFIX) - 1;
-    cycle->root.data = (u_char *) NGX_PREFIX;
 
+    if (old_cycle->root.len > 0) {
+        cycle->root.len = old_cycle->root.len;
+        cycle->root.data = ngx_pnalloc(pool, old_cycle->root.len + 1);
+        if (cycle->root.data == NULL) {
+            ngx_destroy_pool(pool);
+            return(NULL);
+        }
+        ngx_cpystrn(cycle->root.data, old_cycle->root.data,
+                    old_cycle->root.len + 1);
+    } else {
+        cycle->root.len = sizeof(NGX_PREFIX) - 1;
+        cycle->root.data = (u_char *) NGX_PREFIX;
+    }
 
     cycle->conf_file.len = old_cycle->conf_file.len;
     cycle->conf_file.data = ngx_pnalloc(pool, old_cycle->conf_file.len + 1);
@@ -168,7 +173,22 @@
         return NULL;
     }
 
-    cycle->new_log->file->name = error_log;
+    if (cycle->root.len == 0) {
+        cycle->new_log->file->name.data = NGX_ERROR_LOG_PATH;
+        cycle->new_log->file->name.len = sizeof(NGX_ERROR_LOG_PATH) - 1;
+    } else {
+        cycle->new_log->file->name.len = cycle->root.len +
+                                         sizeof(NGX_PREFIX_ERROR_LOG_PATH) - 1;
+        cycle->new_log->file->name.data =
+            ngx_alloc(cycle->new_log->file->name.len + 1, cycle->log);
+        if (cycle->new_log->file->name.data == NULL) {
+            return NGX_CONF_ERROR;
+        }
+        ngx_sprintf(cycle->new_log->file->name.data,
+                    "%V%s%Z", &cycle->root, NGX_PREFIX_ERROR_LOG_PATH);
+        ngx_log_error(NGX_LOG_NOTICE, log, 0,
+                      "error file: \"%s\"", cycle->new_log->file->name.data);
+    }
 
 
     n = old_cycle->listening.nelts ? old_cycle->listening.nelts : 10;
--- src/http/ngx_http_core_module.c.orig	2009-03-26 16:24:19.000000000 +0100
+++ src/http/ngx_http_core_module.c	2009-03-30 22:15:12.000000000 +0200
@@ -119,10 +119,6 @@
 };
 
 
-static ngx_path_init_t  ngx_http_client_temp_path = {
-    ngx_string(NGX_HTTP_CLIENT_TEMP_PATH), { 0, 0, 0 }
-};
-
 
 #if (NGX_HTTP_GZIP)
 
@@ -3008,6 +3004,8 @@
     ngx_hash_key_t   *type;
     ngx_hash_init_t   types_hash;
 
+    ngx_path_init_t ngx_http_client_temp_path;
+
     if (conf->root.data == NULL) {
 
         conf->alias = prev->alias;
@@ -3175,6 +3173,29 @@
         conf->resolver = prev->resolver;
     }
 
+    if (cf->cycle->root.len == 0) {
+        ngx_http_client_temp_path.name.len =
+            ngx_strlen(NGX_HTTP_CLIENT_TEMP_PATH);
+        ngx_http_client_temp_path.name.data = NGX_HTTP_CLIENT_TEMP_PATH;
+    } else {
+        ngx_http_client_temp_path.name.len =
+            cf->cycle->root.len + sizeof(NGX_PREFIX_HTTP_CLIENT_TEMP_PATH) - 1;
+        ngx_http_client_temp_path.name.data =
+            ngx_alloc(ngx_http_client_temp_path.name.len + 1, cf->cycle->log);
+        if (ngx_http_client_temp_path.name.data == NULL) {
+            return NGX_CONF_ERROR;
+        }
+        ngx_sprintf(ngx_http_client_temp_path.name.data, "%V%s%Z",
+                    &cf->cycle->root, NGX_PREFIX_HTTP_CLIENT_TEMP_PATH);
+        ngx_log_error(NGX_LOG_NOTICE, cf->cycle->log, 0,
+                          "http client temp path: \"%s\"",
+                          ngx_http_client_temp_path.name.data);
+    }
+
+    for (i=0; i<3; i++) {
+        ngx_http_client_temp_path.level[i] = 0;
+    }
+
     if (ngx_conf_merge_path_value(cf, &conf->client_body_temp_path,
                               prev->client_body_temp_path,
                               &ngx_http_client_temp_path)
--- src/http/modules/ngx_http_proxy_module.c.orig	2009-03-30 22:13:29.000000000 +0200
+++ src/http/modules/ngx_http_proxy_module.c	2009-03-30 22:15:12.000000000 +0200
@@ -506,11 +506,6 @@
 };
 
 
-static ngx_path_init_t  ngx_http_proxy_temp_path = {
-    ngx_string(NGX_HTTP_PROXY_TEMP_PATH), { 1, 2, 0 }
-};
-
-
 static ngx_int_t
 ngx_http_proxy_handler(ngx_http_request_t *r)
 {
@@ -1889,6 +1884,9 @@
     ngx_http_proxy_redirect_t  *pr;
     ngx_http_script_compile_t   sc;
 
+    ngx_path_init_t             ngx_http_proxy_temp_path;
+    int                         i;
+
     if (conf->upstream.store != 0) {
         ngx_conf_merge_value(conf->upstream.store,
                                   prev->upstream.store, 0);
@@ -2026,6 +2024,31 @@
                                        |NGX_HTTP_UPSTREAM_FT_OFF;
     }
 
+
+    if (cf->cycle->root.len == 0) {
+        ngx_http_proxy_temp_path.name.len =
+            ngx_strlen(NGX_HTTP_PROXY_TEMP_PATH);
+        ngx_http_proxy_temp_path.name.data = NGX_HTTP_PROXY_TEMP_PATH;
+    } else {
+        ngx_http_proxy_temp_path.name.len =
+            cf->cycle->root.len + sizeof(NGX_PREFIX_HTTP_PROXY_TEMP_PATH) - 1;
+        ngx_http_proxy_temp_path.name.data =
+            ngx_alloc(ngx_http_proxy_temp_path.name.len + 1, cf->cycle->log);
+        if (ngx_http_proxy_temp_path.name.data == NULL) {
+            return NGX_CONF_ERROR;
+        }
+        ngx_sprintf(ngx_http_proxy_temp_path.name.data, "%V%s%Z",
+                    &cf->cycle->root, NGX_PREFIX_HTTP_PROXY_TEMP_PATH);
+        ngx_log_error(NGX_LOG_NOTICE, cf->cycle->log, 0,
+                          "http proxy temp path: \"%s\"",
+                          ngx_http_proxy_temp_path.name.data);
+
+    }
+
+    for (i=0; i<3; i++) {
+        ngx_http_proxy_temp_path.level[i] = 0;
+    }
+
     if (ngx_conf_merge_path_value(cf, &conf->upstream.temp_path,
                               prev->upstream.temp_path,
                               &ngx_http_proxy_temp_path)
--- src/http/modules/ngx_http_fastcgi_module.c.orig	2009-03-24 13:49:29.000000000 +0100
+++ src/http/modules/ngx_http_fastcgi_module.c	2009-03-30 22:15:12.000000000 +0200
@@ -499,11 +499,6 @@
 };
 
 
-static ngx_path_init_t  ngx_http_fastcgi_temp_path = {
-    ngx_string(NGX_HTTP_FASTCGI_TEMP_PATH), { 1, 2, 0 }
-};
-
-
 static ngx_int_t
 ngx_http_fastcgi_handler(ngx_http_request_t *r)
 {
@@ -1884,6 +1879,8 @@
     ngx_http_script_compile_t     sc;
     ngx_http_script_copy_code_t  *copy;
 
+    ngx_path_init_t               ngx_http_fastcgi_temp_path;
+
     if (conf->upstream.store != 0) {
         ngx_conf_merge_value(conf->upstream.store,
                                   prev->upstream.store, 0);
@@ -2023,6 +2020,30 @@
                                        |NGX_HTTP_UPSTREAM_FT_OFF;
     }
 
+    if (cf->cycle->root.len == 0) {
+        ngx_http_fastcgi_temp_path.name.len =
+            ngx_strlen(NGX_HTTP_FASTCGI_TEMP_PATH);
+        ngx_http_fastcgi_temp_path.name.data = NGX_HTTP_FASTCGI_TEMP_PATH;
+    } else {
+        ngx_http_fastcgi_temp_path.name.len =
+            cf->cycle->root.len + sizeof(NGX_PREFIX_HTTP_FASTCGI_TEMP_PATH) - 1;
+        ngx_http_fastcgi_temp_path.name.data =
+            ngx_alloc(ngx_http_fastcgi_temp_path.name.len + 1, cf->cycle->log);
+        if (ngx_http_fastcgi_temp_path.name.data == NULL) {
+            return NGX_CONF_ERROR;
+        }
+        ngx_sprintf(ngx_http_fastcgi_temp_path.name.data, "%V%s%Z",
+                    &cf->cycle->root, NGX_PREFIX_HTTP_FASTCGI_TEMP_PATH);
+        ngx_log_error(NGX_LOG_NOTICE, cf->cycle->log, 0,
+                          "http fastcgi temp path: \"%s\"",
+                          ngx_http_fastcgi_temp_path.name.data);
+
+    }
+
+    for (i=0; i<3; i++) {
+        ngx_http_fastcgi_temp_path.level[i] = 0;
+    }
+
     if (ngx_conf_merge_path_value(cf, &conf->upstream.temp_path,
                               prev->upstream.temp_path,
                               &ngx_http_fastcgi_temp_path)
--- src/http/modules/ngx_http_log_module.c.orig	2009-03-30 22:13:29.000000000 +0200
+++ src/http/modules/ngx_http_log_module.c	2009-03-30 22:15:12.000000000 +0200
@@ -179,8 +179,6 @@
 };
 
 
-static ngx_str_t  ngx_http_access_log = ngx_string(NGX_HTTP_LOG_PATH);
-
 
 static ngx_str_t  ngx_http_combined_fmt =
     ngx_string("$remote_addr - $remote_user [$time_local] "
@@ -766,6 +764,8 @@
     ngx_http_log_fmt_t        *fmt;
     ngx_http_log_main_conf_t  *lmcf;
 
+    ngx_str_t                  ngx_http_access_log;
+
     if (conf->open_file_cache == NGX_CONF_UNSET_PTR) {
 
         conf->open_file_cache = prev->open_file_cache;
@@ -798,6 +798,25 @@
         return NGX_CONF_ERROR;
     }
 
+
+    if (cf->cycle->root.data == NULL) {
+        ngx_http_access_log.data = NGX_HTTP_LOG_PATH;
+        ngx_http_access_log.len = sizeof(NGX_HTTP_LOG_PATH) - 1;
+    } else {
+        ngx_http_access_log.len = cf->cycle->root.len +
+                                  sizeof(NGX_PREFIX_HTTP_LOG_PATH) - 1;
+        ngx_http_access_log.data = ngx_alloc(ngx_http_access_log.len + 1,
+                                             cf->cycle->log);
+        if (ngx_http_access_log.data == NULL) {
+            return NGX_CONF_ERROR;
+        }
+        ngx_sprintf(ngx_http_access_log.data, "%V%s%Z",
+                    &cf->cycle->root, NGX_PREFIX_HTTP_LOG_PATH);
+        ngx_log_error(NGX_LOG_NOTICE, cf->cycle->log, 0,
+                          "http log path: \"%s\"",
+                          ngx_http_access_log.data);
+
+    }
     log->file = ngx_conf_open_file(cf->cycle, &ngx_http_access_log);
     if (log->file == NULL) {
         return NGX_CONF_ERROR;
--- src/core/ngx_conf_file.c.orig	2009-03-30 22:13:28.000000000 +0200
+++ src/core/ngx_conf_file.c	2009-03-30 22:15:12.000000000 +0200
@@ -795,7 +795,7 @@
 ngx_conf_full_name(ngx_cycle_t *cycle, ngx_str_t *name, ngx_uint_t conf_prefix)
 {
     size_t      len;
-    u_char     *p, *prefix;
+    u_char     *p, *prefix, *format;
     ngx_str_t   old;
 
     if (name->data[0] == '/') {
@@ -817,9 +817,27 @@
     old = *name;
 
     if (conf_prefix) {
-        len = sizeof(NGX_CONF_PREFIX) - 1;
-        prefix = (u_char *) NGX_CONF_PREFIX;
+        if (cycle->root.len == 0) {
+            len = sizeof(NGX_CONF_PREFIX) - 1;
+            prefix = (u_char *) NGX_CONF_PREFIX;
+        } else {
+            len = cycle->root.len + sizeof(NGX_PREFIX_CONF_PREFIX) - 1;
+            if (NGX_PREFIX_CONF_PREFIX[sizeof(NGX_PREFIX_CONF_PREFIX) - 2]
+                == '/') {
 
+                format = "%V%s%Z";
+            } else {
+                len++;
+                format = "%V%s/%Z";
+            }
+            prefix = ngx_alloc(len + 1, cycle->log);
+            if (prefix == NULL) {
+                return NGX_ERROR;
+            }
+            ngx_sprintf(prefix, format, &cycle->root, NGX_PREFIX_CONF_PREFIX);
+            ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0,
+                          "conf prefix: \"%s\"", prefix);
+        }
     } else {
         len = cycle->root.len;
         prefix = cycle->root.data;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic