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

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

blason
From the debugger I can see that it's probably some offset into
cf->ctx[index].main_conf, but I don't see anyway of knowing what that index
is inside the loc create callback.

Is there any other way of getting this?    Getting it at loc merge time
would be acceptable too.


void *ngx_http_my_module_create_conf(ngx_conf_t *cf) {

}

Thank you.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,275998,275998#msg-275998

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Maxim Dounin
Hello!

On Wed, Aug 09, 2017 at 09:33:59PM -0400, ptcell wrote:

> From the debugger I can see that it's probably some offset into
> cf->ctx[index].main_conf, but I don't see anyway of knowing what that index
> is inside the loc create callback.
>
> Is there any other way of getting this?    Getting it at loc merge time
> would be acceptable too.

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.)

--
Maxim Dounin
http://nginx.org/
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

blason
Maxim Dounin Wrote:
-------------------------------------------------------

> Hello!
>
> On Wed, Aug 09, 2017 at 09:33:59PM -0400, ptcell wrote:
>
> > From the debugger I can see that it's probably some offset into
> > cf->ctx[index].main_conf, but I don't see anyway of knowing what
> that index
> > is inside the loc create callback.
> >
> > Is there any other way of getting this?    Getting it at loc merge
> time
> > would be acceptable too.
>
> 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.)
>
> --
> Maxim Dounin
> http://nginx.org/
> _______________________________________________
> nginx mailing list
> [hidden email]
> http://mailman.nginx.org/mailman/listinfo/nginx


Thank you.  I saw that similar macro for requests, but missed it for
configs.  I see now the module entity has a static index on it.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,275998,276014#msg-276014

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

blason
In reply to this post by Maxim Dounin
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.)
>
> --
> Maxim Dounin
> http://nginx.org/
> _______________________________________________
> nginx mailing list
> [hidden email]
> http://mailman.nginx.org/mailman/listinfo/nginx


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.

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]


/* declared as init process in ngx_module_t     */
static ngx_int_t ngx_my_init_worker_process(ngx_cycle_t *cycle) {
   ngx_http_my_module_conf_t   *main_conf;
   main_conf = ngx_http_cycle_get_module_main_conf(cycle,
ngx_http_my_module);
}

but that either just returned Nulls or crashed.   I suspect there's a
simpler way.

Thank you very much!

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,275998,276080#msg-276080

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Maxim Dounin
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
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Loading...