From b2c846135dbc7cd0e5e226d9217f8716eb5f3a95 Mon Sep 17 00:00:00 2001 From: magnum Date: Tue, 25 Feb 2025 15:10:33 +0100 Subject: [PATCH] Recover from (rare) non-fatal file locking problems --- src/locking.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/locking.c b/src/locking.c index 8918101a2..492350bab 100644 --- a/src/locking.c +++ b/src/locking.c @@ -20,9 +20,18 @@ int hc_lockfile (HCFILE *fp) lock.l_type = F_WRLCK; - /* Needs this loop because a signal may interrupt a wait for lock */ while (fcntl (fp->fd, F_SETLKW, &lock)) { + // These shouldn't happen with F_SETLKW yet are (rarely) seen IRL. Recoverable! + if (errno == EAGAIN || errno == ENOLCK) + { + struct timeval tv = { .tv_sec = 0, .tv_usec = 10000 }; + select (0, NULL, NULL, NULL, &tv); + + continue; + } + + // A signal may interrupt a wait for lock with EINTR. Anything else is fatal if (errno != EINTR) return -1; }