process startup: Centralize pgwin32_signal_initialize() calls.
authorAndres Freund <[email protected]>
Thu, 5 Aug 2021 19:36:06 +0000 (12:36 -0700)
committerAndres Freund <[email protected]>
Thu, 5 Aug 2021 19:36:06 +0000 (12:36 -0700)
For one, the existing location lead to somewhat awkward code in main(). For
another, the new location is easier to understand anyway.

Author: Andres Freund <[email protected]>
Reviewed-By: Kyotaro Horiguchi <[email protected]>
Reviewed-By: Robert Haas <[email protected]>
Discussion: https://postgr.es/m/20210802164124[email protected]

src/backend/main/main.c
src/backend/postmaster/postmaster.c
src/backend/utils/init/miscinit.c

index 9be397395672640ca3d323c388f5eaf9a7b4c603..3a2a0d598cd967ba817f486545502101627c3197 100644 (file)
@@ -181,35 +181,24 @@ main(int argc, char *argv[])
     * Dispatch to one of various subprograms depending on first argument.
     */
 
-#ifdef EXEC_BACKEND
-   if (argc > 1 && strncmp(argv[1], "--fork", 6) == 0)
-       SubPostmasterMain(argc, argv);  /* does not return */
-#endif
-
-#ifdef WIN32
-
-   /*
-    * Start our win32 signal implementation
-    *
-    * SubPostmasterMain() will do this for itself, but the remaining modes
-    * need it here
-    */
-   pgwin32_signal_initialize();
-#endif
-
    if (argc > 1 && strcmp(argv[1], "--check") == 0)
        BootstrapModeMain(argc, argv, true);
    else if (argc > 1 && strcmp(argv[1], "--boot") == 0)
        BootstrapModeMain(argc, argv, false);
+#ifdef EXEC_BACKEND
+   else if (argc > 1 && strncmp(argv[1], "--fork", 6) == 0)
+       SubPostmasterMain(argc, argv);
+#endif
    else if (argc > 1 && strcmp(argv[1], "--describe-config") == 0)
-       GucInfoMain();          /* does not return */
+       GucInfoMain();
    else if (argc > 1 && strcmp(argv[1], "--single") == 0)
        PostgresMain(argc, argv,
                     NULL,      /* no dbname */
-                    strdup(get_user_name_or_exit(progname)));  /* does not return */
+                    strdup(get_user_name_or_exit(progname)));
    else
-       PostmasterMain(argc, argv); /* does not return */
-   abort();                    /* should not get here */
+       PostmasterMain(argc, argv);
+   /* the functions above should not return */
+   abort();
 }
 
 
index 386469121599f1bd6e525c801123cb46be2e3d3e..18504765c237e1ac1d2829a8b5b9438415e2d74b 100644 (file)
@@ -4905,15 +4905,6 @@ SubPostmasterMain(int argc, char *argv[])
    /* Close the postmaster's sockets (as soon as we know them) */
    ClosePostmasterPorts(strcmp(argv[1], "--forklog") == 0);
 
-   /*
-    * Start our win32 signal implementation. This has to be done after we
-    * read the backend variables, because we need to pick up the signal pipe
-    * from the parent process.
-    */
-#ifdef WIN32
-   pgwin32_signal_initialize();
-#endif
-
    /* Setup as postmaster child */
    InitPostmasterChild();
 
index 8b73850d0df10a9e3c5fec3aca3ca1deda006d9b..88801374b5763d7cc12564d6478354afd81a72f0 100644 (file)
@@ -87,13 +87,23 @@ bool        IgnoreSystemIndexes = false;
 /*
  * Initialize the basic environment for a postmaster child
  *
- * Should be called as early as possible after the child's startup.
+ * Should be called as early as possible after the child's startup. However,
+ * on EXEC_BACKEND builds it does need to be after read_backend_variables().
  */
 void
 InitPostmasterChild(void)
 {
    IsUnderPostmaster = true;   /* we are a postmaster subprocess now */
 
+   /*
+    * Start our win32 signal implementation. This has to be done after we
+    * read the backend variables, because we need to pick up the signal pipe
+    * from the parent process.
+    */
+#ifdef WIN32
+   pgwin32_signal_initialize();
+#endif
+
    /*
     * Set reference point for stack-depth checking. We re-do that even in the
     * !EXEC_BACKEND case, because there are some edge cases where processes
@@ -166,6 +176,13 @@ InitStandaloneProcess(const char *argv0)
 {
    Assert(!IsPostmasterEnvironment);
 
+   /*
+    * Start our win32 signal implementation
+    */
+#ifdef WIN32
+   pgwin32_signal_initialize();
+#endif
+
    InitProcessGlobals();
 
    /* Initialize process-local latch support */