* SubPostmasterMain -- Get the fork/exec'd process into a state equivalent * to what it would be if we'd simply forked on Unix, and then * dispatch to the appropriate place. * * The first two command line arguments are expected to be "--forkFOO" * (where FOO indicates which postmaster child we are to become), and * the name of a variables file that we can read to load data that would *
| 5468 | * subprocess FooMain() routine. |
| 5469 | */ |
| 5470 | void |
| 5471 | SubPostmasterMain(int argc, char *argv[]) |
| 5472 | { |
| 5473 | Port port; |
| 5474 | |
| 5475 | /* In EXEC_BACKEND case we will not have inherited these settings */ |
| 5476 | IsPostmasterEnvironment = true; |
| 5477 | whereToSendOutput = DestNone; |
| 5478 | |
| 5479 | /* Setup essential subsystems (to ensure elog() behaves sanely) */ |
| 5480 | InitializeGUCOptions(); |
| 5481 | |
| 5482 | /* Check we got appropriate args */ |
| 5483 | if (argc < 3) |
| 5484 | elog(FATAL, "invalid subpostmaster invocation"); |
| 5485 | |
| 5486 | /* Read in the variables file */ |
| 5487 | memset(&port, 0, sizeof(Port)); |
| 5488 | read_backend_variables(argv[2], &port); |
| 5489 | |
| 5490 | /* Close the postmaster's sockets (as soon as we know them) */ |
| 5491 | ClosePostmasterPorts(strcmp(argv[1], "--forklog") == 0); |
| 5492 | |
| 5493 | /* |
| 5494 | * Start our win32 signal implementation. This has to be done after we |
| 5495 | * read the backend variables, because we need to pick up the signal pipe |
| 5496 | * from the parent process. |
| 5497 | */ |
| 5498 | #ifdef WIN32 |
| 5499 | pgwin32_signal_initialize(); |
| 5500 | #endif |
| 5501 | |
| 5502 | /* Setup as postmaster child */ |
| 5503 | InitPostmasterChild(); |
| 5504 | |
| 5505 | /* |
| 5506 | * If appropriate, physically re-attach to shared memory segment. We want |
| 5507 | * to do this before going any further to ensure that we can attach at the |
| 5508 | * same address the postmaster used. On the other hand, if we choose not |
| 5509 | * to re-attach, we may have other cleanup to do. |
| 5510 | * |
| 5511 | * If testing EXEC_BACKEND on Linux, you should run this as root before |
| 5512 | * starting the postmaster: |
| 5513 | * |
| 5514 | * echo 0 >/proc/sys/kernel/randomize_va_space |
| 5515 | * |
| 5516 | * This prevents using randomized stack and code addresses that cause the |
| 5517 | * child process's memory map to be different from the parent's, making it |
| 5518 | * sometimes impossible to attach to shared memory at the desired address. |
| 5519 | * Return the setting to its old value (usually '1' or '2') when finished. |
| 5520 | */ |
| 5521 | if (strcmp(argv[1], "--forkbackend") == 0 || |
| 5522 | strcmp(argv[1], "--forkavlauncher") == 0 || |
| 5523 | strcmp(argv[1], "--forkavworker") == 0 || |
| 5524 | strcmp(argv[1], "--forkautovac") == 0 || |
| 5525 | strcmp(argv[1], "--forkglobaldeadlockdetector") == 0 || |
| 5526 | strcmp(argv[1], "--forkboot") == 0 || |
| 5527 | strncmp(argv[1], "--forkbgworker=", 15) == 0) |
no test coverage detected