Create a "shmem_startup_hook" to be called at the end of shared memory
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 3 Jan 2009 17:08:39 +0000 (17:08 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 3 Jan 2009 17:08:39 +0000 (17:08 +0000)
initialization, to give loadable modules a reasonable place to perform
creation of any shared memory areas they need.  This is the logical conclusion
of our previous creation of RequestAddinShmemSpace() and RequestAddinLWLocks().
We don't need an explicit shmem_shutdown_hook, because the existing
on_shmem_exit and on_proc_exit mechanisms serve that need.

Also, adjust SubPostmasterMain so that libraries that got loaded into the
postmaster will be loaded into all child processes, not only regular backends.
This improves consistency with the non-EXEC_BACKEND behavior, and might be
necessary for functionality for some types of add-ons.

src/backend/postmaster/postmaster.c
src/backend/storage/ipc/ipci.c
src/include/storage/ipc.h

index f9ea20b7df206fce5f10773afe8c007c3e2a659e..71587ea1d7e30a23fbfbebca3d3c9f519d55a763 100644 (file)
@@ -3668,6 +3668,14 @@ SubPostmasterMain(int argc, char *argv[])
        /* Read in remaining GUC variables */
        read_nondefault_variables();
 
+       /*
+        * Reload any libraries that were preloaded by the postmaster.  Since
+        * we exec'd this process, those libraries didn't come along with us;
+        * but we should load them into all child processes to be consistent
+        * with the non-EXEC_BACKEND behavior.
+        */
+       process_shared_preload_libraries();
+
        /* Run backend or appropriate child */
        if (strcmp(argv[1], "--forkbackend") == 0)
        {
@@ -3680,21 +3688,15 @@ SubPostmasterMain(int argc, char *argv[])
                 * Need to reinitialize the SSL library in the backend, since the
                 * context structures contain function pointers and cannot be passed
                 * through the parameter file.
+                *
+                * XXX should we do this in all child processes?  For the moment it's
+                * enough to do it in backend children.
                 */
 #ifdef USE_SSL
                if (EnableSSL)
                        secure_initialize();
 #endif
 
-               /*
-                * process any libraries that should be preloaded at postmaster start
-                *
-                * NOTE: we have to re-load the shared_preload_libraries here because
-                * this backend is not fork()ed so we can't inherit any shared
-                * libraries / DLL's from our parent (the postmaster).
-                */
-               process_shared_preload_libraries();
-
                /*
                 * Perform additional initialization and client authentication.
                 *
index 8c7751db1b2a92867b2e4406ff084dfb699c7e04..ca6f7264607ea059943b4dacb3f2b852e23b3cd6 100644 (file)
@@ -34,6 +34,8 @@
 #include "storage/spin.h"
 
 
+shmem_startup_hook_type shmem_startup_hook = NULL;
+
 static Size total_addin_request = 0;
 static bool addin_request_allowed = true;
 
@@ -222,4 +224,10 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port)
        if (!IsUnderPostmaster)
                ShmemBackendArrayAllocation();
 #endif
+
+       /*
+        * Now give loadable modules a chance to set up their shmem allocations
+        */
+       if (shmem_startup_hook)
+               shmem_startup_hook();
 }
index d3aea147f57cf7bd408f5471189c13237a23f8ab..7a3a04edf0ebdd5ead6f3a505c4763368042e89e 100644 (file)
@@ -19,6 +19,7 @@
 #define IPC_H
 
 typedef void (*pg_on_exit_callback) (int code, Datum arg);
+typedef void (*shmem_startup_hook_type) (void);
 
 /*----------
  * API for handling cleanup that must occur during either ereport(ERROR)
@@ -71,6 +72,8 @@ extern void cancel_shmem_exit(pg_on_exit_callback function, Datum arg);
 extern void on_exit_reset(void);
 
 /* ipci.c */
+extern PGDLLIMPORT shmem_startup_hook_type shmem_startup_hook;
+
 extern void CreateSharedMemoryAndSemaphores(bool makePrivate, int port);
 
 #endif   /* IPC_H */