* Initialize the basic environment for a postmaster child * * Should be called as early as possible after the child's startup. */
| 101 | * Should be called as early as possible after the child's startup. |
| 102 | */ |
| 103 | void |
| 104 | InitPostmasterChild(void) |
| 105 | { |
| 106 | IsUnderPostmaster = true; /* we are a postmaster subprocess now */ |
| 107 | |
| 108 | /* |
| 109 | * Set reference point for stack-depth checking. This might seem |
| 110 | * redundant in !EXEC_BACKEND builds; but it's not because the postmaster |
| 111 | * launches its children from signal handlers, so we might be running on |
| 112 | * an alternative stack. |
| 113 | */ |
| 114 | (void) set_stack_base(); |
| 115 | |
| 116 | InitProcessGlobals(); |
| 117 | |
| 118 | /* |
| 119 | * make sure stderr is in binary mode before anything can possibly be |
| 120 | * written to it, in case it's actually the syslogger pipe, so the pipe |
| 121 | * chunking protocol isn't disturbed. Non-logpipe data gets translated on |
| 122 | * redirection (e.g. via pg_ctl -l) anyway. |
| 123 | */ |
| 124 | #ifdef WIN32 |
| 125 | _setmode(fileno(stderr), _O_BINARY); |
| 126 | #endif |
| 127 | |
| 128 | /* We don't want the postmaster's proc_exit() handlers */ |
| 129 | on_exit_reset(); |
| 130 | |
| 131 | /* In EXEC_BACKEND case we will not have inherited BlockSig etc values */ |
| 132 | #ifdef EXEC_BACKEND |
| 133 | pqinitmask(); |
| 134 | #endif |
| 135 | |
| 136 | /* Initialize process-local latch support */ |
| 137 | InitializeLatchSupport(); |
| 138 | MyLatch = &LocalLatchData; |
| 139 | InitLatch(MyLatch); |
| 140 | InitializeLatchWaitSet(); |
| 141 | |
| 142 | /* |
| 143 | * If possible, make this process a group leader, so that the postmaster |
| 144 | * can signal any child processes too. Not all processes will have |
| 145 | * children, but for consistency we make all postmaster child processes do |
| 146 | * this. |
| 147 | */ |
| 148 | #ifdef HAVE_SETSID |
| 149 | if (setsid() < 0) |
| 150 | elog(FATAL, "setsid() failed: %m"); |
| 151 | #endif |
| 152 | |
| 153 | /* |
| 154 | * Every postmaster child process is expected to respond promptly to |
| 155 | * SIGQUIT at all times. Therefore we centrally remove SIGQUIT from |
| 156 | * BlockSig and install a suitable signal handler. (Client-facing |
| 157 | * processes may choose to replace this default choice of handler with |
| 158 | * quickdie().) All other blockable signals remain blocked for now. |
| 159 | */ |
| 160 | pqsignal(SIGQUIT, SignalHandlerForCrashExit); |
no test coverage detected