From 22f77b0f9db1220789b262cda6dccad49d031643 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 3 Sep 2009 22:11:30 +0000 Subject: [PATCH] Make LOAD of an already-loaded library into a no-op, instead of attempting to unload and re-load the library. The difficulty with unloading a library is that we haven't defined safe protocols for doing so. In particular, there's no safe mechanism for getting out of a "hook" function pointer unless libraries are unloaded in reverse order of loading. And there's no mechanism at all for undefining a custom GUC variable, so GUC would be left with a pointer to an old value that might or might not still be valid, and very possibly wouldn't be in the same place anymore. While the unload and reload behavior had some usefulness in easing development of new loadable libraries, it's of no use whatever to normal users, so just disabling it isn't giving up that much. Someday we might care to expend the effort to develop safe unload protocols; but even if we did, there'd be little certainty that every third-party loadable module was following them, so some security restrictions would still be needed. Back-patch to 8.2; before that, LOAD was superuser-only anyway. Security: unprivileged users could crash backend. CVE not assigned yet --- doc/src/sgml/ref/create_function.sgml | 8 ++++---- doc/src/sgml/ref/load.sgml | 17 ++++++++--------- doc/src/sgml/xfunc.sgml | 10 ++++------ src/backend/utils/fmgr/dfmgr.c | 10 +++++++++- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/doc/src/sgml/ref/create_function.sgml b/doc/src/sgml/ref/create_function.sgml index 20fc0bc898..56719b44d1 100644 --- a/doc/src/sgml/ref/create_function.sgml +++ b/doc/src/sgml/ref/create_function.sgml @@ -1,5 +1,5 @@ @@ -400,9 +400,9 @@ CREATE FUNCTION foo(int, out text) ... When repeated CREATE FUNCTION calls refer to - the same object file, the file is only loaded once. To unload and - reload the file (perhaps during development), use the command. + the same object file, the file is only loaded once per session. + To unload and + reload the file (perhaps during development), start a new session. diff --git a/doc/src/sgml/ref/load.sgml b/doc/src/sgml/ref/load.sgml index 5fc5817e5f..92d06e8fb2 100644 --- a/doc/src/sgml/ref/load.sgml +++ b/doc/src/sgml/ref/load.sgml @@ -1,5 +1,5 @@ @@ -10,7 +10,7 @@ $PostgreSQL: pgsql/doc/src/sgml/ref/load.sgml,v 1.23 2006/09/16 00:30:19 momjian LOAD - load or reload a shared library file + load a shared library file @@ -28,13 +28,12 @@ LOAD 'filename' This command loads a shared library file into the PostgreSQL - server's address space. If the file had been loaded previously, - it is first unloaded. This command is primarily useful to unload - and reload a shared library file that has been changed since the - server first loaded it. To make use of the shared library, - function(s) in it need to be declared using the - command. + server's address space. If the file has been loaded already, + the command does nothing. Shared library files that contain C functions + are automatically loaded whenever one of their functions is called. + Therefore, an explicit LOAD is usually only needed to + load a library that modifies the server's behavior through hooks + rather than providing a set of functions. diff --git a/doc/src/sgml/xfunc.sgml b/doc/src/sgml/xfunc.sgml index 6cac5ec3fb..9741cfddee 100644 --- a/doc/src/sgml/xfunc.sgml +++ b/doc/src/sgml/xfunc.sgml @@ -1,4 +1,4 @@ - + User-Defined Functions @@ -1213,9 +1213,7 @@ PG_MODULE_MAGIC; file is retained in memory. Future calls in the same session to the function(s) in that file will only incur the small overhead of a symbol table lookup. If you need to force a reload of an object - file, for example after recompiling it, use the command or begin a - fresh session. + file, for example after recompiling it, begin a fresh session. @@ -1241,8 +1239,8 @@ PG_MODULE_MAGIC; unloading the file. Likewise, the function receives no parameters and should return void. Note that _PG_fini will only be called during an unload of the file, not during process termination. - (Presently, an unload only happens in the context of re-loading - the file due to an explicit LOAD command.) + (Presently, unloads are disabled and will never occur, but this may + change in the future.) diff --git a/src/backend/utils/fmgr/dfmgr.c b/src/backend/utils/fmgr/dfmgr.c index ceefe44497..a74d3e5351 100644 --- a/src/backend/utils/fmgr/dfmgr.c +++ b/src/backend/utils/fmgr/dfmgr.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.92 2006/10/06 17:13:59 petere Exp $ + * $PostgreSQL: pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.92.2.1 2009/09/03 22:11:30 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -310,10 +310,17 @@ internal_load_library(const char *libname) * Unload the specified dynamic-link library file, if it is loaded. * * Note: libname is expected to be an exact name for the library file. + * + * XXX for the moment, this is disabled, resulting in LOAD of an already-loaded + * library always being a no-op. We might re-enable it someday if we can + * convince ourselves we have safe protocols for un-hooking from hook function + * pointers, releasing custom GUC variables, and perhaps other things that + * are definitely unsafe currently. */ static void internal_unload_library(const char *libname) { +#ifdef NOT_USED DynamicFileList *file_scanner, *prv, *nxt; @@ -361,6 +368,7 @@ internal_unload_library(const char *libname) else prv = file_scanner; } +#endif /* NOT_USED */ } static bool