Skip to content

Commit

Permalink
fix: Rare race condition on Unix (Windows was already handled)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregungory committed Dec 19, 2024
1 parent 83b0081 commit fe86452
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/rt/ambient.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
static const char RCSid[] = "$Id: ambient.c,v 2.126 2024/12/09 00:44:29 greg Exp $";
static const char RCSid[] = "$Id: ambient.c,v 2.127 2024/12/19 17:43:47 greg Exp $";
/*
* ambient.c - routines dealing with ambient (inter-reflected) component.
*
Expand Down Expand Up @@ -665,14 +665,19 @@ initambfile( /* initialize ambient file */
fputc('\n', ambfp);
putambmagic(ambfp);
} else if (getheader(ambfp, amb_headline, NULL) < 0 || !hasambmagic(ambfp)) {
#ifndef F_SETLKW
static int ntries = 3;
if (--ntries > 0 && ftell(ambfp) == 0) {
int ntries = 2;
if (ntries-- > 0 && ftell(ambfp) == 0) {
#ifdef F_SETLKW
aflock(F_UNLCK);
clearerr(ambfp);
sleep(2);
aflock(F_RDLCK);
#else
clearerr(ambfp);
sleep(2);
#endif
goto retry;
}
#endif
error(USER, "bad/incompatible ambient file");
}
if ((AMB_CNDX != CNDX) | (AMB_WLPART != WLPART)) {
Expand Down

0 comments on commit fe86452

Please sign in to comment.