|
|
05e71a |
From b3d4dbcbfe2986711492634c193f32db14f06a22 Mon Sep 17 00:00:00 2001
|
|
|
05e71a |
From: Phil Sutter <phil@nwl.cc>
|
|
|
05e71a |
Date: Mon, 15 Jan 2018 16:27:31 +0100
|
|
|
05e71a |
Subject: [PATCH] Fix locking if LOCKDIR does not exist
|
|
|
05e71a |
|
|
|
05e71a |
The previous conversion to using flock() missed a crucial bit of code
|
|
|
05e71a |
which tries to create LOCKDIR once in case opening the lock failed -
|
|
|
05e71a |
This patch reestablishes the old behaviour.
|
|
|
05e71a |
|
|
|
05e71a |
Reported-by: Tangchen (UVP) <tang.chen@huawei.com>
|
|
|
05e71a |
Fixes: 6a826591878db ("Use flock() for --concurrent option")
|
|
|
05e71a |
Signed-off-by: Phil Sutter <phil@nwl.cc>
|
|
|
05e71a |
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
|
|
|
05e71a |
Signed-off-by: Phil Sutter <psutter@redhat.com>
|
|
|
05e71a |
---
|
|
|
05e71a |
libebtc.c | 14 ++++++++++----
|
|
|
05e71a |
1 file changed, 10 insertions(+), 4 deletions(-)
|
|
|
05e71a |
|
|
|
05e71a |
diff --git a/libebtc.c b/libebtc.c
|
|
|
05e71a |
index c0ff8ccfa66db..d47424872dc51 100644
|
|
|
05e71a |
--- a/libebtc.c
|
|
|
05e71a |
+++ b/libebtc.c
|
|
|
05e71a |
@@ -143,10 +143,16 @@ int use_lockfd;
|
|
|
05e71a |
* or -2 on any other error. */
|
|
|
05e71a |
static int lock_file()
|
|
|
05e71a |
{
|
|
|
05e71a |
- int fd = open(LOCKFILE, O_CREAT, 00600);
|
|
|
05e71a |
-
|
|
|
05e71a |
- if (fd < 0)
|
|
|
05e71a |
- return -2;
|
|
|
05e71a |
+ int fd, try = 0;
|
|
|
05e71a |
+
|
|
|
05e71a |
+retry:
|
|
|
05e71a |
+ fd = open(LOCKFILE, O_CREAT, 00600);
|
|
|
05e71a |
+ if (fd < 0) {
|
|
|
05e71a |
+ if (try == 1 || mkdir(LOCKDIR, 00700))
|
|
|
05e71a |
+ return -2;
|
|
|
05e71a |
+ try = 1;
|
|
|
05e71a |
+ goto retry;
|
|
|
05e71a |
+ }
|
|
|
05e71a |
return flock(fd, LOCK_EX);
|
|
|
05e71a |
}
|
|
|
05e71a |
|
|
|
05e71a |
--
|
|
|
05e71a |
2.21.0
|
|
|
05e71a |
|