Welcome! Log In Create A New Profile

Advanced

Re: Is there a wait to get at a module's main conf inside the loc conf's init?

Maxim Dounin
August 17, 2017 08:42AM
Hello!

On Thu, Aug 17, 2017 at 02:34:20AM -0400, ptcell wrote:

> Maxim Dounin Wrote:
> -------------------------------------------------------
>
> >
> > Try ngx_http_conf_get_module_main_conf().
> >
> > (Doing so in the create_loc_conf callback is probably pointless
> > though, as main conf contents can be changed later.)
>
> On a related note, is there a way to get the my module's main/srv/loc conf_t
> instances from the cycle instance passed to the worker process init callback
> in my module? I see my conf objects created and put into the ctx object
> before the worker process init is called, so I think there there.

This is something generally better to avoid (because getting a
module configuration from a cycle implies that there can be only
one http{} block), but it is certainly possible to obtain main
configuration via ngx_http_cycle_get_module_main_conf(). For an
example, see ngx_http_perl_init_worker() in the perl module:

http://hg.nginx.org/nginx/file/tip/src/http/modules/perl/ngx_http_perl_module.c#l1041

> From reading the code, I tried something like:
>
> #define ngx_http_cycle_get_module_main_conf(cf, module)
> \
> ((ngx_http_conf_ctx_t *)
> (cycle)->conf_ctx)->main_conf[(module).ctx_index]

It is not clear where you get this macro. Defined it yourself?
You certainly did it wrong. Correct macro is defined in
src/http/ngx_http_config.h as follows:

#define ngx_http_cycle_get_module_main_conf(cycle, module) \
(cycle->conf_ctx[ngx_http_module.index] ? \
((ngx_http_conf_ctx_t *) cycle->conf_ctx[ngx_http_module.index]) \
->main_conf[module.ctx_index]: \
NULL)

You don't need to redefine it, just use it as is.

--
Maxim Dounin
http://nginx.org/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Is there a wait to get at a module's main conf inside the loc conf's init?

ptcell August 09, 2017 09:33PM

Re: Is there a wait to get at a module's main conf inside the loc conf's init?

Maxim Dounin August 10, 2017 06:46AM

Re: Is there a wait to get at a module's main conf inside the loc conf's init?

ptcell August 10, 2017 02:46PM

Re: Is there a wait to get at a module's main conf inside the loc conf's init?

ptcell August 17, 2017 12:53AM

Re: Is there a wait to get at a module's main conf inside the loc conf's init?

Maxim Dounin August 17, 2017 08:42AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 263
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready