@@ -329,6 +329,7 @@ static DNSServiceRef bonjour_sdref = NULL;
329
329
/*
330
330
* postmaster.c - function prototypes
331
331
*/
332
+ static void unlink_external_pid_file (int status , Datum arg );
332
333
static void getInstallationPaths (const char * argv0 );
333
334
static void checkDataDir (void );
334
335
static Port * ConnCreate (int serverFd );
@@ -1071,7 +1072,6 @@ PostmasterMain(int argc, char *argv[])
1071
1072
{
1072
1073
fprintf (fpidfile , "%d\n" , MyProcPid );
1073
1074
fclose (fpidfile );
1074
- /* Should we remove the pid file on postmaster exit? */
1075
1075
1076
1076
/* Make PID file world readable */
1077
1077
if (chmod (external_pid_file , S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH ) != 0 )
@@ -1081,6 +1081,8 @@ PostmasterMain(int argc, char *argv[])
1081
1081
else
1082
1082
write_stderr ("%s: could not write external PID file \"%s\": %s\n" ,
1083
1083
progname , external_pid_file , strerror (errno ));
1084
+
1085
+ on_proc_exit (unlink_external_pid_file , 0 );
1084
1086
}
1085
1087
1086
1088
/*
@@ -1182,6 +1184,17 @@ PostmasterMain(int argc, char *argv[])
1182
1184
}
1183
1185
1184
1186
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
+
1185
1198
/*
1186
1199
* Compute and check the directory paths to files that are part of the
1187
1200
* installation (as deduced from the postgres executable's own location)
0 commit comments