/* Setup essential subsystems (to ensure elog() behaves sanely) */
InitializeGUCOptions();
+ /* Check we got appropriate args */
+ if (argc < 3)
+ elog(FATAL, "invalid subpostmaster invocation");
+
/* Read in the variables file */
memset(&port, 0, sizeof(Port));
read_backend_variables(argv[2], &port);
+ /* Close the postmaster's sockets (as soon as we know them) */
+ ClosePostmasterPorts(strcmp(argv[1], "--forklog") == 0);
+
/*
* Set reference point for stack-depth checking
*/
errmsg("out of memory")));
#endif
- /* Check we got appropriate args */
- if (argc < 3)
- elog(FATAL, "invalid subpostmaster invocation");
-
/*
* If appropriate, physically re-attach to shared memory segment. We want
* to do this before going any further to ensure that we can attach at the
* same address the postmaster used. On the other hand, if we choose not
* to re-attach, we may have other cleanup to do.
+ *
+ * If testing EXEC_BACKEND on Linux, you should run this as root before
+ * starting the postmaster:
+ *
+ * echo 0 >/proc/sys/kernel/randomize_va_space
+ *
+ * This prevents using randomized stack and code addresses that cause the
+ * child process's memory map to be different from the parent's, making it
+ * sometimes impossible to attach to shared memory at the desired address.
+ * Return the setting to its old value (usually '1' or '2') when finished.
*/
if (strcmp(argv[1], "--forkbackend") == 0 ||
strcmp(argv[1], "--forkavlauncher") == 0 ||
{
Assert(argc == 3); /* shouldn't be any more args */
- /* Close the postmaster's sockets */
- ClosePostmasterPorts(false);
-
/*
* Need to reinitialize the SSL library in the backend, since the
* context structures contain function pointers and cannot be passed
/* Need a PGPROC to run CreateSharedMemoryAndSemaphores */
InitProcess();
- /*
- * Attach process to shared data structures. If testing EXEC_BACKEND
- * on Linux, you must run this as root before starting the postmaster:
- *
- * echo 0 >/proc/sys/kernel/randomize_va_space
- *
- * This prevents a randomized stack base address that causes child
- * shared memory to be at a different address than the parent, making
- * it impossible to attached to shared memory. Return the value to
- * '1' when finished.
- */
+ /* Attach process to shared data structures */
CreateSharedMemoryAndSemaphores(false, 0);
/* And run the backend */
}
if (strcmp(argv[1], "--forkboot") == 0)
{
- /* Close the postmaster's sockets */
- ClosePostmasterPorts(false);
-
/* Restore basic shared memory pointers */
InitShmemAccess(UsedShmemSegAddr);
}
if (strcmp(argv[1], "--forkavlauncher") == 0)
{
- /* Close the postmaster's sockets */
- ClosePostmasterPorts(false);
-
/* Restore basic shared memory pointers */
InitShmemAccess(UsedShmemSegAddr);
}
if (strcmp(argv[1], "--forkavworker") == 0)
{
- /* Close the postmaster's sockets */
- ClosePostmasterPorts(false);
-
/* Restore basic shared memory pointers */
InitShmemAccess(UsedShmemSegAddr);
/* do this as early as possible; in particular, before InitProcess() */
IsBackgroundWorker = true;
- /* Close the postmaster's sockets */
- ClosePostmasterPorts(false);
-
/* Restore basic shared memory pointers */
InitShmemAccess(UsedShmemSegAddr);
}
if (strcmp(argv[1], "--forkarch") == 0)
{
- /* Close the postmaster's sockets */
- ClosePostmasterPorts(false);
-
/* Do not want to attach to shared memory */
PgArchiverMain(argc, argv); /* does not return */
}
if (strcmp(argv[1], "--forkcol") == 0)
{
- /* Close the postmaster's sockets */
- ClosePostmasterPorts(false);
-
/* Do not want to attach to shared memory */
PgstatCollectorMain(argc, argv); /* does not return */
}
if (strcmp(argv[1], "--forklog") == 0)
{
- /* Close the postmaster's sockets */
- ClosePostmasterPorts(true);
-
/* Do not want to attach to shared memory */
SysLoggerMain(argc, argv); /* does not return */