1010 *
1111 *
1212 * IDENTIFICATION
13- * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.129 1999/12/04 08:23:43 ishii Exp $
13+ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.130 1999/12/06 07:21:12 ishii Exp $
1414 *
1515 * NOTES
1616 *
@@ -250,6 +250,11 @@ static bool FatalError = false;
250250
251251static unsigned int random_seed = 0 ;
252252
253+ /*
254+ * Path to pid file. Exitpostmaster() remember it to unlink the file.
255+ */
256+ static char PidFile [MAXPGPATH ];
257+
253258extern char * optarg ;
254259extern int optind ,
255260 opterr ;
@@ -277,7 +282,8 @@ static long PostmasterRandom(void);
277282static void RandomSalt (char * salt );
278283static void SignalChildren (SIGNAL_ARGS );
279284static int CountChildren (void );
280-
285+ static void UnlinkPidFile (void );
286+ static void SetPidFname (char * datadir );
281287static int SetPidFile (pid_t pid , char * progname , int port , char * datadir ,
282288 int assert , int nbuf , char * execfile ,
283289 int debuglvl , int netserver ,
@@ -748,6 +754,7 @@ pmdaemonize(char *extraoptions)
748754 }
749755 _exit (0 );
750756 }
757+
751758/* GH: If there's no setsid(), we hopefully don't need silent mode.
752759 * Until there's a better solution.
753760 */
@@ -768,6 +775,12 @@ pmdaemonize(char *extraoptions)
768775 dup2 (i , 1 );
769776 dup2 (i , 2 );
770777 close (i );
778+
779+ /*
780+ * register clean up proc
781+ */
782+ SetPidFname (DataDir );
783+ on_proc_exit (UnlinkPidFile , NULL );
771784}
772785
773786static void
@@ -2165,13 +2178,25 @@ SSDataBase(bool startup)
21652178 return (pid );
21662179}
21672180
2168- static char PidFile [MAXPGPATH ];
2169-
2181+ /*
2182+ * Remove the pid file. This function is called from proc_exit.
2183+ */
21702184static void UnlinkPidFile (void )
21712185{
21722186 unlink (PidFile );
21732187}
21742188
2189+ /*
2190+ * Set path to the pid file
2191+ */
2192+ static void SetPidFname (char * datadir )
2193+ {
2194+ snprintf (PidFile , sizeof (PidFile ), "%s/%s" , datadir , PIDFNAME );
2195+ }
2196+
2197+ /*
2198+ * Create the pid file
2199+ */
21752200static int SetPidFile (pid_t pid , char * progname , int port , char * datadir ,
21762201 int assert , int nbuf , char * execfile ,
21772202 int debuglvl , int netserver ,
@@ -2192,7 +2217,7 @@ static int SetPidFile(pid_t pid, char *progname, int port, char *datadir,
21922217 /*
21932218 * Creating pid file
21942219 */
2195- snprintf ( PidFile , sizeof ( PidFile ), "%s/%s" , datadir , PIDFNAME );
2220+ SetPidFname ( datadir );
21962221 fd = open (PidFile , O_RDWR | O_CREAT | O_EXCL , 0600 );
21972222 if (fd < 0 ) {
21982223 /*
0 commit comments