Skip to contentSkip to conversation

Use flock() for --concurrent option

PATCH Applied Phil Sutter 2 participants 2 messages Oct 6, 2017 – Oct 24, 2017 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/1 Use flock() for --concurrent option

The previous locking mechanism was not atomic, hence it was possible that a killed ebtables process would leave the lock file in place which in turn made future ebtables processes wait indefinitely for the lock to become free.

Fix this by using flock(). This also simplifies code quite a bit because there is no need for a custom signal handler or an __exit routine anymore.

---
 ebtables.c |  8 --------
 libebtc.c  | 49 +++++--------------------------------------------
 2 files changed, 5 insertions(+), 52 deletions(-)
ebtables.c +0 -8
index 62f1ba80063d8..f7dfccf4b2f31 100644
@@ -528,12 +528,6 @@ 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_)
@@ -1047,8 +1041,6 @@ big_iface_length:
 			strcpy(replace->filename, optarg);
 			break;
 		case 13 : /* concurrent */
-			signal(SIGINT, sighandler);
-			signal(SIGTERM, sighandler);
 			use_lockfd = 1;
 			break;
 		case 1 :
libebtc.c +5 -44

69 lines not on this page · raw message

Signature · 1 line
2.13.1
maintainer Applied
#1 lore raw
Quoted 8 lines · Phil Sutter

The previous locking mechanism was not atomic, hence it was possible that a killed ebtables process would leave the lock file in place which in turn made future ebtables processes wait indefinitely for the lock to become free.

Fix this by using flock(). This also simplifies code quite a bit because there is no need for a custom signal handler or an __exit routine anymore.

Applied, thanks Phil.