[PATCH] export variables from the log module

Maxim Dounin mdounin at mdounin.ru
Sun Sep 30 18:54:16 UTC 2012


Hello!

On Sun, Sep 30, 2012 at 07:55:49AM +0400, Vladimir Shebordaev wrote:

[...]

> +static ngx_int_t
> +ngx_http_log_add_variables(ngx_conf_t *cf)
> +{
> +    ngx_http_log_var_t *v;
> +    ngx_http_variable_t *var;
> +    ngx_http_core_main_conf_t *cmcf;
> +
> +    ngx_int_t rc;
> +
> +    cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
> +    
> +    var = NULL;
> +
> +    for (v = ngx_http_log_vars; v->name.len; v++) {
> +
> +        if (var == NULL) {
> +            var = ngx_pcalloc(cf->pool, sizeof(ngx_http_variable_t));
> +            if (var == NULL) {
> +                return NGX_ERROR;
> +            }
> +        }
> +
> +        var->name = v->name;
> +        
> +        rc = ngx_hash_add_key(cmcf->variables_keys, &v->name, var,
> +                              NGX_HASH_READONLY_KEY);
> +
> +        if (rc == NGX_BUSY) {
> +            continue;
> +        }

No, it's layering violation.  It's not log modules business to 
hack cmcf->variables_keys.  And, as a side note, it's very-very 
wrong to just continue on conflicting variable names.

I've already pointed out correct aproach to this: log module 
not-really-variables should be reimplemented/duplicated as real 
variables in ngx_http_variables.c.

[...]

Maxim Dounin



More information about the nginx-devel mailing list