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

Commitdde36bf

Browse files
committed
Create postmaster.pid and postmaster.opts under $PGDATA
1 parent9de156f commitdde36bf

File tree

1 file changed

+172
-3
lines changed

1 file changed

+172
-3
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 172 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.127 1999/10/25 03:07:45 tgl Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.128 1999/12/03 06:26:34 ishii Exp $
1414
*
1515
* NOTES
1616
*
@@ -92,6 +92,23 @@
9292
#include"utils/trace.h"
9393
#include"version.h"
9494

95+
/*
96+
* "postmaster.pid" is a file containing postmaster's pid, being
97+
* created uder $PGDATA upon postmaster's starting up. When postmaster
98+
* shuts down, it will be unlinked. The purpose of the file includes:
99+
*
100+
* (1) supplying neccessary information to stop/restart postmaster
101+
* (2) preventing another postmaster process starting while it has
102+
* already started
103+
*/
104+
#definePIDFNAME"postmaster.pid"
105+
106+
/*
107+
* "postmaster.opts" is a file containing options for postmaser.
108+
* pg_ctl will use it to restart postmaster.
109+
*/
110+
#defineOPTSFNAME"postmaster.opts"
111+
95112
#if !defined(MAXINT)
96113
#defineMAXINT INT_MAX
97114
#endif
@@ -261,6 +278,15 @@ static void RandomSalt(char *salt);
261278
staticvoidSignalChildren(SIGNAL_ARGS);
262279
staticintCountChildren(void);
263280

281+
staticintSetPidFile(pid_tpid,char*progname,intport,char*datadir,
282+
intassert,intnbuf,char*execfile,
283+
intdebuglvl,intnetserver,
284+
#ifdefUSE_SSL
285+
intsecurenetserver,
286+
#endif
287+
intmaxbackends,intreinit,
288+
intsilent,intsendstop,char*extraoptions);
289+
264290
externintBootstrapMain(intargc,char*argv[]);
265291
staticpid_tSSDataBase(boolstartup);
266292
#defineStartupDataBase()SSDataBase(true)
@@ -272,11 +298,11 @@ static void InitSSL(void);
272298

273299
#ifdefCYR_RECODE
274300
voidGetCharSetByHost(char*,int,char*);
275-
276301
#endif
277302

278303
#ifdefUSE_ASSERT_CHECKING
279-
intassert_enabled=1;
304+
305+
intassert_enabled=1;
280306

281307
#endif
282308

@@ -351,6 +377,9 @@ PostmasterMain(int argc, char *argv[])
351377
boolDataDirOK;/* We have a usable PGDATA value */
352378
charhostbuf[MAXHOSTNAMELEN];
353379
intnonblank_argc;
380+
charoriginal_extraoptions[MAXPGPATH];
381+
382+
*original_extraoptions='\0';
354383

355384
/*
356385
* We need three params so we can display status. If we don't get
@@ -509,6 +538,7 @@ PostmasterMain(int argc, char *argv[])
509538
*/
510539
strcat(ExtraOptions," ");
511540
strcat(ExtraOptions,optarg);
541+
strcpy(original_extraoptions,optarg);
512542
break;
513543
case'p':
514544
/* Set PGPORT by hand. */
@@ -618,6 +648,33 @@ PostmasterMain(int argc, char *argv[])
618648
if (silentflag)
619649
pmdaemonize();
620650

651+
/*
652+
* create pid file. if the file has already existed, exits.
653+
*/
654+
if (SetPidFile(
655+
getpid(),/* postmaster process id */
656+
progname,/* postmaster executable file */
657+
PostPortName,/* port number */
658+
DataDir,/* PGDATA */
659+
assert_enabled,/* whether -A is specified or not */
660+
NBuffers,/* -B: number of shared buffers */
661+
Execfile,/* -b: postgres executable file */
662+
DebugLvl,/* -d: debug level */
663+
NetServer,/* -i: accept connection from INET */
664+
#ifdefUSE_SSL
665+
SecureNetServer,/* -l: use SSL */
666+
#endif
667+
MaxBackends,/* -N: max number of backends */
668+
Reinit,/* -n: reinit shared mem after failure */
669+
silentflag,/* -S: detach tty */
670+
SendStop,/* -s: send SIGSTOP */
671+
original_extraoptions/* options for backend */
672+
)
673+
) {
674+
ExitPostmaster(1);
675+
return0;
676+
}
677+
621678
/*
622679
* Set up signal handlers for the postmaster process.
623680
*/
@@ -2068,3 +2125,115 @@ SSDataBase(bool startup)
20682125

20692126
return(pid);
20702127
}
2128+
2129+
staticcharPidFile[MAXPGPATH];
2130+
2131+
staticvoidUnlinkPidFile(void)
2132+
{
2133+
unlink(PidFile);
2134+
}
2135+
2136+
staticintSetPidFile(pid_tpid,char*progname,intport,char*datadir,
2137+
intassert,intnbuf,char*execfile,
2138+
intdebuglvl,intnetserver,
2139+
#ifdefUSE_SSL
2140+
intsecurenetserver,
2141+
#endif
2142+
intmaxbackends,intreinit,
2143+
intsilent,intsendstop,char*extraoptions)
2144+
{
2145+
intfd;
2146+
charoptsfile[MAXPGPATH];
2147+
charpidstr[32];
2148+
charopts[1024];
2149+
charbuf[1024];
2150+
2151+
/*
2152+
* Creating pid file
2153+
*/
2154+
sprintf(PidFile,"%s/%s",datadir,PIDFNAME);
2155+
fd=open(PidFile,O_RDWR |O_CREAT |O_EXCL,0600);
2156+
if (fd<0) {
2157+
fprintf(stderr,"Can't create pidfile: %s\n",PidFile);
2158+
fprintf(stderr,"Is another postmaser running?\n");
2159+
return(-1);
2160+
}
2161+
sprintf(pidstr,"%d",pid);
2162+
if (write(fd,pidstr,strlen(pidstr))!=strlen(pidstr)) {
2163+
fprintf(stderr,"Write to pid file failed\n");
2164+
close(fd);
2165+
unlink(PidFile);
2166+
return(-1);
2167+
}
2168+
close(fd);
2169+
2170+
/*
2171+
* Creating opts file
2172+
*/
2173+
sprintf(optsfile,"%s/%s",datadir,OPTSFNAME);
2174+
fd=open(optsfile,O_RDWR |O_TRUNC |O_CREAT,0600);
2175+
if (fd<0) {
2176+
fprintf(stderr,"Can't create optsfile:%s",optsfile);
2177+
unlink(PidFile);
2178+
return(-1);
2179+
}
2180+
sprintf(opts,"%s\n-p %d\n-D %s\n",progname,port,datadir);
2181+
if (assert) {
2182+
sprintf(buf,"-A %d\n",assert);
2183+
strcat(opts,buf);
2184+
}
2185+
2186+
sprintf(buf,"-B %d\n-b %s\n",nbuf,execfile);
2187+
strcat(opts,buf);
2188+
2189+
if (debuglvl) {
2190+
sprintf(buf,"-d %d\n",debuglvl);
2191+
strcat(opts,buf);
2192+
}
2193+
2194+
if (netserver) {
2195+
strcat(opts,"-i\n");
2196+
}
2197+
2198+
#ifdefUSE_SSL
2199+
if (securenetserver) {
2200+
strcat(opts,"-l\n");
2201+
}
2202+
#endif
2203+
2204+
sprintf(buf,"-N %d\n",maxbackends);
2205+
strcat(opts,buf);
2206+
2207+
if (!reinit) {
2208+
strcat(opts,"-n\n");
2209+
}
2210+
2211+
if (silent) {
2212+
strcat(opts,"-S\n");
2213+
}
2214+
2215+
if (sendstop) {
2216+
strcat(opts,"-s\n");
2217+
}
2218+
2219+
if (strlen(extraoptions)>0) {
2220+
strcat(opts,"-o '");
2221+
strcat(opts,extraoptions);
2222+
strcat(opts,"'");
2223+
}
2224+
2225+
if (write(fd,opts,strlen(opts))!=strlen(opts)) {
2226+
perror("Writing to opts file failed");
2227+
unlink(PidFile);
2228+
close(fd);
2229+
return(-1);
2230+
}
2231+
close(fd);
2232+
2233+
/*
2234+
* register clean up proc
2235+
*/
2236+
on_proc_exit(UnlinkPidFile,NULL);
2237+
2238+
return(0);
2239+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp