[Patch] add -p option to override prefix

Igor Sysoev is at rambler-co.ru
Thu Mar 26 16:02:29 MSK 2009

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.

Igor Sysoev

More information about the nginx mailing list