From 666f8626f5ec0e9561aa7944f761abf8b48cee79 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Wed, 15 Oct 2014 16:44:59 +0200 Subject: [PATCH 1/2] [FIX] allow postgres_set variables to be reused. This allow using the same code snippet to be included in multiple `server` directives. Fixes FRiCKLE/ngx_postgres#17 --- src/ngx_postgres_module.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/ngx_postgres_module.c b/src/ngx_postgres_module.c index 365de007..27c620a7 100644 --- a/src/ngx_postgres_module.c +++ b/src/ngx_postgres_module.c @@ -1079,7 +1079,7 @@ ngx_postgres_conf_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) pgvar->idx = pglcf->variables->nelts - 1; - pgvar->var = ngx_http_add_variable(cf, &value[1], 0); + pgvar->var = ngx_http_add_variable(cf, &value[1], NGX_HTTP_VAR_CHANGEABLE); if (pgvar->var == NULL) { dd("returning NGX_CONF_ERROR"); return NGX_CONF_ERROR; @@ -1091,22 +1091,11 @@ ngx_postgres_conf_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) return NGX_CONF_ERROR; } - /* - * Check if "$variable" was previously defined, - * back-off even if it was marked as "CHANGEABLE". - */ - if (pgvar->var->get_handler != NULL) { - ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "postgres: variable \"$%V\" is duplicate" - " in \"%V\" directive", &value[1], &cmd->name); - - dd("returning NGX_CONF_ERROR"); - return NGX_CONF_ERROR; + if (pgvar->var->get_handler == NULL) { + pgvar->var->get_handler = ngx_postgres_variable_get_custom; + pgvar->var->data = (uintptr_t) pgvar; } - pgvar->var->get_handler = ngx_postgres_variable_get_custom; - pgvar->var->data = (uintptr_t) pgvar; - pgvar->value.row = ngx_atoi(value[2].data, value[2].len); if (pgvar->value.row == NGX_ERROR) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, From bc6217e5ebe40b0beea794cb2cc91d21914a55fc Mon Sep 17 00:00:00 2001 From: Anonymous Date: Wed, 14 Dec 2016 13:56:52 +0000 Subject: [PATCH 2/2] Fix build with nginx 1.11.6 --- src/ngx_postgres_module.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ngx_postgres_module.c b/src/ngx_postgres_module.c index 365de007..e86abd61 100644 --- a/src/ngx_postgres_module.c +++ b/src/ngx_postgres_module.c @@ -1320,6 +1320,7 @@ ngx_postgres_find_upstream(ngx_http_request_t *r, ngx_url_t *url) continue; } + #if (nginx_version < 1011006) if (uscfp[i]->default_port && url->default_port && (uscfp[i]->default_port != url->default_port)) { @@ -1327,6 +1328,7 @@ ngx_postgres_find_upstream(ngx_http_request_t *r, ngx_url_t *url) continue; } + #endif dd("returning"); return uscfp[i]; }