From aaa4ace72ba1d195bbf436134a336816c33f7bd0 Mon Sep 17 00:00:00 2001 From: Jiri Popelka Date: Fri, 4 Jul 2014 15:50:41 +0200 Subject: iptables: add optional [seconds] argument to -w This patch adds an optional numeric argument to -w option (added with 93587a0) so one can specify how long to wait for an exclusive lock. If the value isn't specified it works as before, i.e. program waits indefinitely. If user specifies it, program exits after the given time interval passes. This patch also adds the -w/--wait to nftables compat code, so the parser doesn't complain. [ In the original patch, iptables-compat -w X was not working, I have fixed by adding the dummy code not to break scripts using the new optional argument --pablo ] Signed-off-by: Jiri Popelka Signed-off-by: Pablo Neira Ayuso --- iptables/xshared.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'iptables/xshared.c') diff --git a/iptables/xshared.c b/iptables/xshared.c index 6c9992ed..b18022ee 100644 --- a/iptables/xshared.c +++ b/iptables/xshared.c @@ -243,10 +243,11 @@ void xs_init_match(struct xtables_match *match) match->init(match->m); } -bool xtables_lock(bool wait) +bool xtables_lock(int wait) { int i = 0, ret, xt_socket; struct sockaddr_un xt_addr; + int waited = 0; memset(&xt_addr, 0, sizeof(xt_addr)); xt_addr.sun_family = AF_UNIX; @@ -261,11 +262,12 @@ bool xtables_lock(bool wait) offsetof(struct sockaddr_un, sun_path)+XT_SOCKET_LEN); if (ret == 0) return true; - else if (wait == false) + else if (wait >= 0 && waited >= wait) return false; if (++i % 2 == 0) fprintf(stderr, "Another app is currently holding the xtables lock; " - "waiting for it to exit...\n"); + "waiting (%ds) for it to exit...\n", waited); + waited++; sleep(1); } } -- cgit v1.2.3