summaryrefslogtreecommitdiffstats
path: root/iptables/xshared.c
diff options
context:
space:
mode:
Diffstat (limited to 'iptables/xshared.c')
-rw-r--r--iptables/xshared.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/iptables/xshared.c b/iptables/xshared.c
index 3fbe3b1a..825479c3 100644
--- a/iptables/xshared.c
+++ b/iptables/xshared.c
@@ -246,7 +246,7 @@ void xs_init_match(struct xtables_match *match)
match->init(match->m);
}
-int xtables_lock(int wait, struct timeval *wait_interval)
+static int xtables_lock(int wait, struct timeval *wait_interval)
{
struct timeval time_left, wait_time;
int fd, i = 0;
@@ -255,8 +255,11 @@ int xtables_lock(int wait, struct timeval *wait_interval)
time_left.tv_usec = 0;
fd = open(XT_LOCK_NAME, O_CREAT, 0600);
- if (fd < 0)
- return XT_LOCK_UNSUPPORTED;
+ if (fd < 0) {
+ fprintf(stderr, "Fatal: can't open lock file %s: %s\n",
+ XT_LOCK_NAME, strerror(errno));
+ return XT_LOCK_FAILED;
+ }
if (wait == -1) {
if (flock(fd, LOCK_EX) == 0)
@@ -291,6 +294,28 @@ void xtables_unlock(int lock)
close(lock);
}
+int xtables_lock_or_exit(int wait, struct timeval *wait_interval)
+{
+ int lock = xtables_lock(wait, wait_interval);
+
+ if (lock == XT_LOCK_FAILED) {
+ xtables_free_opts(1);
+ exit(RESOURCE_PROBLEM);
+ }
+
+ if (lock == XT_LOCK_BUSY) {
+ fprintf(stderr, "Another app is currently holding the xtables lock. ");
+ if (wait == 0)
+ fprintf(stderr, "Perhaps you want to use the -w option?\n");
+ else
+ fprintf(stderr, "Stopped waiting after %ds.\n", wait);
+ xtables_free_opts(1);
+ exit(RESOURCE_PROBLEM);
+ }
+
+ return lock;
+}
+
int parse_wait_time(int argc, char *argv[])
{
int wait = -1;