diff options
Diffstat (limited to 'iptables/ip6tables-restore.c')
-rw-r--r-- | iptables/ip6tables-restore.c | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/iptables/ip6tables-restore.c b/iptables/ip6tables-restore.c index 31bc502..2993667 100644 --- a/iptables/ip6tables-restore.c +++ b/iptables/ip6tables-restore.c @@ -14,6 +14,7 @@ #include <string.h> #include <stdio.h> #include <stdlib.h> +#include <time.h> #include "ip6tables.h" #include "xshared.h" #include "xtables.h" @@ -36,7 +37,8 @@ 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 = "wait", .has_arg = true, .val = 'w'}, + {.name = "wait-interval", .has_arg = true, .val = 'W'}, {.name = "modprobe", .has_arg = true, .val = 'M'}, {.name = "table", .has_arg = true, .val = 'T'}, {NULL}, @@ -46,7 +48,7 @@ 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] [-w]\n" + fprintf(stderr, "Usage: %s [-b] [-c] [-v] [-t] [-h] [-w] [-W]\n" " [ --binary ]\n" " [ --counters ]\n" " [ --verbose ]\n" @@ -54,6 +56,7 @@ static void print_usage(const char *name, const char *version) " [ --help ]\n" " [ --noflush ]\n" " [ --wait ]\n" + " [ --wait-interval ]\n" " [ --modprobe=<command>]\n", name); exit(1); @@ -191,7 +194,10 @@ int ip6tables_restore_main(int argc, char *argv[]) int in_table = 0, testing = 0; const char *tablename = NULL; const struct xtc_ops *ops = &ip6tc_ops; - + struct timeval wait_interval = { + .tv_sec = 1, + }; + bool wait_interval_set = false; line = 0; ip6tables_globals.program_name = "ip6tables-restore"; @@ -207,7 +213,7 @@ int ip6tables_restore_main(int argc, char *argv[]) init_extensions6(); #endif - while ((c = getopt_long(argc, argv, "bcvthnwM:T:", options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "bcvthnwM:W:T:", options, NULL)) != -1) { switch (c) { case 'b': binary = 1; @@ -229,7 +235,26 @@ int ip6tables_restore_main(int argc, char *argv[]) noflush = 1; break; case 'w': - wait = 1; + wait = -1; + if (optarg) { + if (sscanf(optarg, "%i", &wait) != 1) + xtables_error(PARAMETER_PROBLEM, + "wait seconds not numeric"); + } else if (optind < argc && argv[optind][0] != '-' + && argv[optind][0] != '!') + if (sscanf(argv[optind++], "%i", &wait) != 1) + xtables_error(PARAMETER_PROBLEM, + "wait seconds not numeric"); + break; + case 'W': + if (optarg) + parse_wait_interval(optarg, &wait_interval); + else if (optind < argc && + argv[optind][0] != '-' && + argv[optind][0] != '!') + parse_wait_interval(argv[optind++], + &wait_interval); + wait_interval_set = true; break; case 'M': xtables_modprobe_program = optarg; @@ -254,7 +279,7 @@ int ip6tables_restore_main(int argc, char *argv[]) } else in = stdin; - if (!xtables_lock(wait)) { + if (!xtables_lock(wait, &wait_interval)) { fprintf(stderr, "Another app is currently holding the xtables lock. " "Perhaps you want to use the -w option?\n"); exit(RESOURCE_PROBLEM); |