]> granicus.if.org Git - postgresql/commitdiff
Remove external PID file on postmaster exit
authorPeter Eisentraut <peter_e@gmx.net>
Tue, 21 Aug 2012 03:47:11 +0000 (23:47 -0400)
committerPeter Eisentraut <peter_e@gmx.net>
Tue, 21 Aug 2012 03:47:11 +0000 (23:47 -0400)
src/backend/postmaster/postmaster.c

index a4fb2a441e49ccc9e6bafbd6922ef93eda8430c0..73520a6ca2f4d3300f3d8939c0e9412064a911c3 100644 (file)
@@ -329,6 +329,7 @@ static DNSServiceRef bonjour_sdref = NULL;
 /*
  * postmaster.c - function prototypes
  */
+static void unlink_external_pid_file(int status, Datum arg);
 static void getInstallationPaths(const char *argv0);
 static void checkDataDir(void);
 static Port *ConnCreate(int serverFd);
@@ -1071,7 +1072,6 @@ PostmasterMain(int argc, char *argv[])
                {
                        fprintf(fpidfile, "%d\n", MyProcPid);
                        fclose(fpidfile);
-                       /* Should we remove the pid file on postmaster exit? */
 
                        /* Make PID file world readable */
                        if (chmod(external_pid_file, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) != 0)
@@ -1081,6 +1081,8 @@ PostmasterMain(int argc, char *argv[])
                else
                        write_stderr("%s: could not write external PID file \"%s\": %s\n",
                                                 progname, external_pid_file, strerror(errno));
+
+               on_proc_exit(unlink_external_pid_file, 0);
        }
 
        /*
@@ -1182,6 +1184,17 @@ PostmasterMain(int argc, char *argv[])
 }
 
 
+/*
+ * on_proc_exit callback to delete external_pid_file
+ */
+static void
+unlink_external_pid_file(int status, Datum arg)
+{
+       if (external_pid_file)
+               unlink(external_pid_file);
+}
+
+
 /*
  * Compute and check the directory paths to files that are part of the
  * installation (as deduced from the postgres executable's own location)