|
|
9c64ad |
commit 24f8174646123c2833bc87967b366796231b04e0
|
|
|
9c64ad |
Author: Liping Zhang <zlpnobody@gmail.com>
|
|
|
9c64ad |
Date: Sun Feb 5 21:57:34 2017 +0800
|
|
|
9c64ad |
|
|
|
9c64ad |
xshared: do not lock again and again if "-w" option is not specified
|
|
|
9c64ad |
|
|
|
9c64ad |
After running the following commands, some confusing messages was printed
|
|
|
9c64ad |
out:
|
|
|
9c64ad |
# while : ; do
|
|
|
9c64ad |
iptables -A INPUT &
|
|
|
9c64ad |
iptables -D INPUT &
|
|
|
9c64ad |
done
|
|
|
9c64ad |
[...]
|
|
|
9c64ad |
Another app is currently holding the xtables lock; still -9s 0us time
|
|
|
9c64ad |
ahead to have a chance to grab the lock...
|
|
|
9c64ad |
Another app is currently holding the xtables lock; still -29s 0us time
|
|
|
9c64ad |
ahead to have a chance to grab the lock...
|
|
|
9c64ad |
|
|
|
9c64ad |
If "-w" option is not specified, the "wait" will be zero, so we should
|
|
|
9c64ad |
check whether the timer_left is less than wait_interval before we call
|
|
|
9c64ad |
select to sleep.
|
|
|
9c64ad |
|
|
|
9c64ad |
Also remove unused "BASE_MICROSECONDS" and "struct timeval waited_time"
|
|
|
9c64ad |
introduced by commit e8f857a5a151 ("xtables: Add an interval option for
|
|
|
9c64ad |
xtables lock wait").
|
|
|
9c64ad |
|
|
|
9c64ad |
Fixes: e8f857a5a151 ("xtables: Add an interval option for xtables lock wait")
|
|
|
9c64ad |
Signed-off-by: Liping Zhang <zlpnobody@gmail.com>
|
|
|
9c64ad |
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
|
|
|
9c64ad |
|
|
|
9c64ad |
diff --git a/iptables/xshared.c b/iptables/xshared.c
|
|
|
9c64ad |
index cccb8ae..055acf2 100644
|
|
|
9c64ad |
--- a/iptables/xshared.c
|
|
|
9c64ad |
+++ b/iptables/xshared.c
|
|
|
9c64ad |
@@ -17,7 +17,6 @@
|
|
|
9c64ad |
#include "xshared.h"
|
|
|
9c64ad |
|
|
|
9c64ad |
#define XT_LOCK_NAME "/run/xtables.lock"
|
|
|
9c64ad |
-#define BASE_MICROSECONDS 100000
|
|
|
9c64ad |
|
|
|
9c64ad |
/*
|
|
|
9c64ad |
* Print out any special helps. A user might like to be able to add a --help
|
|
|
9c64ad |
@@ -249,13 +248,11 @@ void xs_init_match(struct xtables_match *match)
|
|
|
9c64ad |
|
|
|
9c64ad |
bool xtables_lock(int wait, struct timeval *wait_interval)
|
|
|
9c64ad |
{
|
|
|
9c64ad |
- struct timeval time_left, wait_time, waited_time;
|
|
|
9c64ad |
+ struct timeval time_left, wait_time;
|
|
|
9c64ad |
int fd, i = 0;
|
|
|
9c64ad |
|
|
|
9c64ad |
time_left.tv_sec = wait;
|
|
|
9c64ad |
time_left.tv_usec = 0;
|
|
|
9c64ad |
- waited_time.tv_sec = 0;
|
|
|
9c64ad |
- waited_time.tv_usec = 0;
|
|
|
9c64ad |
|
|
|
9c64ad |
fd = open(XT_LOCK_NAME, O_CREAT, 0600);
|
|
|
9c64ad |
if (fd < 0)
|
|
|
9c64ad |
@@ -264,6 +261,9 @@ bool xtables_lock(int wait, struct timeval *wait_interval)
|
|
|
9c64ad |
while (1) {
|
|
|
9c64ad |
if (flock(fd, LOCK_EX | LOCK_NB) == 0)
|
|
|
9c64ad |
return true;
|
|
|
9c64ad |
+ else if (wait >= 0 && timercmp(&time_left, wait_interval, <))
|
|
|
9c64ad |
+ return false;
|
|
|
9c64ad |
+
|
|
|
9c64ad |
if (++i % 10 == 0) {
|
|
|
9c64ad |
if (wait != -1)
|
|
|
9c64ad |
fprintf(stderr, "Another app is currently holding the xtables lock; "
|
|
|
9c64ad |
@@ -279,10 +279,7 @@ bool xtables_lock(int wait, struct timeval *wait_interval)
|
|
|
9c64ad |
if (wait == -1)
|
|
|
9c64ad |
continue;
|
|
|
9c64ad |
|
|
|
9c64ad |
- timeradd(&waited_time, wait_interval, &waited_time);
|
|
|
9c64ad |
timersub(&time_left, wait_interval, &time_left);
|
|
|
9c64ad |
- if (!timerisset(&time_left))
|
|
|
9c64ad |
- return false;
|
|
|
9c64ad |
}
|
|
|
9c64ad |
}
|
|
|
9c64ad |
|