diff options
Diffstat (limited to 'iptables/iptables-restore.c')
-rw-r--r-- | iptables/iptables-restore.c | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/iptables/iptables-restore.c b/iptables/iptables-restore.c index 2009f73..09a0f1c 100644 --- a/iptables/iptables-restore.c +++ b/iptables/iptables-restore.c @@ -11,6 +11,7 @@ #include <string.h> #include <stdio.h> #include <stdlib.h> +#include <time.h> #include "iptables.h" #include "xshared.h" #include "xtables.h" @@ -33,7 +34,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}, @@ -53,6 +55,7 @@ static void print_usage(const char *name, const char *version) " [ --help ]\n" " [ --noflush ]\n" " [ --wait ]\n" + " [ --wait-interval ]\n" " [ --table=<TABLE> ]\n" " [ --modprobe=<command>]\n", name); @@ -191,7 +194,10 @@ iptables_restore_main(int argc, char *argv[]) int in_table = 0, testing = 0; const char *tablename = NULL; const struct xtc_ops *ops = &iptc_ops; - + struct timeval wait_interval = { + .tv_sec = 1, + }; + bool wait_interval_set = false; line = 0; iptables_globals.program_name = "iptables-restore"; @@ -229,7 +235,26 @@ iptables_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 @@ iptables_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); |