init module callback called twice

xdrew nginx-forum at forum.nginx.org
Thu Apr 8 09:54:42 UTC 2021


Hello,

I'm developing a little custom module for nginx, and I need to execute some
user code once my module is loaded. I do this by attaching to the hook in
ngx_module_t structure:

ngx_module_t  ngx_http_hello_world_module = {
...
    NULL,                                  /* init master */
    init_module,                         /* init module */
    NULL,                                  /* init process */
...
}

static ngx_int_t init_module(ngx_cycle_t *cycle) {
ngx_log_stderr (0, "Initializing module") ; }

Surprisingly my callback is called twice. First time it follows log message

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: Initializing module

and then 

nginx: configuration file /etc/nginx/nginx.conf test is successful
nginx: Initializing module

Is there a way to recognize that I'm called in some different context (e.g.
some value from ngx_cycle_t structure)?
Or may be I'm doing something completely wrong?

Thanks
Andrew

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



More information about the nginx mailing list