Skip to content

Commit a11c8be

Browse files
committed
Back-patch fix to prevent infinite loop when $PGDATA is not writable.
1 parent 7d03946 commit a11c8be

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/backend/utils/init/miscinit.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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
{
491491
int fd;
492492
char buffer[MAXPGPATH + 100];
493+
int ntries;
493494
int len;
494495
int encoded_pid;
495496
pid_t other_pid;
496497
pid_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)
515518
elog(FATAL, "Can't create lock file %s: %m", filename);
516519

517520
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy