13
13
*
14
14
* Copyright (c) 2001-2003, PostgreSQL Global Development Group
15
15
*
16
- * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.58 2004/02/02 16:37:46 momjian Exp $
16
+ * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.59 2004/03/09 05:11:52 momjian Exp $
17
17
* ----------
18
18
*/
19
19
#include "postgres.h"
51
51
#include "utils/ps_status.h"
52
52
#include "utils/syscache.h"
53
53
54
+ #ifdef EXEC_BACKEND
55
+ #include "utils/guc.h"
56
+ #endif
57
+
54
58
#ifdef WIN32
55
59
extern pid_t win32_forkexec (const char * path , char * argv []);
56
60
#endif
@@ -158,6 +162,17 @@ extern int pgpipe(int handles[2]); /* pgpipe() is in /src/port */
158
162
* ------------------------------------------------------------
159
163
*/
160
164
165
+ #ifdef EXEC_BACKEND
166
+
167
+ void
168
+ pgstat_init_forkexec_backend (void )
169
+ {
170
+ Assert (DataDir != NULL );
171
+ snprintf (pgStat_fname , MAXPGPATH ,
172
+ PGSTAT_STAT_FILENAME , DataDir );
173
+ }
174
+
175
+ #endif
161
176
162
177
/* ----------
163
178
* pgstat_init() -
@@ -364,9 +379,9 @@ static pid_t
364
379
pgstat_forkexec (STATS_PROCESS_TYPE procType )
365
380
{
366
381
pid_t pid ;
367
- char * av [11 ];
382
+ char * av [13 ];
368
383
int ac = 0 , bufc = 0 , i ;
369
- char pgstatBuf [8 ][MAXPGPATH ];
384
+ char pgstatBuf [10 ][MAXPGPATH ];
370
385
371
386
av [ac ++ ] = "postgres" ;
372
387
switch (procType )
@@ -391,11 +406,15 @@ pgstat_forkexec(STATS_PROCESS_TYPE procType)
391
406
snprintf (pgstatBuf [bufc ++ ],MAXPGPATH ,"%d" ,pgStatPipe [0 ]);
392
407
snprintf (pgstatBuf [bufc ++ ],MAXPGPATH ,"%d" ,pgStatPipe [1 ]);
393
408
409
+ /* + misc */
410
+ snprintf (pgstatBuf [bufc ++ ],MAXPGPATH ,"%d" ,MaxBackends );
411
+
394
412
/* + the pstat file names, and postgres pathname */
395
413
/* FIXME: [fork/exec] whitespaces in directories? */
396
414
snprintf (pgstatBuf [bufc ++ ],MAXPGPATH ,"%s" ,pgStat_tmpfname );
397
415
snprintf (pgstatBuf [bufc ++ ],MAXPGPATH ,"%s" ,pgStat_fname );
398
416
snprintf (pgstatBuf [bufc ++ ],MAXPGPATH ,"%s" ,pg_pathname );
417
+ snprintf (pgstatBuf [bufc ++ ],MAXPGPATH ,"%s" ,DataDir );
399
418
400
419
/* Add to the arg list */
401
420
Assert (bufc <= lengthof (pgstatBuf ));
@@ -427,16 +446,20 @@ pgstat_forkexec(STATS_PROCESS_TYPE procType)
427
446
static void
428
447
pgstat_parseArgs (PGSTAT_FORK_ARGS )
429
448
{
430
- Assert (argc == 8 );
449
+ Assert (argc == 10 );
431
450
argc = 0 ;
432
451
pgStatSock = atoi (argv [argc ++ ]);
433
452
pgStatPmPipe [0 ] = atoi (argv [argc ++ ]);
434
453
pgStatPmPipe [1 ] = atoi (argv [argc ++ ]);
435
454
pgStatPipe [0 ] = atoi (argv [argc ++ ]);
436
455
pgStatPipe [1 ] = atoi (argv [argc ++ ]);
456
+ MaxBackends = atoi (argv [argc ++ ]);
437
457
strncpy (pgStat_tmpfname ,argv [argc ++ ],MAXPGPATH );
438
458
strncpy (pgStat_fname , argv [argc ++ ],MAXPGPATH );
439
459
strncpy (pg_pathname , argv [argc ++ ],MAXPGPATH );
460
+ DataDir = strdup (argv [argc ++ ]);
461
+
462
+ read_nondefault_variables ();
440
463
}
441
464
442
465
#endif
@@ -504,7 +527,7 @@ pgstat_start(void)
504
527
#endif
505
528
506
529
#ifdef EXEC_BACKEND
507
- switch ((pgStatSock = (int ) pgstat_forkexec (STAT_PROC_BUFFER )))
530
+ switch ((pgStatPid = (int ) pgstat_forkexec (STAT_PROC_BUFFER )))
508
531
#else
509
532
switch ((pgStatPid = (int ) fork ()))
510
533
#endif
@@ -1344,6 +1367,10 @@ pgstat_mainInit(void)
1344
1367
/* In EXEC case we will not have inherited these settings */
1345
1368
IsPostmasterEnvironment = true;
1346
1369
whereToSendOutput = None ;
1370
+
1371
+ /* Setup global context */
1372
+ MemoryContextInit (); /* before any elog'ing can occur */
1373
+ InitializeGUCOptions ();
1347
1374
#endif
1348
1375
1349
1376
MyProcPid = getpid (); /* reset MyProcPid */
@@ -1382,7 +1409,6 @@ NON_EXEC_STATIC void
1382
1409
pgstat_main (PGSTAT_FORK_ARGS )
1383
1410
{
1384
1411
pgstat_mainInit (); /* Note: for *both* EXEC_BACKEND and regular cases */
1385
-
1386
1412
#ifdef EXEC_BACKEND
1387
1413
pgstat_parseArgs (argc ,argv );
1388
1414
#endif
@@ -1458,9 +1484,7 @@ pgstat_mainChild(PGSTAT_FORK_ARGS)
1458
1484
HASHCTL hash_ctl ;
1459
1485
1460
1486
#ifdef EXEC_BACKEND
1461
- MemoryContextInit (); /* before any elog'ing can occur */
1462
-
1463
- pgstat_mainInit ();
1487
+ pgstat_mainInit (); /* Note: only in EXEC_BACKEND case */
1464
1488
pgstat_parseArgs (argc ,argv );
1465
1489
#else
1466
1490
MyProcPid = getpid (); /* reset MyProcPid */
0 commit comments