Skip to content

Commit 8567bb2

Browse files
committed
Corrects a typo, introduces missing variables, and rearranges the
initialization of stats process under EXEC_BACKEND. [A cleaner, rationalized approach to stat/backend/SSDataBase child processes under EXEC_BACKEND is on my TODO list. However this patch takes care of immediate concerns (ie. stats test now passes under win32)] Claudio Natoli
1 parent eeec317 commit 8567bb2

File tree

3 files changed

+41
-11
lines changed

3 files changed

+41
-11
lines changed

src/backend/postmaster/pgstat.c

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* Copyright (c) 2001-2003, PostgreSQL Global Development Group
1515
*
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 $
1717
* ----------
1818
*/
1919
#include "postgres.h"
@@ -51,6 +51,10 @@
5151
#include "utils/ps_status.h"
5252
#include "utils/syscache.h"
5353

54+
#ifdef EXEC_BACKEND
55+
#include "utils/guc.h"
56+
#endif
57+
5458
#ifdef WIN32
5559
extern pid_t win32_forkexec(const char* path, char *argv[]);
5660
#endif
@@ -158,6 +162,17 @@ extern int pgpipe(int handles[2]); /* pgpipe() is in /src/port */
158162
* ------------------------------------------------------------
159163
*/
160164

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
161176

162177
/* ----------
163178
* pgstat_init() -
@@ -364,9 +379,9 @@ static pid_t
364379
pgstat_forkexec(STATS_PROCESS_TYPE procType)
365380
{
366381
pid_t pid;
367-
char *av[11];
382+
char *av[13];
368383
int ac = 0, bufc = 0, i;
369-
char pgstatBuf[8][MAXPGPATH];
384+
char pgstatBuf[10][MAXPGPATH];
370385

371386
av[ac++] = "postgres";
372387
switch (procType)
@@ -391,11 +406,15 @@ pgstat_forkexec(STATS_PROCESS_TYPE procType)
391406
snprintf(pgstatBuf[bufc++],MAXPGPATH,"%d",pgStatPipe[0]);
392407
snprintf(pgstatBuf[bufc++],MAXPGPATH,"%d",pgStatPipe[1]);
393408

409+
/* + misc */
410+
snprintf(pgstatBuf[bufc++],MAXPGPATH,"%d",MaxBackends);
411+
394412
/* + the pstat file names, and postgres pathname */
395413
/* FIXME: [fork/exec] whitespaces in directories? */
396414
snprintf(pgstatBuf[bufc++],MAXPGPATH,"%s",pgStat_tmpfname);
397415
snprintf(pgstatBuf[bufc++],MAXPGPATH,"%s",pgStat_fname);
398416
snprintf(pgstatBuf[bufc++],MAXPGPATH,"%s",pg_pathname);
417+
snprintf(pgstatBuf[bufc++],MAXPGPATH,"%s",DataDir);
399418

400419
/* Add to the arg list */
401420
Assert(bufc <= lengthof(pgstatBuf));
@@ -427,16 +446,20 @@ pgstat_forkexec(STATS_PROCESS_TYPE procType)
427446
static void
428447
pgstat_parseArgs(PGSTAT_FORK_ARGS)
429448
{
430-
Assert(argc == 8);
449+
Assert(argc == 10);
431450
argc = 0;
432451
pgStatSock = atoi(argv[argc++]);
433452
pgStatPmPipe[0] = atoi(argv[argc++]);
434453
pgStatPmPipe[1] = atoi(argv[argc++]);
435454
pgStatPipe[0] = atoi(argv[argc++]);
436455
pgStatPipe[1] = atoi(argv[argc++]);
456+
MaxBackends = atoi(argv[argc++]);
437457
strncpy(pgStat_tmpfname,argv[argc++],MAXPGPATH);
438458
strncpy(pgStat_fname, argv[argc++],MAXPGPATH);
439459
strncpy(pg_pathname, argv[argc++],MAXPGPATH);
460+
DataDir = strdup(argv[argc++]);
461+
462+
read_nondefault_variables();
440463
}
441464

442465
#endif
@@ -504,7 +527,7 @@ pgstat_start(void)
504527
#endif
505528

506529
#ifdef EXEC_BACKEND
507-
switch ((pgStatSock = (int) pgstat_forkexec(STAT_PROC_BUFFER)))
530+
switch ((pgStatPid = (int) pgstat_forkexec(STAT_PROC_BUFFER)))
508531
#else
509532
switch ((pgStatPid = (int) fork()))
510533
#endif
@@ -1344,6 +1367,10 @@ pgstat_mainInit(void)
13441367
/* In EXEC case we will not have inherited these settings */
13451368
IsPostmasterEnvironment = true;
13461369
whereToSendOutput = None;
1370+
1371+
/* Setup global context */
1372+
MemoryContextInit(); /* before any elog'ing can occur */
1373+
InitializeGUCOptions();
13471374
#endif
13481375

13491376
MyProcPid = getpid(); /* reset MyProcPid */
@@ -1382,7 +1409,6 @@ NON_EXEC_STATIC void
13821409
pgstat_main(PGSTAT_FORK_ARGS)
13831410
{
13841411
pgstat_mainInit(); /* Note: for *both* EXEC_BACKEND and regular cases */
1385-
13861412
#ifdef EXEC_BACKEND
13871413
pgstat_parseArgs(argc,argv);
13881414
#endif
@@ -1458,9 +1484,7 @@ pgstat_mainChild(PGSTAT_FORK_ARGS)
14581484
HASHCTL hash_ctl;
14591485

14601486
#ifdef EXEC_BACKEND
1461-
MemoryContextInit(); /* before any elog'ing can occur */
1462-
1463-
pgstat_mainInit();
1487+
pgstat_mainInit(); /* Note: only in EXEC_BACKEND case */
14641488
pgstat_parseArgs(argc,argv);
14651489
#else
14661490
MyProcPid = getpid(); /* reset MyProcPid */

src/backend/postmaster/postmaster.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.371 2004/03/09 04:43:06 momjian Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.372 2004/03/09 05:11:52 momjian Exp $
4141
*
4242
* NOTES
4343
*
@@ -2721,6 +2721,9 @@ SubPostmasterMain(int argc, char* argv[])
27212721
read_nondefault_variables();
27222722
read_backend_variables(backendID,&port);
27232723

2724+
/* Remaining initialization */
2725+
pgstat_init_forkexec_backend();
2726+
27242727
/* FIXME: [fork/exec] Ugh */
27252728
load_hba();
27262729
load_ident();

src/include/pgstat.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright (c) 2001-2003, PostgreSQL Global Development Group
77
*
8-
* $PostgreSQL: pgsql/src/include/pgstat.h,v 1.20 2004/03/02 18:37:52 momjian Exp $
8+
* $PostgreSQL: pgsql/src/include/pgstat.h,v 1.21 2004/03/09 05:11:53 momjian Exp $
99
* ----------
1010
*/
1111
#ifndef PGSTAT_H
@@ -368,6 +368,9 @@ extern void pgstat_mainChild(PGSTAT_FORK_ARGS);
368368
* Functions called from postmaster
369369
* ----------
370370
*/
371+
#ifdef EXEC_BACKEND
372+
extern void pgstat_init_forkexec_backend(void);
373+
#endif
371374
extern void pgstat_init(void);
372375
extern void pgstat_start(void);
373376
extern bool pgstat_ispgstat(int pid);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy