ebtables-tiny: fix lockfile function

flock without LOCK_NB never returns on a conflicting lock, so this
function doesn't conform to its comment.

Also close the lock file on error, so we can keep retrying.

Signed-off-by: Jan Luebbe <sho@stratum0.net>
This commit is contained in:
Jan Luebbe 2023-07-19 20:54:06 +02:00
parent dc99bbb906
commit 4aa99cc5a1
1 changed files with 5 additions and 1 deletions

View File

@ -127,6 +127,7 @@ void ebt_list_extensions()
static int lock_file()
{
int fd, try = 0;
int ret = 0;
retry:
fd = open(LOCKFILE, O_CREAT, 00600);
@ -136,7 +137,10 @@ retry:
try = 1;
goto retry;
}
return flock(fd, LOCK_EX);
ret = flock(fd, LOCK_EX | LOCK_NB);
if (ret)
close(fd);
return ret;
}
/* Get the table from the kernel or from a binary file */