From 307bbe68714e0f016249c776018a8f9db34147aa Mon Sep 17 00:00:00 2001 From: Bart De Schuymer Date: Sun, 19 Jun 2011 18:54:13 +0000 Subject: add logic to support the --concurrent option: use a file lock to support concurrent scripts running ebtables --- ebtables.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'ebtables.c') diff --git a/ebtables.c b/ebtables.c index d71a981..d5d24b0 100644 --- a/ebtables.c +++ b/ebtables.c @@ -26,6 +26,7 @@ #include #include #include +#include #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 (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); -- cgit v1.2.3