diff options
author | Bart De Schuymer <bdschuym@pandora.be> | 2011-06-19 18:54:13 +0000 |
---|---|---|
committer | Bart De Schuymer <bdschuym@pandora.be> | 2011-06-19 18:54:13 +0000 |
commit | 307bbe68714e0f016249c776018a8f9db34147aa (patch) | |
tree | fa50b91cc5da8a698e4abd3fef16d2f23a7093d9 /ebtables.c | |
parent | f9b4bcb9394d4cce14772ea50506f80167542c2b (diff) |
add logic to support the --concurrent option: use a file lock to support concurrent scripts running ebtables
Diffstat (limited to 'ebtables.c')
-rw-r--r-- | ebtables.c | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -26,6 +26,7 @@ #include <stdio.h> #include <stdlib.h> #include <inttypes.h> +#include <signal.h> #include "include/ebtables_u.h" #include "include/ethernetdb.h" @@ -91,6 +92,7 @@ static struct option ebt_original_options[] = { "atomic-file" , required_argument, 0, 9 }, { "atomic-save" , no_argument , 0, 10 }, { "init-table" , no_argument , 0, 11 }, + { "concurrent" , no_argument , 0, 13 }, { 0 } }; @@ -374,6 +376,7 @@ static void print_help() "--set-counters -c chain\n" " pcnt bcnt : set the counters of the to be added rule\n" "--modprobe -M program : try to insert modules using this program\n" +"--concurrent : use a file lock to support concurrent scripts\n" "--version -V : print package version\n\n" "Environment variable:\n" ATOMIC_ENV_VARIABLE " : if set <FILE> (see above) will equal its value" @@ -525,6 +528,12 @@ void ebt_early_init_once() ebt_iterate_targets(merge_target); } +/* signal handler, installed when the option --concurrent is specified. */ +static void sighandler(int signum) +{ + exit(-1); +} + /* We use exec_style instead of #ifdef's because ebtables.so is a shared object. */ int do_command(int argc, char *argv[], int exec_style, struct ebt_u_replace *replace_) @@ -1037,6 +1046,11 @@ big_iface_length: replace->filename = (char *)malloc(strlen(optarg) + 1); strcpy(replace->filename, optarg); break; + case 13 : /* concurrent */ + signal(SIGINT, sighandler); + signal(SIGTERM, sighandler); + use_lockfd = 1; + break; case 1 : if (!strcmp(optarg, "!")) ebt_check_inverse2(optarg); |