From: Paul Ramsey Date: Tue, 11 Aug 2015 14:33:23 +0000 (+0000) Subject: #2382, allow multiple libraries to co-exist during upgrade, warn about GUC value... X-Git-Tag: 2.2.0rc1~169 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a44b27c702c625a826542a833490e19addd8ba3a;p=postgis #2382, allow multiple libraries to co-exist during upgrade, warn about GUC value being locked during coexistence period. git-svn-id: http://svn.osgeo.org/postgis/trunk@13902 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/postgis/lwgeom_backend_api.c b/postgis/lwgeom_backend_api.c index 5bac65d5d..5fbfa54af 100644 --- a/postgis/lwgeom_backend_api.c +++ b/postgis/lwgeom_backend_api.c @@ -104,7 +104,31 @@ static void lwgeom_backend_switch( const char* newvalue, void* extra ) void lwgeom_init_backend() { - DefineCustomStringVariable( "postgis.backend", /* name */ + /* #2382 Before trying to create a user GUC, make sure */ + /* that the name is not already in use. Why would it be in use? */ + /* During an upgrade, a prior copy of the PostGIS library will */ + /* already be loaded in memory and the GUC already defined. We */ + /* can skip GUC definition in this case, so we just return. */ + static const char *guc_name = "postgis.backend"; + const char *guc_installed = GetConfigOption(guc_name, TRUE, FALSE); + + /* Uh oh, this GUC name already exists. Ordinarily we could just go on */ + /* our way, but the way the postgis.backend works is by using the "assign" */ + /* callback to change which backend is in use by flipping a global variable */ + /* over. This saves the overhead of looking up the engine every time, at */ + /* the expense of the extra complexity. */ + if ( guc_installed ) + { + /* In this narrow case the previously installed GUC is tied to the callback in */ + /* the previously loaded library. Probably this is happening during an */ + /* upgrade, so the old library is where the callback ties to. */ + elog(WARNING, "'%s' is currently set to '%s' and cannot be changed until you reconnect", guc_name, guc_installed); + return; + } + + /* Good, the GUC name is not already in use, so this must be a fresh */ + /* and clean new load of the library, and we can define the user GUC */ + DefineCustomStringVariable( guc_name, /* name */ "Sets the PostGIS Geometry Backend.", /* short_desc */ "Sets the PostGIS Geometry Backend (allowed values are 'geos' or 'sfcgal')", /* long_desc */ &lwgeom_backend_name, /* valueAddr */