8
8
* Portions Copyright (c) 1994, Regents of the University of California
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.180 2004/05/27 17 :12:49 tgl Exp $
11
+ * $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.181 2004/05/28 05 :12:45 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
43
43
#include "utils/fmgroids.h"
44
44
#include "utils/guc.h"
45
45
#include "utils/lsyscache.h"
46
+ #include "utils/ps_status.h"
46
47
#include "utils/relcache.h"
47
48
48
49
49
50
#define ALLOC (t , c ) ((t *) calloc((unsigned)(c), sizeof(t)))
50
51
51
- #ifdef EXEC_BACKEND
52
- typedef struct Port Port ;
53
- extern void SSDataBaseInit (int );
54
- extern void read_backend_variables (unsigned long , Port * );
55
- #endif
56
-
57
52
extern int Int_yyparse (void );
58
53
static hashnode * AddStr (char * str , int strlength , int mderef );
59
54
static Form_pg_attribute AllocateAttribute (void );
@@ -233,42 +228,37 @@ usage(void)
233
228
}
234
229
235
230
236
-
237
- int
238
- BootstrapMain (int argc , char * argv [])
239
- /* ----------------------------------------------------------------
240
- * The main loop for handling the backend in bootstrap mode
241
- * the bootstrap mode is used to initialize the template database
242
- * the bootstrap backend doesn't speak SQL, but instead expects
231
+ /*
232
+ * The main loop for running the backend in bootstrap mode
233
+ *
234
+ * The bootstrap mode is used to initialize the template database.
235
+ * The bootstrap backend doesn't speak SQL, but instead expects
243
236
* commands in a special bootstrap language.
244
237
*
245
- * The arguments passed in to BootstrapMain are the run-time arguments
246
- * without the argument '-boot', the caller is required to have
247
- * removed -boot from the run-time args
248
- * ----------------------------------------------------------------
238
+ * For historical reasons, BootstrapMain is also used as the control
239
+ * routine for non-backend subprocesses launched by the postmaster,
240
+ * such as startup and shutdown.
249
241
*/
242
+ int
243
+ BootstrapMain (int argc , char * argv [])
250
244
{
251
245
int i ;
252
246
char * dbname ;
253
247
int flag ;
254
248
int xlogop = BS_XLOG_NOP ;
255
249
char * potential_DataDir = NULL ;
256
- #ifdef EXEC_BACKEND
257
- unsigned long backendID = 0 ;
258
- #endif
259
250
260
251
/*
261
252
* initialize globals
262
253
*/
263
-
264
254
MyProcPid = getpid ();
265
255
266
256
/*
267
257
* Fire up essential subsystems: error and memory management
268
258
*
269
259
* If we are running under the postmaster, this is done already.
270
260
*/
271
- if (!IsUnderPostmaster || ExecBackend )
261
+ if (!IsUnderPostmaster )
272
262
MemoryContextInit ();
273
263
274
264
/*
@@ -284,6 +274,13 @@ BootstrapMain(int argc, char *argv[])
284
274
* variable */
285
275
}
286
276
277
+ /* Ignore the initial -boot argument, if present */
278
+ if (argc > 1 && strcmp (argv [1 ], "-boot" ) == 0 )
279
+ {
280
+ argv ++ ;
281
+ argc -- ;
282
+ }
283
+
287
284
while ((flag = getopt (argc , argv , "B:c:d:D:Fo:p:x:-:" )) != -1 )
288
285
{
289
286
switch (flag )
@@ -315,14 +312,6 @@ BootstrapMain(int argc, char *argv[])
315
312
xlogop = atoi (optarg );
316
313
break ;
317
314
case 'p' :
318
- #ifdef EXEC_BACKEND
319
- {
320
- char buf [MAXPGPATH ];
321
- IsUnderPostmaster = true;
322
- sscanf (optarg ,"%lu,%s" ,& backendID ,buf );
323
- dbname = strdup (buf );
324
- }
325
- #endif
326
315
dbname = strdup (optarg );
327
316
break ;
328
317
case 'B' :
@@ -369,7 +358,7 @@ BootstrapMain(int argc, char *argv[])
369
358
if (!dbname || argc != optind )
370
359
usage ();
371
360
372
- if (!IsUnderPostmaster || ExecBackend )
361
+ if (!IsUnderPostmaster )
373
362
{
374
363
if (!potential_DataDir )
375
364
{
@@ -388,21 +377,43 @@ BootstrapMain(int argc, char *argv[])
388
377
Assert (DataDir );
389
378
ValidatePgVersion (DataDir );
390
379
391
- /* Acquire configuration parameters */
380
+ /*
381
+ * Identify myself via ps
382
+ */
392
383
if (IsUnderPostmaster )
393
384
{
394
- #ifdef EXEC_BACKEND
395
- read_backend_variables (backendID ,NULL );
396
- read_nondefault_variables ();
385
+ const char * statmsg ;
397
386
398
- SSDataBaseInit (xlogop );
399
- #endif
387
+ switch (xlogop )
388
+ {
389
+ case BS_XLOG_STARTUP :
390
+ statmsg = "startup subprocess" ;
391
+ break ;
392
+ case BS_XLOG_CHECKPOINT :
393
+ statmsg = "checkpoint subprocess" ;
394
+ break ;
395
+ case BS_XLOG_BGWRITER :
396
+ statmsg = "bgwriter subprocess" ;
397
+ break ;
398
+ case BS_XLOG_SHUTDOWN :
399
+ statmsg = "shutdown subprocess" ;
400
+ break ;
401
+ default :
402
+ statmsg = "??? subprocess" ;
403
+ break ;
404
+ }
405
+ init_ps_display (statmsg , "" , "" );
406
+ set_ps_display ("" );
400
407
}
401
- else
408
+
409
+ /* Acquire configuration parameters, unless inherited from postmaster */
410
+ if (!IsUnderPostmaster )
411
+ {
402
412
ProcessConfigFile (PGC_POSTMASTER );
403
413
404
- /* If timezone is not set, determine what the OS uses */
405
- pg_timezone_initialize ();
414
+ /* If timezone is not set, determine what the OS uses */
415
+ pg_timezone_initialize ();
416
+ }
406
417
407
418
if (IsUnderPostmaster )
408
419
{
@@ -450,10 +461,6 @@ BootstrapMain(int argc, char *argv[])
450
461
SetProcessingMode (BootstrapProcessing );
451
462
IgnoreSystemIndexes (true);
452
463
453
- #ifdef EXEC_BACKEND
454
- if (IsUnderPostmaster )
455
- CreateSharedMemoryAndSemaphores (false, MaxBackends , 0 );
456
- #endif
457
464
XLOGPathInit ();
458
465
459
466
BaseInit ();
0 commit comments