diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2017-06-05 07:34:05 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2017-06-05 07:34:05 +0000 |
commit | 2b38b2d401da8bf9e8147d724e7e4142a7ad082e (patch) | |
tree | 94ec19d1e63a671d1b6312f88185017362805be8 | |
parent | f70f52c66386f3ac39fe1b5d43087f4a4301d8bb (diff) | |
parent | be8e0e129c0a59a30832a870f7563ab9a20c2e47 (diff) | |
download | platform_external_iptables-android-8.0.0_r22.tar.gz platform_external_iptables-android-8.0.0_r22.tar.bz2 platform_external_iptables-android-8.0.0_r22.zip |
release-request-a2143a0f-bf92-4fa8-ad68-7346e7505126-for-git_oc-dr1-release-4067638 snap-temp-L84900000070511178android-8.0.0_r34android-8.0.0_r33android-8.0.0_r27android-8.0.0_r26android-8.0.0_r25android-8.0.0_r24android-8.0.0_r23android-8.0.0_r22android-8.0.0_r21oreo-dr3-releaseoreo-dr2-releaseoreo-dr1-release
Change-Id: Ifcfa8787e05f2545dda0bafec15f04c550fdb45e
-rw-r--r-- | iptables/ip6tables-restore.c | 7 | ||||
-rw-r--r-- | iptables/ip6tables.c | 11 | ||||
-rw-r--r-- | iptables/iptables-restore.c | 7 | ||||
-rw-r--r-- | iptables/iptables.c | 11 | ||||
-rw-r--r-- | iptables/xshared.c | 31 | ||||
-rw-r--r-- | iptables/xshared.h | 7 |
6 files changed, 37 insertions, 37 deletions
diff --git a/iptables/ip6tables-restore.c b/iptables/ip6tables-restore.c index 7d405906..0db8d849 100644 --- a/iptables/ip6tables-restore.c +++ b/iptables/ip6tables-restore.c @@ -296,12 +296,7 @@ int ip6tables_restore_main(int argc, char *argv[]) in_table = 0; } else if ((buffer[0] == '*') && (!in_table)) { /* Acquire a lock before we create a new table handle */ - lock = xtables_lock(wait, &wait_interval); - if (lock == XT_LOCK_BUSY) { - fprintf(stderr, "Another app is currently holding the xtables lock. " - "Perhaps you want to use the -w option?\n"); - exit(RESOURCE_PROBLEM); - } + lock = xtables_lock_or_exit(wait, &wait_interval); /* New table */ char *table; diff --git a/iptables/ip6tables.c b/iptables/ip6tables.c index 579d347b..49bd006f 100644 --- a/iptables/ip6tables.c +++ b/iptables/ip6tables.c @@ -1779,15 +1779,8 @@ int do_command6(int argc, char *argv[], char **table, generic_opt_check(command, cs.options); /* Attempt to acquire the xtables lock */ - if (!restore && xtables_lock(wait, &wait_interval) == 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); - } + if (!restore) + xtables_lock_or_exit(wait, &wait_interval); /* only allocate handle if we weren't called with a handle */ if (!*handle) diff --git a/iptables/iptables-restore.c b/iptables/iptables-restore.c index 113045df..078d1d46 100644 --- a/iptables/iptables-restore.c +++ b/iptables/iptables-restore.c @@ -295,12 +295,7 @@ iptables_restore_main(int argc, char *argv[]) in_table = 0; } else if ((buffer[0] == '*') && (!in_table)) { /* Acquire a lock before we create a new table handle */ - lock = xtables_lock(wait, &wait_interval); - if (lock == XT_LOCK_BUSY) { - fprintf(stderr, "Another app is currently holding the xtables lock. " - "Perhaps you want to use the -w option?\n"); - exit(RESOURCE_PROBLEM); - } + lock = xtables_lock_or_exit(wait, &wait_interval); /* New table */ char *table; diff --git a/iptables/iptables.c b/iptables/iptables.c index 62731c5e..d61d5b90 100644 --- a/iptables/iptables.c +++ b/iptables/iptables.c @@ -1766,15 +1766,8 @@ int do_command4(int argc, char *argv[], char **table, generic_opt_check(command, cs.options); /* Attempt to acquire the xtables lock */ - if (!restore && xtables_lock(wait, &wait_interval) == 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); - } + if (!restore) + xtables_lock_or_exit(wait, &wait_interval); /* only allocate handle if we weren't called with a handle */ if (!*handle) 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; diff --git a/iptables/xshared.h b/iptables/xshared.h index f8dc5278..e390f649 100644 --- a/iptables/xshared.h +++ b/iptables/xshared.h @@ -93,8 +93,7 @@ extern void xs_init_match(struct xtables_match *); * * A value >= 0 indicates the lock filedescriptor. Other values are: * - * XT_LOCK_UNSUPPORTED : The system does not support locking, execution will - * proceed lockless. + * XT_LOCK_FAILED : The lock could not be acquired. * * XT_LOCK_BUSY : The lock was held by another process. xtables_lock only * returns this value when |wait| == false. If |wait| == true, xtables_lock @@ -104,11 +103,11 @@ extern void xs_init_match(struct xtables_match *); */ enum { XT_LOCK_BUSY = -1, - XT_LOCK_UNSUPPORTED = -2, + XT_LOCK_FAILED = -2, XT_LOCK_NOT_ACQUIRED = -3, }; -extern int xtables_lock(int wait, struct timeval *tv); extern void xtables_unlock(int lock); +extern int xtables_lock_or_exit(int wait, struct timeval *tv); int parse_wait_time(int argc, char *argv[]); void parse_wait_interval(int argc, char *argv[], struct timeval *wait_interval); |