Module: exit master

Maxim Dounin mdounin at mdounin.ru
Fri Feb 3 14:34:23 UTC 2012


Hello!

On Fri, Feb 03, 2012 at 02:25:21PM +0100, Laurent wrote:

> Hi,
> 
> I'm experiencing some troubles (and headaches) with my little nginx module.
> I've seen a lot of module code lately, and a ton of stuff about nginx
> modules but I can't manage to do what I need to.
> Here is my problem:
> I have created my own nginx module called "mymodule". Its loc_conf
> structure looks like that:
> 
> typedef struct {
>     void *serverConf;
>     ngx_str_t server_file;
> } ngx_http_mymodule_loc_conf_t;
> 
> its command structure looks like that:
> 
> static ngx_command_t ngx_http_mymodule_commands[] = {
>   {
>   ngx_string("mymodule"),
>   NGX_HTTP_LOC_CONF | NGX_CONF_TAKE1,
>   ngx_http_mymodule,
>   NGX_HTTP_LOC_CONF_OFFSET,
>   0,
>   NULL
>   },
> ngx_null_command };
> 
> in the ngx_http_mymodule function I do some stuff and set the
> serverConf pointer in the ngx_http_mymodule_loc_conf_t.
> The problem is that I would like to retrieve that serverConf pointer
> when the thread / process is exited. But the only parameter given to
> ngx_module_t while exiting thread process or master is a ngx_cycle_t*
> and I can't find how to retrieve the ngx_http_mymodule_loc_conf_t from
> it in order to work on that serverConf pointer.

You can't get location config from a cycle, as there are multiple 
locations and each has it's own config.  You may get module main 
config via ngx_http_cycle_get_module_main_conf().

Alternatively, depending on what you are trying to do, just a pool 
cleanup handler on configuration pool (with arbitrary opaque data 
passed) may be a better solution.

Maxim Dounin



More information about the nginx-devel mailing list