module develop --nginx segmentation fault

Sergey Bochenkov bachan at j3qq4.org
Thu Aug 21 15:52:33 MSD 2008


It's your custom config struct. You should allocate memory for it by yourself.

Example:

typedef struct {
	// fields

} ngx_http_super_loc_conf_t;

static ngx_http_module_t ngx_http_super_module_ctx =
{
	NULL,				// preconfiguration
	ngx_http_super_filter_init,	// postconfiguration

	NULL,				// create main configuration
	NULL,				// init main configuration

	NULL,				// create server configuration
	NULL,				// merge server configuration

	ngx_http_super_create_loc_conf,	// create location configuration
	ngx_http_super_merge_loc_conf	// merge location configuration
};

// ...

static void *ngx_http_super_create_loc_conf(ngx_conf_t *cf)
{
	ngx_http_super_loc_conf_t *conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_super_loc_conf_t));
	if (NULL == conf) return NGX_CONF_ERROR;

	return conf;
}

// ...

static char *ngx_http_super(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
	ngx_http_super_loc_conf_t *nlcf = conf;

	ngx_str_t *value = cf->args->elts;

	// ...

	return NGX_CONF_OK;
}

> Hi,
>   ncache_http_xxxx_enable(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
> 
> the conf is NULL.
> 
> 
> 
> 2008/8/21 Sergey Bochenkov <bachan at j3qq4.org>:
> >
> > What 3rd parameter if you said, that directive can take only one?
> >
> > NGX_CONF_TAKE1 means, that:
> >
> > ngx_str_t *value = cf->args->elts;
> >
> > ngx_str_t *directive_name   = &value[0]; // name of the directive
> > ngx_str_t *directive_param1 = &value[1]; // first (and last) directive parameter
> >
> >> Hi ,
> >>    I developed a nginx module, and compile is ok.
> >>  When I test the config file without the module directive ,it's ok.
> >> But when I test the config file with the module directive , segmentationo fault.
> >> I add log in the command set function and found the 3rd parameter is  null .
> >> I have set the correct location create&merge conf function in the
> >> module ctx structure.
> >> The directive is  flag is
> >> "NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1"
> >>
> >> Any idea on the reason?
> >>
> >> BR,
> >> DeltaY
> >>
> >>
> >
> >
> >
> >
> 
> 







More information about the nginx mailing list