8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -490,15 +490,18 @@ CreateLockFile(const char *filename, bool amPostmaster,
490
490
{
491
491
int fd ;
492
492
char buffer [MAXPGPATH + 100 ];
493
+ int ntries ;
493
494
int len ;
494
495
int encoded_pid ;
495
496
pid_t other_pid ;
496
497
pid_t my_pid = getpid ();
497
498
498
499
/*
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.
500
503
*/
501
- for (;; )
504
+ for (ntries = 0 ; ; ntries ++ )
502
505
{
503
506
504
507
/*
@@ -511,7 +514,7 @@ CreateLockFile(const char *filename, bool amPostmaster,
511
514
/*
512
515
* Couldn't create the pid file. Probably it already exists.
513
516
*/
514
- if (errno != EEXIST && errno != EACCES )
517
+ if (( errno != EEXIST && errno != EACCES ) || ntries > 100 )
515
518
elog (FATAL ,"Can't create lock file %s: %m" ,filename );
516
519
517
520
/*