8000 Remove non-functional code for unloading loadable modules. · postgrespro/postgres@ab02d70 · GitHub
[go: up one dir, main page]

Skip to content

Commit ab02d70

Browse files
committed
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 602a9ef, 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
1 parent 78ccd6c commit ab02d70

File tree

13 files changed

+13
-200
lines changed
  • < 8000 div class="PRIVATE_TreeView-item-container prc-TreeView-TreeViewItemContainer--2Rkn" style="--level:1">
    contrib
  • doc/src/sgml
  • src
  • 13 files changed

    +13
    -200
    lines changed

    contrib/auto_explain/auto_explain.c

    Lines changed: 0 additions & 14 deletions
    Original file line numberDiff line numberDiff line change
    @@ -77,7 +77,6 @@ static ExecutorFinish_hook_type prev_ExecutorFinish = NULL;
    7777
    static ExecutorEnd_hook_type prev_ExecutorEnd = NULL;
    7878

    7979
    void _PG_init(void);
    80-
    void _PG_fini(void);
    8180

    8281
    static void explain_ExecutorStart(QueryDesc *queryDesc, int eflags);
    8382
    static void explain_ExecutorRun(QueryDesc *queryDesc,
    @@ -244,19 +243,6 @@ _PG_init(void)
    244243
    ExecutorEnd_hook = explain_ExecutorEnd;
    245244
    }
    246245

    247-
    /*
    248-
    * Module unload callback
    249-
    */
    250-
    void
    251-
    _PG_fini(void)
    252-
    {
    253-
    /* Uninstall hooks. */
    254-
    ExecutorStart_hook = prev_ExecutorStart;
    255-
    ExecutorRun_hook = prev_ExecutorRun;
    256-
    ExecutorFinish_hook = prev_ExecutorFinish;
    257-
    ExecutorEnd_hook = prev_ExecutorEnd;
    258-
    }
    259-
    260246
    /*
    261247
    * ExecutorStart hook: start up logging if needed
    262248
    */

    contrib/passwordcheck/passwordcheck.c

    Lines changed: 0 additions & 11 deletions
    Original file line numberDiff line numberDiff line change
    @@ -33,7 +33,6 @@ static check_password_hook_type prev_check_password_hook = NULL;
    3333
    #define MIN_PWD_LENGTH 8
    3434

    3535
    extern void _PG_init(void);
    36-
    extern void _PG_fini(void);
    3736

    3837
    /*
    3938
    * check_password
    @@ -149,13 +148,3 @@ _PG_init(void)
    149148
    prev_check_password_hook = check_password_hook;
    150149
    check_password_hook = check_password;
    151150
    }
    152-
    153-
    /*
    154-
    * Module unload function
    155-
    */
    156-
    void
    157-
    _PG_fini(void)
    158-
    {
    159-
    /* uninstall hook */
    160-
    check_password_hook = prev_check_password_hook;
    161-
    }

    contrib/pg_stat_statements/pg_stat_statements.c

    Lines changed: 0 additions & 18 deletions
    Original file line numberDiff line numberDiff line change
    @@ -305,7 +305,6 @@ static bool pgss_save; /* whether to save stats across shutdown */
    305305
    /*---- Function declarations ----*/
    306306

    307307
    void _PG_init(void);
    308-
    void _PG_fini(void);
    309308

    310309
    PG_FUNCTION_INFO_V1(pg_stat_statements_reset);
    311310
    PG_FUNCTION_INFO_V1(pg_stat_statements_reset_1_7);
    @@ -481,23 +480,6 @@ _PG_init(void)
    481480
    ProcessUtility_hook = pgss_ProcessUtility;
    482481
    }
    483482

    484-
    /*
    485-
    * Module unload callback
    486-
    */
    487-
    void
    488-
    _PG_fini(void)
    489-
    {
    490-
    /* Uninstall hooks. */
    491-
    shmem_startup_hook = prev_shmem_startup_hook;
    492-
    post_parse_analyze_hook = prev_post_parse_analyze_hook;
    493-
    planner_hook = prev_planner_hook;
    494-
    ExecutorStart_hook = prev_ExecutorStart;
    495-
    ExecutorRun_hook = prev_ExecutorRun;
    496-
    ExecutorFinish_hook = prev_ExecutorFinish;
    497-
    ExecutorEnd_hook = prev_ExecutorEnd;
    498-
    ProcessUtility_hook = prev_ProcessUtility;
    499-
    }
    500-
    501483
    /*
    502484
    * shmem_startup hook: allocate or attach to shared memory,
    503485
    * then load any pre-existing statistics from file.

    doc/src/sgml/xfunc.sgml

    Lines changed: 3 additions & 15 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1978,28 +1978,16 @@ PG_MODULE_MAGIC;
    19781978
    <indexterm zone="xfunc-c-dynload">
    19791979
    <primary>_PG_init</primary>
    19801980
    </indexterm>
    1981-
    <indexterm zone="xfunc-c-dynload">
    1982-
    <primary>_PG_fini</primary>
    1983-
    </indexterm>
    19841981
    <indexterm zone="xfunc-c-dynload">
    19851982
    <primary>library initialization function</primary>
    19861983
    </indexterm>
    1987-
    <indexterm zone="xfunc-c-dynload">
    1988-
    <primary>library finalization function</primary>
    1989-
    </indexterm>
    19901984

    19911985
    <para>
    1992-
    Optionally, a dynamically loaded file can contain initialization and
    1993-
    finalization functions. If the file includes a function named
    1986+
    Optionally, a dynamically loaded file can contain an initialization
    1987+
    function. If the file includes a function named
    19941988
    <function>_PG_init</function>, that function will be called immediately after
    19951989
    loading the file. The function receives no parameters and should
    1996-
    return void. If the file includes a function named
    1997-
    <function>_PG_fini</function>, that function will be called immediately before
    1998-
    unloading the file. Likewise, the function receives no parameters and
    1999-
    should return void. Note that <function>_PG_fini</function> will only be called
    2000-
    during an unload of the file, not during process termination.
    2001-
    (Presently, unloads are disabled and will never occur, but this may
    2002-
    change in the future.)
    1990+
    return void. There is presently no way to unload a dynamically loaded file.
    20031991
    </para>
    20041992

    20051993
    </sect2>

    src/backend/postmaster/pgarch.c

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -802,7 +802,7 @@ HandlePgArchInterrupts(void)
    802802
    * Ideally, we would simply unload the previous archive module and
    803803
    * load the new one, but there is presently no mechanism for
    804804
    * unloading a library (see the comment above
    805-
    * internal_unload_library()). To deal with this, we simply restart
    805+
    * internal_load_library()). To deal with this, we simply restart
    806806
    * the archiver. The new archive module will be loaded when the new
    807807
    * archiver process starts up.
    808808
    */

    src/backend/utils/fmgr/dfmgr.c

    Lines changed: 6 additions & 71 deletions
    Original file line numberDiff line numberDiff line change
    @@ -37,9 +37,8 @@
    3737
    #include "utils/hsearch.h"
    3838

    3939

    40-
    /* signatures for PostgreSQL-specific library init/fini functions */
    40+
    /* signature for PostgreSQL-specific library init function */
    4141
    typedef void (*PG_init_t) (void);
    42-
    typedef void (*PG_fini_t) (void);
    4342

    4443
    /* hashtable entry for rendezvous variables */
    4544
    typedef struct
    @@ -79,7 +78,6 @@ char *Dynamic_library_path;
    7978
    static void *internal_load_library(const char *libname);
    8079
    static void incompatible_module_error(const char *libname,
    8180
    const Pg_magic_struct *module_magic_data) pg_attribute_noreturn();
    82-
    static void internal_unload_library(const char *libname);
    8381
    static bool file_exists(const char *name);
    8482
    static char *expand_dynamic_library_name(const char *name);
    8583
    static void check_restricted_library_name(const char *name);
    @@ -154,9 +152,6 @@ load_file(const char *filename, bool restricted)
    154152
    /* Expand the possibly-abbreviated filename to an exact path name */
    155153
    fullname = expand_dynamic_library_name(filename);
    156154

    157-
    /* Unload the library if currently loaded */
    158-
    internal_unload_library(fullname);
    159-
    160155
    /* Load the shared library */
    161156
    (void) internal_load_library(fullname);
    162157

    @@ -179,6 +174,11 @@ lookup_external_function(void *filehandle, const char *funcname)
    179174
    * loaded. Return the pg_dl* handle for the file.
    180175
    *
    181176
    * Note: libname is expected to be an exact name for the library file.
    177+
    *
    178+
    * NB: There is presently no way to unload a dynamically loaded file. We might
    179+
    * add one someday if we can convince ourselves we have safe protocols for un-
    180+
    * hooking from hook function pointers, releasing custom GUC variables, and
    181+
    * perhaps other things that are definitely unsafe currently.
    182182
    */
    183183
    static void *
    184184
    internal_load_library(const char *libname)
    @@ -400,71 +400,6 @@ incompatible_module_error(const char *libname,
    400400
    errdetail_internal("%s", details.data)));
    401401
    }
    402402

    403-
    /*
    404-
    * Unload the specified dynamic-link library file, if it is loaded.
    405-
    *
    406-
    * Note: libname is expected to be an exact name for the library file.
    407-
    *
    408-
    * XXX for the moment, this is disabled, resulting in LOAD of an already-loaded
    409-
    * library always being a no-op. We might re-enable it someday if we can
    410-
    * convince ourselves we have safe protocols for un-hooking from hook function
    411-
    * pointers, releasing custom GUC variables, and perhaps other things that
    412-
    * are definitely unsafe currently.
    413-
    */
    414-
    static void
    415-
    internal_unload_library(const char *libname)
    416-
    {
    417-
    #ifdef NOT_USED
    418-
    DynamicFileList *file_scanner,
    419-
    *prv,
    420-
    *nxt;
    421-
    struct stat stat_buf;
    422-
    PG_fini_t PG_fini;
    423-
    424-
    /*
    425-
    * We need to do stat() in order to determine whether this is the same
    426-
    * file as a previously loaded file; it's also handy so as to give a good
    427-
    * error message if bogus file name given.
    428-
    */
    429-
    if (stat(libname, &stat_buf) == -1)
    430-
    ereport(ERROR,
    431-
    (errcode_for_file_access(),
    432-
    errmsg("could not access file \"%s\": %m", libname)));
    433-
    434-
    /*
    435-
    * We have to zap all entries in the list that match on either filename or
    436-
    * inode, else internal_load_library() will still think it's present.
    437-
    */
    438-
    prv = NULL;
    439-
    for (file_scanner = file_list; file_scanner != NULL; file_scanner = nxt)
    440-
    {
    441-
    nxt = file_scanner->next;
    442-
    if (strcmp(libname, file_scanner->filename) == 0 ||
    443-
    SAME_INODE(stat_buf, *file_scanner))
    444-
    {
    445-
    if (prv)
    446-
    prv->next = nxt;
    447-
    else
    448-
    file_list = nxt;
    449-
    450-
    /*
    451-
    * If the library has a _PG_fini() function, call it.
    452-
    */
    453-
    PG_fini = (PG_fini_t) dlsym(file_scanner->handle, "_PG_fini");
    454-
    if (PG_fini)
    455-
    (*PG_fini) ();
    456-
    457-
    clear_external_function_hash(file_scanner->handle);
    458-
    dlclose(file_scanner->handle);
    459-
    free((char *) file_scanner);
    460-
    /* prv does not change */
    461-
    }
    462-
    else
    463-
    prv = file_scanner;
    464-
    }
    465-
    #endif /* NOT_USED */
    466-
    }
    467-
    468403
    static bool
    469404
    file_exists(const char *name)
    470405
    {

    src/backend/utils/fmgr/fmgr.c

    Lines changed: 0 additions & 14 deletions
    Original file line numberDiff line numberDiff line change
    @@ -582,20 +582,6 @@ record_C_func(HeapTuple procedureTuple,
    582582
    entry->inforec = inforec;
    583583
    }
    584584

    585-
    /*
    586-
    * clear_external_function_hash: remove entries for a library being closed
    587-
    *
    588-
    * Presently we just zap the entire hash table, but later it might be worth
    589-
    * the effort to remove only the entries associated with the given handle.
    590-
    */
    591-
    void
    592-
    clear_external_function_hash(void *filehandle)
    593-
    {
    594-
    if (CFuncHash)
    595-
    hash_destroy(CFuncHash);
    596-
    CFuncHash = NULL;
    597-
    }
    598-
    599585

    600586
    /*
    601587
    * Copy an FmgrInfo struct

    src/include/fmgr.h

    Lines changed: 0 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -705,7 +705,6 @@ extern bytea *OidSendFunctionCall(Oid functionId, Datum val);
    705705
    * Routines in fmgr.c
    706706
    */
    707707
    extern const Pg_finfo_record *fetch_finfo_record(void *filehandle, const char *funcname);
    708-
    extern void clear_external_function_hash(void *filehandle);
    709708
    extern Oid fmgr_internal_function(const char *proname);
    710709
    extern Oid get_fn_expr_rettype(FmgrInfo *flinfo);
    711710
    extern Oid get_fn_expr_argtype(FmgrInfo *flinfo, int argnum);

    src/pl/plpgsql/src/plpgsql.h

    Lines changed: 0 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1100,8 +1100,6 @@ typedef struct PLpgSQL_execstate
    11001100
    * variable "PLpgSQL_plugin" and set it to point to a PLpgSQL_plugin struct.
    11011101
    * Typically the struct could just be static data in the plugin library.
    11021102
    * We expect that a plugin would do this at library load time (_PG_init()).
    1103-
    * It must also be careful to set the rendezvous variable back to NULL
    1104-
    * if it is unloaded (_PG_fini()).
    11051103
    *
    11061104
    * This structure is basically a collection of function pointers --- at
    11071105
    * various interesting points in pl_exec.c, we call these functions

    src/test/modules/delay_execution/delay_execution.c

    Lines changed: 1 addition & 9 deletions
    Original file line numberDiff line numberDiff line change
    @@ -36,9 +36,8 @@ static int post_planning_lock_id = 0;
    3636
    /* Save previous planner hook user to be a good citizen */
    3737
    static planner_hook_type prev_planner_hook = NULL;
    3838

    39-
    /* Module load/unload functions */
    39+
    /* Module load function */
    4040
    void _PG_init(void);
    41-
    void _PG_fini(void);
    4241

    4342

    4443
    /* planner_hook function to provide the desired delay */
    @@ -97,10 +96,3 @@ _PG_init(void)
    9796
    prev_planner_hook = planner_hook;
    9897
    planner_hook = delay_execution_planner;
    9998
    }
    100-
    101-
    /* Module unload function (pro forma, not used currently) */
    102-
    void
    103-
    _PG_fini(void)
    104-
    {
    105-
    planner_hook = prev_planner_hook;
    106-
    }

    0 commit comments

    Comments
     (0)
    0