@@ -329,6 +329,7 @@ static DNSServiceRef bonjour_sdref = NULL;
329329/*
330330 * postmaster.c - function prototypes
331331 */
332+ static void unlink_external_pid_file (int status ,Datum arg );
332333static void getInstallationPaths (const char * argv0 );
333334static void checkDataDir (void );
334335static Port * ConnCreate (int serverFd );
@@ -1071,7 +1072,6 @@ PostmasterMain(int argc, char *argv[])
10711072{
10721073fprintf (fpidfile ,"%d\n" ,MyProcPid );
10731074fclose (fpidfile );
1074- /* Should we remove the pid file on postmaster exit? */
10751075
10761076/* Make PID file world readable */
10771077if (chmod (external_pid_file ,S_IRUSR |S_IWUSR |S_IRGRP |S_IROTH )!= 0 )
@@ -1081,6 +1081,8 @@ PostmasterMain(int argc, char *argv[])
10811081else
10821082write_stderr ("%s: could not write external PID file \"%s\": %s\n" ,
10831083progname ,external_pid_file ,strerror (errno ));
1084+
1085+ on_proc_exit (unlink_external_pid_file ,0 );
10841086}
10851087
10861088/*
@@ -1182,6 +1184,17 @@ PostmasterMain(int argc, char *argv[])
11821184}
11831185
11841186
1187+ /*
1188+ * on_proc_exit callback to delete external_pid_file
1189+ */
1190+ static void
1191+ unlink_external_pid_file (int status ,Datum arg )
1192+ {
1193+ if (external_pid_file )
1194+ unlink (external_pid_file );
1195+ }
1196+
1197+
11851198/*
11861199 * Compute and check the directory paths to files that are part of the
11871200 * installation (as deduced from the postgres executable's own location)