[Patch] add -p option to override prefix

Jérôme Loyet jerome at loyet.net
Wed Apr 1 00:34:51 MSD 2009


2009/3/26 Igor Sysoev <is at 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   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
>
>            ngx_snprintf(ccf->pid.data, ccf->pid.len, "%s%s",
>                         cycle->root.data, NGX_PREFIX_PID_PATH);
>
> you need
>
>            ngx_sprintf(ccf->pid.data, "%V%s%Z",
>                        &cycle->root, NGX_PREFIX_PID_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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nginx-prefix-v2.patch
Type: application/octet-stream
Size: 18410 bytes
Desc: not available
URL: <http://nginx.org/pipermail/nginx/attachments/20090331/c5c93493/attachment.obj>


More information about the nginx mailing list