37
37
*
38
38
*
39
39
* IDENTIFICATION
40
- * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.316 2003/05/02 21:52:42 momjian Exp $
40
+ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.317 2003/05/02 21:59:31 momjian Exp $
41
41
*
42
42
* NOTES
43
43
*
@@ -172,13 +172,6 @@ static int ServerSock_INET = INVALID_SOCK; /* stream socket server */
172
172
static int ServerSock_UNIX = INVALID_SOCK ; /* stream socket server */
173
173
#endif
174
174
175
- /* Used to reduce macros tests */
176
- #ifdef EXEC_BACKEND
177
- const bool ExecBackend = true;
178
- #else
179
- const bool ExecBackend = false;
180
- #endif
181
-
182
175
/*
183
176
* Set by the -o option
184
177
*/
@@ -263,11 +256,12 @@ static void dummy_handler(SIGNAL_ARGS);
263
256
static void CleanupProc (int pid , int exitstatus );
264
257
static void LogChildExit (int lev , const char * procname ,
265
258
int pid , int exitstatus );
266
- static int DoBackend (Port * port );
259
+ static int BackendFinalize (Port * port );
267
260
void ExitPostmaster (int status );
268
261
static void usage (const char * );
269
262
static int ServerLoop (void );
270
263
static int BackendStartup (Port * port );
264
+ static void BackendFork (Port * port , Backend * bn );
271
265
static int ProcessStartupPacket (Port * port , bool SSLdone );
272
266
static void processCancelRequest (Port * port , void * pkt );
273
267
static int initMasks (fd_set * rmask , fd_set * wmask );
@@ -577,6 +571,9 @@ PostmasterMain(int argc, char *argv[])
577
571
SetDataDir (potential_DataDir );
578
572
579
573
ProcessConfigFile (PGC_POSTMASTER );
574
+ #ifdef EXEC_BACKEND
575
+ write_nondefault_variables (PGC_POSTMASTER );
576
+ #endif
580
577
581
578
/*
582
579
* Check for invalid combinations of GUC settings.
@@ -1238,7 +1235,7 @@ ProcessStartupPacket(Port *port, bool SSLdone)
1238
1235
* Now fetch parameters out of startup packet and save them into the
1239
1236
* Port structure. All data structures attached to the Port struct
1240
1237
* must be allocated in TopMemoryContext so that they won't disappear
1241
- * when we pass them to PostgresMain (see DoBackend ). We need not worry
1238
+ * when we pass them to PostgresMain (see BackendFinalize ). We need not worry
1242
1239
* about leaking this storage on failure, since we aren't in the postmaster
1243
1240
* process anymore.
1244
1241
*/
@@ -1410,11 +1407,7 @@ processCancelRequest(Port *port, void *pkt)
1410
1407
elog (DEBUG1 , "processCancelRequest: CheckPointPID in cancel request for process %d" , backendPID );
1411
1408
return ;
1412
1409
}
1413
- else if (ExecBackend )
1414
- {
1415
- AttachSharedMemoryAndSemaphores ();
1416
- }
1417
-
1410
+
1418
1411
/* See if we have a matching backend */
1419
1412
1420
1413
for (curr = DLGetHead (BackendList ); curr ; curr = DLGetSucc (curr ))
@@ -1579,6 +1572,9 @@ SIGHUP_handler(SIGNAL_ARGS)
1579
1572
elog (LOG , "Received SIGHUP, reloading configuration files" );
1580
1573
SignalChildren (SIGHUP );
1581
1574
ProcessConfigFile (PGC_SIGHUP );
1575
+ #ifdef EXEC_BACKEND
1576
+ write_nondefault_variables (PGC_SIGHUP );
1577
+ #endif
1582
1578
load_hba ();
1583
1579
load_ident ();
1584
1580
}
@@ -2064,28 +2060,7 @@ BackendStartup(Port *port)
2064
2060
pid = fork ();
2065
2061
2066
2062
if (pid == 0 ) /* child */
2067
- {
2068
- int status ;
2069
-
2070
- #ifdef LINUX_PROFILE
2071
- setitimer (ITIMER_PROF , & prof_itimer , NULL );
2072
- #endif
2073
-
2074
- #ifdef __BEOS__
2075
- /* Specific beos backend startup actions */
2076
- beos_backend_startup ();
2077
- #endif
2078
- free (bn );
2079
-
2080
- status = DoBackend (port );
2081
- if (status != 0 )
2082
- {
2083
- elog (LOG , "connection startup failed" );
2084
- proc_exit (status );
2085
- }
2086
- else
2087
- proc_exit (0 );
2088
- }
2063
+ BackendFork (port , bn ); /* never returns */
2089
2064
2090
2065
/* in parent, error */
2091
2066
if (pid < 0 )
@@ -2119,6 +2094,31 @@ BackendStartup(Port *port)
2119
2094
}
2120
2095
2121
2096
2097
+ static void
2098
+ BackendFork (Port * port , Backend * bn )
2099
+ {
2100
+ int status ;
2101
+
2102
+ #ifdef LINUX_PROFILE
2103
+ setitimer (ITIMER_PROF , & prof_itimer , NULL );
2104
+ #endif
2105
+
2106
+ #ifdef __BEOS__
2107
+ /* Specific beos backend startup actions */
2108
+ beos_backend_startup ();
2109
+ #endif
2110
+ free (bn );
2111
+
2112
+ status = BackendFinalize (port );
2113
+ if (status != 0 )
2114
+ {
2115
+ elog (LOG , "connection startup failed" );
2116
+ proc_exit (status );
2117
+ }
2118
+ else
2119
+ proc_exit (0 );
2120
+ }
2121
+
2122
2122
/*
2123
2123
* Try to report backend fork() failure to client before we close the
2124
2124
* connection. Since we do not care to risk blocking the postmaster on
@@ -2184,7 +2184,7 @@ split_opts(char **argv, int *argcp, char *s)
2184
2184
}
2185
2185
2186
2186
/*
2187
- * DoBackend -- perform authentication, and if successful, set up the
2187
+ * BackendFinalize -- perform authentication, and if successful, set up the
2188
2188
* backend's argument list and invoke backend main().
2189
2189
*
2190
2190
* This used to perform an execv() but we no longer exec the backend;
@@ -2195,7 +2195,7 @@ split_opts(char **argv, int *argcp, char *s)
2195
2195
* If PostgresMain() fails, return status.
2196
2196
*/
2197
2197
static int
2198
- DoBackend (Port * port )
2198
+ BackendFinalize (Port * port )
2199
2199
{
2200
2200
char * remote_host ;
2201
2201
char * * av ;
@@ -2232,6 +2232,10 @@ DoBackend(Port *port)
2232
2232
/* Reset MyProcPid to new backend's pid */
2233
2233
MyProcPid = getpid ();
2234
2234
2235
+ #ifdef EXEC_BACKEND
2236
+ read_nondefault_variables ();
2237
+ #endif
2238
+
2235
2239
/*
2236
2240
* Initialize libpq and enable reporting of elog errors to the client.
2237
2241
* Must do this now because authentication uses libpq to send
@@ -2259,7 +2263,7 @@ DoBackend(Port *port)
2259
2263
unsigned short remote_port ;
2260
2264
char * host_addr ;
2261
2265
#ifdef HAVE_IPV6
2262
- char ip_hostinfo [INET6_ADDRSTRLEN ];
2266
+ char ip_hostinfo [INET6_ADDRSTRLEN ];
2263
2267
#else
2264
2268
char ip_hostinfo [INET_ADDRSTRLEN ];
2265
2269
#endif
@@ -2305,7 +2309,7 @@ DoBackend(Port *port)
2305
2309
}
2306
2310
else
2307
2311
{
2308
- /* not AF_INET */
2312
+ /* not AF_INET */
2309
2313
remote_host = "[local]" ;
2310
2314
2311
2315
if (Log_connections )
@@ -2329,7 +2333,7 @@ DoBackend(Port *port)
2329
2333
* indefinitely. PreAuthDelay doesn't count against the time limit.
2330
2334
*/
2331
2335
if (!enable_sig_alarm (AuthenticationTimeout * 1000 , false))
2332
- elog (FATAL , "DoBackend : Unable to set timer for auth timeout" );
2336
+ elog (FATAL , "BackendFinalize : Unable to set timer for auth timeout" );
2333
2337
2334
2338
/*
2335
2339
* Receive the startup packet (which might turn out to be a cancel
@@ -2358,7 +2362,7 @@ DoBackend(Port *port)
2358
2362
* SIGTERM/SIGQUIT again until backend startup is complete.
2359
2363
*/
2360
2364
if (!disable_sig_alarm (false))
2361
- elog (FATAL , "DoBackend : Unable to disable timer for auth timeout" );
2365
+ elog (FATAL , "BackendFinalize : Unable to disable timer for auth timeout" );
2362
2366
PG_SETMASK (& BlockSig );
2363
2367
2364
2368
if (Log_connections )
0 commit comments