Back-patch fix to prevent infinite loop when $PGDATA is not writable.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 8 Aug 2001 22:25:45 +0000 (22:25 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 8 Aug 2001 22:25:45 +0000 (22:25 +0000)
src/backend/utils/init/miscinit.c

index 33b9e11203efe744b9ccf6945d296852a3358353..956acdede4f22ecf24e9e441564085371da5612c 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.65 2001/04/16 02:42:01 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.65.2.1 2001/08/08 22:25:45 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -490,15 +490,18 @@ CreateLockFile(const char *filename, bool amPostmaster,
 {
    int         fd;
    char        buffer[MAXPGPATH + 100];
+   int         ntries;
    int         len;
    int         encoded_pid;
    pid_t       other_pid;
    pid_t       my_pid = getpid();
 
    /*
-    * We need a loop here because of race conditions.
+    * We need a loop here because of race conditions.  But don't loop
+    * forever (for example, a non-writable $PGDATA directory might cause
+    * a failure that won't go away).  100 tries seems like plenty.
     */
-   for (;;)
+   for (ntries = 0; ; ntries++)
    {
 
        /*
@@ -511,7 +514,7 @@ CreateLockFile(const char *filename, bool amPostmaster,
        /*
         * Couldn't create the pid file. Probably it already exists.
         */
-       if (errno != EEXIST && errno != EACCES)
+       if ((errno != EEXIST && errno != EACCES) || ntries > 100)
            elog(FATAL, "Can't create lock file %s: %m", filename);
 
        /*