88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.65 2001/04/16 02:42:01 tgl Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.65.2.1 2001/08/08 22:25:45 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -490,15 +490,18 @@ CreateLockFile(const char *filename, bool amPostmaster,
490490{
491491int fd ;
492492char buffer [MAXPGPATH + 100 ];
493+ int ntries ;
493494int len ;
494495int encoded_pid ;
495496pid_t other_pid ;
496497pid_t my_pid = getpid ();
497498
498499/*
499- * We need a loop here because of race conditions.
500+ * We need a loop here because of race conditions. But don't loop
501+ * forever (for example, a non-writable $PGDATA directory might cause
502+ * a failure that won't go away). 100 tries seems like plenty.
500503 */
501- for (;; )
504+ for (ntries = 0 ; ; ntries ++ )
502505{
503506
504507/*
@@ -511,7 +514,7 @@ CreateLockFile(const char *filename, bool amPostmaster,
511514/*
512515 * Couldn't create the pid file. Probably it already exists.
513516 */
514- if (errno != EEXIST && errno != EACCES )
517+ if (( errno != EEXIST && errno != EACCES ) || ntries > 100 )
515518elog (FATAL ,"Can't create lock file %s: %m" ,filename );
516519
517520/*