8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -539,15 +539,18 @@ CreateLockFile(const char *filename, bool amPostmaster,
539
539
{
540
540
int fd ;
541
541
char buffer [MAXPGPATH + 100 ];
542
+ int ntries ;
542
543
int len ;
543
544
int encoded_pid ;
544
545
pid_t other_pid ;
545
546
pid_t my_pid = getpid ();
546
547
547
548
/*
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.
549
552
*/
550
- for (;; )
553
+ for (ntries = 0 ; ; ntries ++ )
551
554
{
552
555
553
556
/*
@@ -560,7 +563,7 @@ CreateLockFile(const char *filename, bool amPostmaster,
560
563
/*
561
564
* Couldn't create the pid file. Probably it already exists.
562
565
*/
563
- if (errno != EEXIST && errno != EACCES )
566
+ if (( errno != EEXIST && errno != EACCES ) || ntries > 100 )
564
567
elog (FATAL ,"Can't create lock file %s: %m" ,filename );
565
568
566
569
/*