1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-19 13:42:17 +03:00

Remove non-functional code for unloading loadable modules.

The code for unloading a library has been commented-out for over 12
years, ever since commit 602a9ef5a7, and we're
no closer to supporting it now than we were back then.

Nathan Bossart, reviewed by Michael Paquier and by me.

Discussion: http://postgr.es/m/Ynsc9bRL1caUSBSE@paquier.xyz
This commit is contained in:
Robert Haas
2022-05-11 15:27:33 -04:00
parent 78ccd6cca4
commit ab02d702ef
13 changed files with 13 additions and 200 deletions

View File

@@ -37,9 +37,8 @@
#include "utils/hsearch.h"
/* signatures for PostgreSQL-specific library init/fini functions */
/* signature for PostgreSQL-specific library init function */
typedef void (*PG_init_t) (void);
typedef void (*PG_fini_t) (void);
/* hashtable entry for rendezvous variables */
typedef struct
@@ -79,7 +78,6 @@ char *Dynamic_library_path;
static void *internal_load_library(const char *libname);
static void incompatible_module_error(const char *libname,
const Pg_magic_struct *module_magic_data) pg_attribute_noreturn();
static void internal_unload_library(const char *libname);
static bool file_exists(const char *name);
static char *expand_dynamic_library_name(const char *name);
static void check_restricted_library_name(const char *name);
@@ -154,9 +152,6 @@ load_file(const char *filename, bool restricted)
/* Expand the possibly-abbreviated filename to an exact path name */
fullname = expand_dynamic_library_name(filename);
/* Unload the library if currently loaded */
internal_unload_library(fullname);
/* Load the shared library */
(void) internal_load_library(fullname);
@@ -179,6 +174,11 @@ lookup_external_function(void *filehandle, const char *funcname)
* loaded. Return the pg_dl* handle for the file.
*
* Note: libname is expected to be an exact name for the library file.
*
* NB: There is presently no way to unload a dynamically loaded file. We might
* add one 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_load_library(const char *libname)
@@ -400,71 +400,6 @@ incompatible_module_error(const char *libname,
errdetail_internal("%s", details.data)));
}
/*
* 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;
struct stat stat_buf;
PG_fini_t PG_fini;
/*
* We need to do stat() in order to determine whether this is the same
* file as a previously loaded file; it's also handy so as to give a good
* error message if bogus file name given.
*/
if (stat(libname, &stat_buf) == -1)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not access file \"%s\": %m", libname)));
/*
* We have to zap all entries in the list that match on either filename or
* inode, else internal_load_library() will still think it's present.
*/
prv = NULL;
for (file_scanner = file_list; file_scanner != NULL; file_scanner = nxt)
{
nxt = file_scanner->next;
if (strcmp(libname, file_scanner->filename) == 0 ||
SAME_INODE(stat_buf, *file_scanner))
{
if (prv)
prv->next = nxt;
else
file_list = nxt;
/*
* If the library has a _PG_fini() function, call it.
*/
PG_fini = (PG_fini_t) dlsym(file_scanner->handle, "_PG_fini");
if (PG_fini)
(*PG_fini) ();
clear_external_function_hash(file_scanner->handle);
dlclose(file_scanner->handle);
free((char *) file_scanner);
/* prv does not change */
}
else
prv = file_scanner;
}
#endif /* NOT_USED */
}
static bool
file_exists(const char *name)
{

View File

@@ -582,20 +582,6 @@ record_C_func(HeapTuple procedureTuple,
entry->inforec = inforec;
}
/*
* clear_external_function_hash: remove entries for a library being closed
*
* Presently we just zap the entire hash table, but later it might be worth
* the effort to remove only the entries associated with the given handle.
*/
void
clear_external_function_hash(void *filehandle)
{
if (CFuncHash)
hash_destroy(CFuncHash);
CFuncHash = NULL;
}
/*
* Copy an FmgrInfo struct