Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit488f278

Browse files
committed
Final rearrangement of main postgresql child process (ie.
BackendFork/SSDataBase/pgstat) startup, to allow fork/exec calls toclosely mimic (the soon to be provided) Win32 CreateProcess equivalentcalls.Claudio Natoli
1 parent06288d4 commit488f278

File tree

6 files changed

+254
-160
lines changed

6 files changed

+254
-160
lines changed

‎src/backend/bootstrap/bootstrap.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.172 2003/12/25 03:52:50 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.173 2004/01/06 23:15:22 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -51,7 +51,7 @@
5151
#ifdefEXEC_BACKEND
5252
typedefstructPortPort;
5353
externvoidSSDataBaseInit(int);
54-
externvoidread_backend_variables(pid_t,Port*);
54+
externvoidread_backend_variables(unsigned long,Port*);
5555
#endif
5656

5757
externintInt_yyparse(void);
@@ -231,6 +231,9 @@ BootstrapMain(int argc, char *argv[])
231231
intflag;
232232
intxlogop=BS_XLOG_NOP;
233233
char*potential_DataDir=NULL;
234+
#ifdefEXEC_BACKEND
235+
unsigned longbackendID=0;
236+
#endif
234237

235238
/*
236239
* initialize globals
@@ -291,10 +294,15 @@ BootstrapMain(int argc, char *argv[])
291294
break;
292295
case'p':
293296
#ifdefEXEC_BACKEND
294-
IsUnderPostmaster= true;
297+
{
298+
charbuf[MAXPGPATH];
299+
IsUnderPostmaster= true;
300+
sscanf(optarg,"%lu,%s",&backendID,buf);
301+
dbname=strdup(buf);
302+
}
295303
#endif
296304
dbname=strdup(optarg);
297-
break;
305+
break;
298306
case'B':
299307
SetConfigOption("shared_buffers",optarg,PGC_POSTMASTER,PGC_S_ARGV);
300308
break;
@@ -363,7 +371,7 @@ BootstrapMain(int argc, char *argv[])
363371
{
364372
#ifdefEXEC_BACKEND
365373
read_nondefault_variables();
366-
read_backend_variables(getpid(),NULL);
374+
read_backend_variables(backendID,NULL);
367375

368376
SSDataBaseInit(xlogop);
369377
#endif
@@ -431,11 +439,11 @@ BootstrapMain(int argc, char *argv[])
431439
switch (xlogop)
432440
{
433441
caseBS_XLOG_BGWRITER:
434-
InitDummyProcess(DUMMY_PROC_BGWRITER);
442+
InitDummyProcess(DUMMY_PROC_BGWRITER);
435443
break;
436-
444+
437445
default:
438-
InitDummyProcess(DUMMY_PROC_DEFAULT);
446+
InitDummyProcess(DUMMY_PROC_DEFAULT);
439447
break;
440448
}
441449
}

‎src/backend/main/main.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/main/main.c,v 1.69 2003/12/25 03:52:50 momjian Exp $
16+
* $PostgreSQL: pgsql/src/backend/main/main.c,v 1.70 2004/01/06 23:15:22 momjian Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -203,9 +203,9 @@ main(int argc, char *argv[])
203203

204204
/*
205205
* Now dispatch to one of PostmasterMain, PostgresMain, GucInfoMain,
206-
* pgstat_main, pgstat_mainChild or BootstrapMain depending on the
207-
* program name (and possibly first argument) we were called with.
208-
* The lack of consistency here is historical.
206+
*SubPostmasterMain,pgstat_main, pgstat_mainChild or BootstrapMain
207+
*depending on theprogram name (and possibly first argument) we
208+
*were called with.The lack of consistency here is historical.
209209
*/
210210
len=strlen(new_argv[0]);
211211

@@ -223,6 +223,16 @@ main(int argc, char *argv[])
223223
exit(BootstrapMain(argc-1,new_argv+1));
224224

225225
#ifdefEXEC_BACKEND
226+
/*
227+
* If the first argument is "-forkexec", then invoke SubPostmasterMain. Note
228+
* we remove "-forkexec" from the arguments passed on to SubPostmasterMain.
229+
*/
230+
if (argc>1&&strcmp(new_argv[1],"-forkexec")==0)
231+
{
232+
SubPostmasterMain(argc-2,new_argv+2);
233+
exit(0);
234+
}
235+
226236
/*
227237
* If the first argument is "-statBuf", then invoke pgstat_main. Note
228238
* we remove "-statBuf" from the arguments passed on to pgstat_main.

‎src/backend/postmaster/pgstat.c

Lines changed: 38 additions & 32 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.50 2003/12/25 03:52:51 momjian Exp $
16+
*$PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.51 2004/01/06 23:15:22 momjian Exp $
1717
* ----------
1818
*/
1919
#include"postgres.h"
@@ -107,7 +107,7 @@ static char pgStat_fname[MAXPGPATH];
107107
* ----------
108108
*/
109109
#ifdefEXEC_BACKEND
110-
staticvoidpgstat_exec(STATS_PROCESS_TYPEprocType);
110+
staticpid_tpgstat_forkexec(STATS_PROCESS_TYPEprocType);
111111
staticvoidpgstat_parseArgs(PGSTAT_FORK_ARGS);
112112
#endif
113113
NON_EXEC_STATICvoidpgstat_main(PGSTAT_FORK_ARGS);
@@ -337,15 +337,16 @@ pgstat_init(void)
337337
#ifdefEXEC_BACKEND
338338

339339
/* ----------
340-
*pgstat_exec() -
340+
*pgstat_forkexec() -
341341
*
342-
* Used to format up the arglist for, and exec, statistics
342+
* Used to format up the arglist for,then forkand exec, statistics
343343
* (buffer and collector) processes
344344
*
345345
*/
346-
staticvoid
347-
pgstat_exec(STATS_PROCESS_TYPEprocType)
346+
staticpid_t
347+
pgstat_forkexec(STATS_PROCESS_TYPEprocType)
348348
{
349+
pid_tpid;
349350
char*av[11];
350351
intac=0,bufc=0,i;
351352
charpgstatBuf[8][MAXPGPATH];
@@ -387,9 +388,12 @@ pgstat_exec(STATS_PROCESS_TYPE procType)
387388
av[ac++]=NULL;
388389
Assert(ac <=lengthof(av));
389390

390-
if (execv(pg_pathname,av)==-1)
391+
/* Fire off execv in child */
392+
if ((pid=fork())==0&& (execv(pg_pathname,av)==-1))
391393
/* FIXME: [fork/exec] suggestions for what to do here? Can't call elog... */
392-
Assert(false);
394+
abort();
395+
396+
returnpid;/* Parent returns pid */
393397
}
394398

395399

@@ -479,7 +483,11 @@ pgstat_start(void)
479483
beos_before_backend_startup();
480484
#endif
481485

486+
#ifdefEXEC_BACKEND
487+
switch ((pgStatSock= (int)pgstat_forkexec(STAT_PROC_BUFFER)))
488+
#else
482489
switch ((pgStatPid= (int)fork()))
490+
#endif
483491
{
484492
case-1:
485493
#ifdef__BEOS__
@@ -490,32 +498,27 @@ pgstat_start(void)
490498
(errmsg("could not fork statistics buffer: %m")));
491499
return;
492500

501+
#ifndefEXEC_BACKEND
493502
case0:
503+
/* in postmaster child ... */
504+
#ifdef__BEOS__
505+
/* Specific beos actions after backend startup */
506+
beos_backend_startup();
507+
#endif
508+
/* Close the postmaster's sockets, except for pgstat link */
509+
ClosePostmasterPorts(false);
510+
511+
/* Drop our connection to postmaster's shared memory, as well */
512+
PGSharedMemoryDetach();
513+
514+
pgstat_main();
494515
break;
516+
#endif
495517

496518
default:
497519
pgstat_is_running= true;
498520
return;
499521
}
500-
501-
/* in postmaster child ... */
502-
503-
#ifdef__BEOS__
504-
/* Specific beos actions after backend startup */
505-
beos_backend_startup();
506-
#endif
507-
508-
/* Close the postmaster's sockets, except for pgstat link */
509-
ClosePostmasterPorts(false);
510-
511-
/* Drop our connection to postmaster's shared memory, as well */
512-
PGSharedMemoryDetach();
513-
514-
#ifdefEXEC_BACKEND
515-
pgstat_exec(STAT_PROC_BUFFER);
516-
#else
517-
pgstat_main();
518-
#endif
519522
}
520523

521524

@@ -1385,28 +1388,31 @@ pgstat_main(PGSTAT_FORK_ARGS)
13851388
exit(1);
13861389
}
13871390

1391+
#ifdefEXEC_BACKEND
1392+
/* child becomes collector process */
1393+
switch (pgstat_forkexec(STAT_PROC_COLLECTOR))
1394+
#else
13881395
switch (fork())
1396+
#endif
13891397
{
13901398
case-1:
13911399
ereport(LOG,
13921400
(errmsg("could not fork statistics collector: %m")));
13931401
exit(1);
13941402

1403+
#ifndefEXEC_BACKEND
13951404
case0:
13961405
/* child becomes collector process */
1397-
#ifdefEXEC_BACKEND
1398-
pgstat_exec(STAT_PROC_COLLECTOR);
1399-
#else
14001406
pgstat_mainChild();
1407+
break;
14011408
#endif
1402-
exit(0);
14031409

14041410
default:
14051411
/* parent becomes buffer process */
14061412
closesocket(pgStatPipe[0]);
14071413
pgstat_recvbuffer();
1408-
exit(0);
14091414
}
1415+
exit(0);
14101416
}
14111417

14121418

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp