aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYusuke Sato <yusukes@google.com>2015-08-26 19:59:14 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-08-26 19:59:14 +0000
commit16752d9f7a92d4404a65296080f581d821e52e11 (patch)
tree9fdd6f331fbe2531fbe801149717cc9379ef33f9
parent0304f3bd45922a134b001955529bc72dc7525303 (diff)
parentf2a192e32451d50910c432dbc66352602fda5136 (diff)
downloadplatform_external_iptables-brillo-m7-release.tar.gz
platform_external_iptables-brillo-m7-release.tar.bz2
platform_external_iptables-brillo-m7-release.zip
am f2a192e3: Merge "Add \'-w\' option to ip[6]tables-restore"brillo-m7-releasebrillo-m7-mr-devbrillo-m7-dev
* commit 'f2a192e32451d50910c432dbc66352602fda5136': Add '-w' option to ip[6]tables-restore
-rw-r--r--iptables/ip6tables-restore.c18
-rw-r--r--iptables/iptables-restore.c18
2 files changed, 30 insertions, 6 deletions
diff --git a/iptables/ip6tables-restore.c b/iptables/ip6tables-restore.c
index b8b9e0dd..31bc502f 100644
--- a/iptables/ip6tables-restore.c
+++ b/iptables/ip6tables-restore.c
@@ -15,6 +15,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "ip6tables.h"
+#include "xshared.h"
#include "xtables.h"
#include "libiptc/libip6tc.h"
#include "ip6tables-multi.h"
@@ -25,7 +26,7 @@
#define DEBUGP(x, args...)
#endif
-static int binary = 0, counters = 0, verbose = 0, noflush = 0;
+static int binary = 0, counters = 0, verbose = 0, noflush = 0, wait = 0;
/* Keeping track of external matches and targets. */
static const struct option options[] = {
@@ -35,6 +36,7 @@ static const struct option options[] = {
{.name = "test", .has_arg = false, .val = 't'},
{.name = "help", .has_arg = false, .val = 'h'},
{.name = "noflush", .has_arg = false, .val = 'n'},
+ {.name = "wait", .has_arg = false, .val = 'w'},
{.name = "modprobe", .has_arg = true, .val = 'M'},
{.name = "table", .has_arg = true, .val = 'T'},
{NULL},
@@ -44,13 +46,14 @@ static void print_usage(const char *name, const char *version) __attribute__((no
static void print_usage(const char *name, const char *version)
{
- fprintf(stderr, "Usage: %s [-b] [-c] [-v] [-t] [-h]\n"
+ fprintf(stderr, "Usage: %s [-b] [-c] [-v] [-t] [-h] [-w]\n"
" [ --binary ]\n"
" [ --counters ]\n"
" [ --verbose ]\n"
" [ --test ]\n"
" [ --help ]\n"
" [ --noflush ]\n"
+ " [ --wait ]\n"
" [ --modprobe=<command>]\n", name);
exit(1);
@@ -204,7 +207,7 @@ int ip6tables_restore_main(int argc, char *argv[])
init_extensions6();
#endif
- while ((c = getopt_long(argc, argv, "bcvthnM:T:", options, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "bcvthnwM:T:", options, NULL)) != -1) {
switch (c) {
case 'b':
binary = 1;
@@ -225,6 +228,9 @@ int ip6tables_restore_main(int argc, char *argv[])
case 'n':
noflush = 1;
break;
+ case 'w':
+ wait = 1;
+ break;
case 'M':
xtables_modprobe_program = optarg;
break;
@@ -248,6 +254,12 @@ int ip6tables_restore_main(int argc, char *argv[])
}
else in = stdin;
+ if (!xtables_lock(wait)) {
+ fprintf(stderr, "Another app is currently holding the xtables lock. "
+ "Perhaps you want to use the -w option?\n");
+ exit(RESOURCE_PROBLEM);
+ }
+
/* Grab standard input. */
while (fgets(buffer, sizeof(buffer), in)) {
int ret = 0;
diff --git a/iptables/iptables-restore.c b/iptables/iptables-restore.c
index 8c942ff6..2009f732 100644
--- a/iptables/iptables-restore.c
+++ b/iptables/iptables-restore.c
@@ -12,6 +12,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "iptables.h"
+#include "xshared.h"
#include "xtables.h"
#include "libiptc/libiptc.h"
#include "iptables-multi.h"
@@ -22,7 +23,7 @@
#define DEBUGP(x, args...)
#endif
-static int binary = 0, counters = 0, verbose = 0, noflush = 0;
+static int binary = 0, counters = 0, verbose = 0, noflush = 0, wait = 0;
/* Keeping track of external matches and targets. */
static const struct option options[] = {
@@ -32,6 +33,7 @@ static const struct option options[] = {
{.name = "test", .has_arg = false, .val = 't'},
{.name = "help", .has_arg = false, .val = 'h'},
{.name = "noflush", .has_arg = false, .val = 'n'},
+ {.name = "wait", .has_arg = false, .val = 'w'},
{.name = "modprobe", .has_arg = true, .val = 'M'},
{.name = "table", .has_arg = true, .val = 'T'},
{NULL},
@@ -43,13 +45,14 @@ static void print_usage(const char *name, const char *version) __attribute__((no
static void print_usage(const char *name, const char *version)
{
- fprintf(stderr, "Usage: %s [-b] [-c] [-v] [-t] [-h]\n"
+ fprintf(stderr, "Usage: %s [-b] [-c] [-v] [-t] [-h] [-w]\n"
" [ --binary ]\n"
" [ --counters ]\n"
" [ --verbose ]\n"
" [ --test ]\n"
" [ --help ]\n"
" [ --noflush ]\n"
+ " [ --wait ]\n"
" [ --table=<TABLE> ]\n"
" [ --modprobe=<command>]\n", name);
@@ -204,7 +207,7 @@ iptables_restore_main(int argc, char *argv[])
init_extensions4();
#endif
- while ((c = getopt_long(argc, argv, "bcvthnM:T:", options, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "bcvthnwM:T:", options, NULL)) != -1) {
switch (c) {
case 'b':
binary = 1;
@@ -225,6 +228,9 @@ iptables_restore_main(int argc, char *argv[])
case 'n':
noflush = 1;
break;
+ case 'w':
+ wait = 1;
+ break;
case 'M':
xtables_modprobe_program = optarg;
break;
@@ -248,6 +254,12 @@ iptables_restore_main(int argc, char *argv[])
}
else in = stdin;
+ if (!xtables_lock(wait)) {
+ fprintf(stderr, "Another app is currently holding the xtables lock. "
+ "Perhaps you want to use the -w option?\n");
+ exit(RESOURCE_PROBLEM);
+ }
+
/* Grab standard input. */
while (fgets(buffer, sizeof(buffer), in)) {
int ret = 0;