Clean up order in miscinit.c a bit
authorPeter Eisentraut <peter@eisentraut.org>
Wed, 11 Mar 2020 12:51:55 +0000 (13:51 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Wed, 11 Mar 2020 12:51:55 +0000 (13:51 +0100)
The code around InitPostmasterChild() from commit 31c453165b5 somehow
ended up in the middle of a block of code related to "User ID state".
Move it into its own block instead.

src/backend/utils/init/miscinit.c
src/include/miscadmin.h

index b02bad442033bd12f3486b588b00e0bc9339371c..cd099b0c709c5f64c0fb67544c70adee31ac0897 100644 (file)
@@ -75,6 +75,119 @@ static Latch LocalLatchData;
 bool       IgnoreSystemIndexes = false;
 
 
+/* ----------------------------------------------------------------
+ * common process startup code
+ * ----------------------------------------------------------------
+ */
+
+/*
+ * Initialize the basic environment for a postmaster child
+ *
+ * Should be called as early as possible after the child's startup.
+ */
+void
+InitPostmasterChild(void)
+{
+   IsUnderPostmaster = true;   /* we are a postmaster subprocess now */
+
+   InitProcessGlobals();
+
+   /*
+    * make sure stderr is in binary mode before anything can possibly be
+    * written to it, in case it's actually the syslogger pipe, so the pipe
+    * chunking protocol isn't disturbed. Non-logpipe data gets translated on
+    * redirection (e.g. via pg_ctl -l) anyway.
+    */
+#ifdef WIN32
+   _setmode(fileno(stderr), _O_BINARY);
+#endif
+
+   /* We don't want the postmaster's proc_exit() handlers */
+   on_exit_reset();
+
+   /* Initialize process-local latch support */
+   InitializeLatchSupport();
+   MyLatch = &LocalLatchData;
+   InitLatch(MyLatch);
+
+   /*
+    * If possible, make this process a group leader, so that the postmaster
+    * can signal any child processes too. Not all processes will have
+    * children, but for consistency we make all postmaster child processes do
+    * this.
+    */
+#ifdef HAVE_SETSID
+   if (setsid() < 0)
+       elog(FATAL, "setsid() failed: %m");
+#endif
+
+   /* Request a signal if the postmaster dies, if possible. */
+   PostmasterDeathSignalInit();
+}
+
+/*
+ * Initialize the basic environment for a standalone process.
+ *
+ * argv0 has to be suitable to find the program's executable.
+ */
+void
+InitStandaloneProcess(const char *argv0)
+{
+   Assert(!IsPostmasterEnvironment);
+
+   InitProcessGlobals();
+
+   /* Initialize process-local latch support */
+   InitializeLatchSupport();
+   MyLatch = &LocalLatchData;
+   InitLatch(MyLatch);
+
+   /* Compute paths, no postmaster to inherit from */
+   if (my_exec_path[0] == '\0')
+   {
+       if (find_my_exec(argv0, my_exec_path) < 0)
+           elog(FATAL, "%s: could not locate my own executable path",
+                argv0);
+   }
+
+   if (pkglib_path[0] == '\0')
+       get_pkglib_path(my_exec_path, pkglib_path);
+}
+
+void
+SwitchToSharedLatch(void)
+{
+   Assert(MyLatch == &LocalLatchData);
+   Assert(MyProc != NULL);
+
+   MyLatch = &MyProc->procLatch;
+
+   if (FeBeWaitSet)
+       ModifyWaitEvent(FeBeWaitSet, 1, WL_LATCH_SET, MyLatch);
+
+   /*
+    * Set the shared latch as the local one might have been set. This
+    * shouldn't normally be necessary as code is supposed to check the
+    * condition before waiting for the latch, but a bit care can't hurt.
+    */
+   SetLatch(MyLatch);
+}
+
+void
+SwitchBackToLocalLatch(void)
+{
+   Assert(MyLatch != &LocalLatchData);
+   Assert(MyProc != NULL && MyLatch == &MyProc->procLatch);
+
+   MyLatch = &LocalLatchData;
+
+   if (FeBeWaitSet)
+       ModifyWaitEvent(FeBeWaitSet, 1, WL_LATCH_SET, MyLatch);
+
+   SetLatch(MyLatch);
+}
+
+
 /* ----------------------------------------------------------------
  *             database path / name support stuff
  * ----------------------------------------------------------------
@@ -262,113 +375,6 @@ static int    SecurityRestrictionContext = 0;
 /* We also remember if a SET ROLE is currently active */
 static bool SetRoleIsActive = false;
 
-/*
- * Initialize the basic environment for a postmaster child
- *
- * Should be called as early as possible after the child's startup.
- */
-void
-InitPostmasterChild(void)
-{
-   IsUnderPostmaster = true;   /* we are a postmaster subprocess now */
-
-   InitProcessGlobals();
-
-   /*
-    * make sure stderr is in binary mode before anything can possibly be
-    * written to it, in case it's actually the syslogger pipe, so the pipe
-    * chunking protocol isn't disturbed. Non-logpipe data gets translated on
-    * redirection (e.g. via pg_ctl -l) anyway.
-    */
-#ifdef WIN32
-   _setmode(fileno(stderr), _O_BINARY);
-#endif
-
-   /* We don't want the postmaster's proc_exit() handlers */
-   on_exit_reset();
-
-   /* Initialize process-local latch support */
-   InitializeLatchSupport();
-   MyLatch = &LocalLatchData;
-   InitLatch(MyLatch);
-
-   /*
-    * If possible, make this process a group leader, so that the postmaster
-    * can signal any child processes too. Not all processes will have
-    * children, but for consistency we make all postmaster child processes do
-    * this.
-    */
-#ifdef HAVE_SETSID
-   if (setsid() < 0)
-       elog(FATAL, "setsid() failed: %m");
-#endif
-
-   /* Request a signal if the postmaster dies, if possible. */
-   PostmasterDeathSignalInit();
-}
-
-/*
- * Initialize the basic environment for a standalone process.
- *
- * argv0 has to be suitable to find the program's executable.
- */
-void
-InitStandaloneProcess(const char *argv0)
-{
-   Assert(!IsPostmasterEnvironment);
-
-   InitProcessGlobals();
-
-   /* Initialize process-local latch support */
-   InitializeLatchSupport();
-   MyLatch = &LocalLatchData;
-   InitLatch(MyLatch);
-
-   /* Compute paths, no postmaster to inherit from */
-   if (my_exec_path[0] == '\0')
-   {
-       if (find_my_exec(argv0, my_exec_path) < 0)
-           elog(FATAL, "%s: could not locate my own executable path",
-                argv0);
-   }
-
-   if (pkglib_path[0] == '\0')
-       get_pkglib_path(my_exec_path, pkglib_path);
-}
-
-void
-SwitchToSharedLatch(void)
-{
-   Assert(MyLatch == &LocalLatchData);
-   Assert(MyProc != NULL);
-
-   MyLatch = &MyProc->procLatch;
-
-   if (FeBeWaitSet)
-       ModifyWaitEvent(FeBeWaitSet, 1, WL_LATCH_SET, MyLatch);
-
-   /*
-    * Set the shared latch as the local one might have been set. This
-    * shouldn't normally be necessary as code is supposed to check the
-    * condition before waiting for the latch, but a bit care can't hurt.
-    */
-   SetLatch(MyLatch);
-}
-
-void
-SwitchBackToLocalLatch(void)
-{
-   Assert(MyLatch != &LocalLatchData);
-   Assert(MyProc != NULL && MyLatch == &MyProc->procLatch);
-
-   MyLatch = &LocalLatchData;
-
-   if (FeBeWaitSet)
-       ModifyWaitEvent(FeBeWaitSet, 1, WL_LATCH_SET, MyLatch);
-
-   SetLatch(MyLatch);
-}
-
 /*
  * GetUserId - get the current effective user ID.
  *
index f985453ec32de6e63f70b314403b707f04ef7f2c..6b9093733fb98e723e5eb8b7166c2d34eb7da354 100644 (file)
@@ -303,8 +303,13 @@ extern char *DatabasePath;
 /* now in utils/init/miscinit.c */
 extern void InitPostmasterChild(void);
 extern void InitStandaloneProcess(const char *argv0);
+extern void SwitchToSharedLatch(void);
+extern void SwitchBackToLocalLatch(void);
 
 extern void SetDatabasePath(const char *path);
+extern void checkDataDir(void);
+extern void SetDataDir(const char *dir);
+extern void ChangeToDataDir(void);
 
 extern char *GetUserNameFromId(Oid roleid, bool noerr);
 extern Oid GetUserId(void);
@@ -324,13 +329,6 @@ extern void SetSessionAuthorization(Oid userid, bool is_superuser);
 extern Oid GetCurrentRoleId(void);
 extern void SetCurrentRoleId(Oid roleid, bool is_superuser);
 
-extern void checkDataDir(void);
-extern void SetDataDir(const char *dir);
-extern void ChangeToDataDir(void);
-
-extern void SwitchToSharedLatch(void);
-extern void SwitchBackToLocalLatch(void);
-
 /* in utils/misc/superuser.c */
 extern bool superuser(void);   /* current user is superuser */
 extern bool superuser_arg(Oid roleid); /* given user is superuser */