Skip to content

Commit 666f862

Browse files
committed
[FIX] allow postgres_set variables to be reused.
This allow using the same code snippet to be included in multiple `server` directives. Fixes FRiCKLE#17
1 parent 7950a25 commit 666f862

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

src/ngx_postgres_module.c

+4-15
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ ngx_postgres_conf_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
10791079

10801080
pgvar->idx = pglcf->variables->nelts - 1;
10811081

1082-
pgvar->var = ngx_http_add_variable(cf, &value[1], 0);
1082+
pgvar->var = ngx_http_add_variable(cf, &value[1], NGX_HTTP_VAR_CHANGEABLE);
10831083
if (pgvar->var == NULL) {
10841084
dd("returning NGX_CONF_ERROR");
10851085
return NGX_CONF_ERROR;
@@ -1091,22 +1091,11 @@ ngx_postgres_conf_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
10911091
return NGX_CONF_ERROR;
10921092
}
10931093

1094-
/*
1095-
* Check if "$variable" was previously defined,
1096-
* back-off even if it was marked as "CHANGEABLE".
1097-
*/
1098-
if (pgvar->var->get_handler != NULL) {
1099-
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1100-
"postgres: variable \"$%V\" is duplicate"
1101-
" in \"%V\" directive", &value[1], &cmd->name);
1102-
1103-
dd("returning NGX_CONF_ERROR");
1104-
return NGX_CONF_ERROR;
1094+
if (pgvar->var->get_handler == NULL) {
1095+
pgvar->var->get_handler = ngx_postgres_variable_get_custom;
1096+
pgvar->var->data = (uintptr_t) pgvar;
11051097
}
11061098

1107-
pgvar->var->get_handler = ngx_postgres_variable_get_custom;
1108-
pgvar->var->data = (uintptr_t) pgvar;
1109-
11101099
pgvar->value.row = ngx_atoi(value[2].data, value[2].len);
11111100
if (pgvar->value.row == NGX_ERROR) {
11121101
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,

0 commit comments

Comments
 (0)