Module API and srv structure initialization

Hi guys, i’m new to this forum (already introduced myself ^^).

I’m writing a nginx handler module and i need to load a file in a server
directive inside the config, let’s assume it’s something like:

server {

mymodule-ruleset /etc/nginx/mymodule-rules.json;

}

So i have a server structure like:

typedef struct {

ngx_str_t ruleset;

}
ngx_mymodule_srv_conf_t;

I initialize the ruleset attribute inside the merge_srv_conf handler:

ngx_conf_merge_str_value( conf->ruleset_path, prev->ruleset_path,
DEFAULT_RULESET_PATH );

( Where DEFAULT_RULESET_PATH is a constant #defined my me ).

The problem is, i have to load this file only once for server directive,
but the user could ignore the mymodule-ruleset using its default value,
so i can’t use an handler to load it (it could be never called).

Where’s the best place to load this file? In the postconfiguration
handler ? If so, how do i retrieve the srv_conf_t inside the
postconfiguration handler ?

Thanks for your time, i’m new to nginx developing and i’m finding some
trouble to understand its structure.

PS: I’ve already read the guides specified in the wiki, but there’s
nothing so specific.

Posted at Nginx Forum:

Hello!

On Wed, Jan 25, 2012 at 03:49:40AM -0500, evilsocket wrote:

Hi guys, i’m new to this forum (already introduced myself ^^).

I’m writing a nginx handler module and i need to load a file in a server
directive inside the config, let’s assume it’s something like:

[…]

See nginx-devel@ for the reply. Cross-posting isn’t really good
idea.

Maxim D.

I guess i’m gonna load it as a main configuration inside the post
configuration handler, thanks so much :slight_smile:

Posted at Nginx Forum: