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
This commit is contained in:
Bruce Momjian 2004-03-09 05:11:53 +00:00
parent eeec31774a
commit 8567bb2d06
3 changed files with 41 additions and 11 deletions

View File

@ -13,7 +13,7 @@
*
* Copyright (c) 2001-2003, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.58 2004/02/02 16:37:46 momjian Exp $
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.59 2004/03/09 05:11:52 momjian Exp $
* ----------
*/
#include "postgres.h"
@ -51,6 +51,10 @@
#include "utils/ps_status.h"
#include "utils/syscache.h"
#ifdef EXEC_BACKEND
#include "utils/guc.h"
#endif
#ifdef WIN32
extern pid_t win32_forkexec(const char* path, char *argv[]);
#endif
@ -158,6 +162,17 @@ extern int pgpipe(int handles[2]); /* pgpipe() is in /src/port */
* ------------------------------------------------------------
*/
#ifdef EXEC_BACKEND
void
pgstat_init_forkexec_backend(void)
{
Assert(DataDir != NULL);
snprintf(pgStat_fname, MAXPGPATH,
PGSTAT_STAT_FILENAME, DataDir);
}
#endif
/* ----------
* pgstat_init() -
@ -364,9 +379,9 @@ static pid_t
pgstat_forkexec(STATS_PROCESS_TYPE procType)
{
pid_t pid;
char *av[11];
char *av[13];
int ac = 0, bufc = 0, i;
char pgstatBuf[8][MAXPGPATH];
char pgstatBuf[10][MAXPGPATH];
av[ac++] = "postgres";
switch (procType)
@ -391,11 +406,15 @@ pgstat_forkexec(STATS_PROCESS_TYPE procType)
snprintf(pgstatBuf[bufc++],MAXPGPATH,"%d",pgStatPipe[0]);
snprintf(pgstatBuf[bufc++],MAXPGPATH,"%d",pgStatPipe[1]);
/* + misc */
snprintf(pgstatBuf[bufc++],MAXPGPATH,"%d",MaxBackends);
/* + the pstat file names, and postgres pathname */
/* FIXME: [fork/exec] whitespaces in directories? */
snprintf(pgstatBuf[bufc++],MAXPGPATH,"%s",pgStat_tmpfname);
snprintf(pgstatBuf[bufc++],MAXPGPATH,"%s",pgStat_fname);
snprintf(pgstatBuf[bufc++],MAXPGPATH,"%s",pg_pathname);
snprintf(pgstatBuf[bufc++],MAXPGPATH,"%s",DataDir);
/* Add to the arg list */
Assert(bufc <= lengthof(pgstatBuf));
@ -427,16 +446,20 @@ pgstat_forkexec(STATS_PROCESS_TYPE procType)
static void
pgstat_parseArgs(PGSTAT_FORK_ARGS)
{
Assert(argc == 8);
Assert(argc == 10);
argc = 0;
pgStatSock = atoi(argv[argc++]);
pgStatPmPipe[0] = atoi(argv[argc++]);
pgStatPmPipe[1] = atoi(argv[argc++]);
pgStatPipe[0] = atoi(argv[argc++]);
pgStatPipe[1] = atoi(argv[argc++]);
MaxBackends = atoi(argv[argc++]);
strncpy(pgStat_tmpfname,argv[argc++],MAXPGPATH);
strncpy(pgStat_fname, argv[argc++],MAXPGPATH);
strncpy(pg_pathname, argv[argc++],MAXPGPATH);
DataDir = strdup(argv[argc++]);
read_nondefault_variables();
}
#endif
@ -504,7 +527,7 @@ pgstat_start(void)
#endif
#ifdef EXEC_BACKEND
switch ((pgStatSock = (int) pgstat_forkexec(STAT_PROC_BUFFER)))
switch ((pgStatPid = (int) pgstat_forkexec(STAT_PROC_BUFFER)))
#else
switch ((pgStatPid = (int) fork()))
#endif
@ -1344,6 +1367,10 @@ pgstat_mainInit(void)
/* In EXEC case we will not have inherited these settings */
IsPostmasterEnvironment = true;
whereToSendOutput = None;
/* Setup global context */
MemoryContextInit(); /* before any elog'ing can occur */
InitializeGUCOptions();
#endif
MyProcPid = getpid(); /* reset MyProcPid */
@ -1382,7 +1409,6 @@ NON_EXEC_STATIC void
pgstat_main(PGSTAT_FORK_ARGS)
{
pgstat_mainInit(); /* Note: for *both* EXEC_BACKEND and regular cases */
#ifdef EXEC_BACKEND
pgstat_parseArgs(argc,argv);
#endif
@ -1458,9 +1484,7 @@ pgstat_mainChild(PGSTAT_FORK_ARGS)
HASHCTL hash_ctl;
#ifdef EXEC_BACKEND
MemoryContextInit(); /* before any elog'ing can occur */
pgstat_mainInit();
pgstat_mainInit(); /* Note: only in EXEC_BACKEND case */
pgstat_parseArgs(argc,argv);
#else
MyProcPid = getpid(); /* reset MyProcPid */

View File

@ -37,7 +37,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.371 2004/03/09 04:43:06 momjian Exp $
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.372 2004/03/09 05:11:52 momjian Exp $
*
* NOTES
*
@ -2721,6 +2721,9 @@ SubPostmasterMain(int argc, char* argv[])
read_nondefault_variables();
read_backend_variables(backendID,&port);
/* Remaining initialization */
pgstat_init_forkexec_backend();
/* FIXME: [fork/exec] Ugh */
load_hba();
load_ident();

View File

@ -5,7 +5,7 @@
*
* Copyright (c) 2001-2003, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/include/pgstat.h,v 1.20 2004/03/02 18:37:52 momjian Exp $
* $PostgreSQL: pgsql/src/include/pgstat.h,v 1.21 2004/03/09 05:11:53 momjian Exp $
* ----------
*/
#ifndef PGSTAT_H
@ -368,6 +368,9 @@ extern void pgstat_mainChild(PGSTAT_FORK_ARGS);
* Functions called from postmaster
* ----------
*/
#ifdef EXEC_BACKEND
extern void pgstat_init_forkexec_backend(void);
#endif
extern void pgstat_init(void);
extern void pgstat_start(void);
extern bool pgstat_ispgstat(int pid);