OSDN Git Service

Re-read Unix-socket lock file every so often (every CheckPoint interval,
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 27 Jan 2001 00:05:31 +0000 (00:05 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 27 Jan 2001 00:05:31 +0000 (00:05 +0000)
actually) to ensure that its file access time doesn't get old enough to
tempt a /tmp directory cleaner to remove it.  Still another reason we
should never have put the sockets in /tmp in the first place ...

src/backend/postmaster/postmaster.c
src/backend/utils/init/miscinit.c
src/include/miscadmin.h

index 3d7c1cb..98fff8b 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.203 2001/01/24 19:43:04 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.204 2001/01/27 00:05:31 tgl Exp $
  *
  * NOTES
  *
@@ -788,7 +788,15 @@ ServerLoop(void)
                                timeout = &timeout_tv;
                        }
                        else
+                       {
                                CheckPointPID = CheckPointDataBase();
+                               /*
+                                * Since this code is executed periodically, it's a fine
+                                * place to do other actions that should happen every now
+                                * and then on no particular schedule.  Such as...
+                                */
+                               TouchSocketLockFile();
+                       }
                }
 
 #ifdef USE_SSL
index d16dca6..0ecfa27 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.60 2001/01/24 19:43:16 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.61 2001/01/27 00:05:31 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -41,6 +41,9 @@ unsigned char RecodeBackTable[128];
 
 ProcessingMode Mode = InitProcessing;
 
+/* Note: we rely on this to initialize as zeroes */
+static char socketLockFile[MAXPGPATH];
+
 
 /* ----------------------------------------------------------------
  *             ignoring system indexes support stuff
@@ -617,9 +620,37 @@ CreateSocketLockFile(const char *socketfile, bool amPostmaster)
                                        encoded_pid, socketfile);
                return false;
        }
+       /* Save name of lockfile for TouchSocketLockFile */
+       strcpy(socketLockFile, lockfile);
        return true;
 }
 
+/*
+ * Re-read the socket lock file.  This should be called every so often
+ * to ensure that the lock file has a recent access date.  That saves it
+ * from being removed by overenthusiastic /tmp-directory-cleaner daemons.
+ * (Another reason we should never have put the socket file in /tmp...)
+ */
+void
+TouchSocketLockFile(void)
+{
+       int                     fd;
+       char            buffer[1];
+
+       /* Do nothing if we did not create a socket... */
+       if (socketLockFile[0] != '\0')
+       {
+               /* XXX any need to complain about errors here? */
+               fd = open(socketLockFile, O_RDONLY | PG_BINARY, 0);
+               if (fd >= 0)
+               {
+                       read(fd, buffer, sizeof(buffer));
+                       close(fd);
+               }
+       }
+}
+
+
 /*-------------------------------------------------------------------------
  *                             Version checking support
  *-------------------------------------------------------------------------
index 93b153c..fa73145 100644 (file)
@@ -12,7 +12,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: miscadmin.h,v 1.79 2001/01/24 19:43:19 momjian Exp $
+ * $Id: miscadmin.h,v 1.80 2001/01/27 00:05:31 tgl Exp $
  *
  * NOTES
  *       some of the information in this file should be moved to
@@ -280,6 +280,7 @@ extern ProcessingMode Mode;
 
 extern bool CreateDataDirLockFile(const char *datadir, bool amPostmaster);
 extern bool CreateSocketLockFile(const char *socketfile, bool amPostmaster);
+extern void TouchSocketLockFile(void);
 
 extern void ValidatePgVersion(const char *path);