Skip to contentSkip to conversation

Fix locking if LOCKDIR does not exist

PATCH Applied Phil Sutter 2 participants 2 messages Jan 15, 2018 – Jan 17, 2018 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/1 Fix locking if LOCKDIR does not exist

The previous conversion to using flock() missed a crucial bit of code which tries to create LOCKDIR once in case opening the lock failed - This patch reestablishes the old behaviour.

Fixes 6a826591878db ("Use flock() for --concurrent option")
---
 libebtc.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
libebtc.c +10 -4
index c0ff8ccfa66db..d47424872dc51 100644
@@ -143,10 +143,16 @@ int use_lockfd;
  * or -2 on any other error. */
 static int lock_file()
 {
-	int fd = open(LOCKFILE, O_CREAT, 00600);
-
-	if (fd < 0)
-		return -2;
+	int fd, try = 0;
+
+retry:
+	fd = open(LOCKFILE, O_CREAT, 00600);
+	if (fd < 0) {
+		if (try == 1 || mkdir(LOCKDIR, 00700))
+			return -2;
+		try = 1;
+		goto retry;
+	}
 	return flock(fd, LOCK_EX);
 }
 
Signature · 1 line
2.15.1
maintainer Applied
#1 lore raw
Quoted 3 lines · Phil Sutter

The previous conversion to using flock() missed a crucial bit of code which tries to create LOCKDIR once in case opening the lock failed - This patch reestablishes the old behaviour.

Applied, thanks Phil.