mirror of
https://github.com/hashcat/hashcat.git
synced 2025-07-24 23:48:19 +00:00
Merge pull request #4162 from magnumripper/robust-lock
Recover from (rare) non-fatal file locking problems
This commit is contained in:
commit
4df5e4517d
@ -20,9 +20,18 @@ int hc_lockfile (HCFILE *fp)
|
|||||||
|
|
||||||
lock.l_type = F_WRLCK;
|
lock.l_type = F_WRLCK;
|
||||||
|
|
||||||
/* Needs this loop because a signal may interrupt a wait for lock */
|
|
||||||
while (fcntl (fp->fd, F_SETLKW, &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;
|
if (errno != EINTR) return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user