88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.72 2001/06/20 18:07:56 petere Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.73 2001/07/03 16:49:48 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -539,15 +539,18 @@ CreateLockFile(const char *filename, bool amPostmaster,
539539{
540540int fd ;
541541char buffer [MAXPGPATH + 100 ];
542+ int ntries ;
542543int len ;
543544int encoded_pid ;
544545pid_t other_pid ;
545546pid_t my_pid = getpid ();
546547
547548/*
548- * We need a loop here because of race conditions.
549+ * We need a loop here because of race conditions. But don't loop
550+ * forever (for example, a non-writable $PGDATA directory might cause
551+ * a failure that won't go away). 100 tries seems like plenty.
549552 */
550- for (;; )
553+ for (ntries = 0 ; ; ntries ++ )
551554{
552555
553556/*
@@ -560,7 +563,7 @@ CreateLockFile(const char *filename, bool amPostmaster,
560563/*
561564 * Couldn't create the pid file. Probably it already exists.
562565 */
563- if (errno != EEXIST && errno != EACCES )
566+ if (( errno != EEXIST && errno != EACCES ) || ntries > 100 )
564567elog (FATAL ,"Can't create lock file %s: %m" ,filename );
565568
566569/*