* Postmaster main entry point */
| 701 | * Postmaster main entry point |
| 702 | */ |
| 703 | void |
| 704 | PostmasterMain(int argc, char *argv[]) |
| 705 | { |
| 706 | int opt; |
| 707 | int status; |
| 708 | char *userDoption = NULL; |
| 709 | bool listen_addr_saved = false; |
| 710 | int i; |
| 711 | char *output_config_variable = NULL; |
| 712 | |
| 713 | InitProcessGlobals(); |
| 714 | |
| 715 | PostmasterPid = MyProcPid; |
| 716 | |
| 717 | IsPostmasterEnvironment = true; |
| 718 | |
| 719 | /* |
| 720 | * We should not be creating any files or directories before we check the |
| 721 | * data directory (see checkDataDir()), but just in case set the umask to |
| 722 | * the most restrictive (owner-only) permissions. |
| 723 | * |
| 724 | * checkDataDir() will reset the umask based on the data directory |
| 725 | * permissions. |
| 726 | */ |
| 727 | umask(PG_MODE_MASK_OWNER); |
| 728 | |
| 729 | /* |
| 730 | * Initialize random(3) so we don't get the same values in every run. |
| 731 | * |
| 732 | * Note: the seed is pretty predictable from externally-visible facts such |
| 733 | * as postmaster start time, so avoid using random() for security-critical |
| 734 | * random values during postmaster startup. At the time of first |
| 735 | * connection, PostmasterRandom will select a hopefully-more-random seed. |
| 736 | */ |
| 737 | srandom((unsigned int) (MyProcPid ^ MyStartTime)); |
| 738 | |
| 739 | /* |
| 740 | * By default, palloc() requests in the postmaster will be allocated in |
| 741 | * the PostmasterContext, which is space that can be recycled by backends. |
| 742 | * Allocated data that needs to be available to backends should be |
| 743 | * allocated in TopMemoryContext. |
| 744 | */ |
| 745 | PostmasterContext = AllocSetContextCreate(TopMemoryContext, |
| 746 | "Postmaster", |
| 747 | ALLOCSET_DEFAULT_SIZES); |
| 748 | MemoryContextSwitchTo(PostmasterContext); |
| 749 | |
| 750 | /* Initialize paths to installation files */ |
| 751 | getInstallationPaths(argv[0]); |
| 752 | |
| 753 | /* |
| 754 | * Set up signal handlers for the postmaster process. |
| 755 | * |
| 756 | * In the postmaster, we use pqsignal_pm() rather than pqsignal() (which |
| 757 | * is used by all child processes and client processes). That has a |
| 758 | * couple of special behaviors: |
| 759 | * |
| 760 | * 1. We tell sigaction() to block all signals for the duration of the |
no test coverage detected