summaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2008-11-01 12:13:52 +0100
committerDavid Sommerseth <dazo@users.sourceforge.net>2008-11-01 12:13:52 +0100
commit64f6478a2dac17994566c4d59a302bd4f816b31f (patch)
treec8539a3ec275d46b99b6868b1bcb3850f00271f9 /plugin
parente2b56924035977f1a8aac1b87372ad0be6eb51e8 (diff)
downloadeurephia-64f6478a2dac17994566c4d59a302bd4f816b31f.tar.gz
eurephia-64f6478a2dac17994566c4d59a302bd4f816b31f.tar.xz
eurephia-64f6478a2dac17994566c4d59a302bd4f816b31f.zip
BUGFIX (2/2) ... implemented master side fix of shutdown bug
Also changed the worker side to use sem_timedwait(), to not wait forever on shutdown acknowledge
Diffstat (limited to 'plugin')
-rw-r--r--plugin/firewall/eurephiafw.c22
-rw-r--r--plugin/firewall/iptables/efw_iptables.c22
2 files changed, 40 insertions, 4 deletions
diff --git a/plugin/firewall/eurephiafw.c b/plugin/firewall/eurephiafw.c
index 4df4459..4c57ae5 100644
--- a/plugin/firewall/eurephiafw.c
+++ b/plugin/firewall/eurephiafw.c
@@ -28,6 +28,7 @@
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <time.h>
#include "eurephia_struct.h"
#include "eurephia_log.h"
@@ -213,7 +214,7 @@ void eFW_StartFirewall(eurephiaCTX *ctx) {
void eFW_StopFirewall(eurephiaCTX *ctx) {
char buf[520], *fwdest = NULL;
- int childret = -1;
+ struct timespec tsp;
if( ctx->fwcfg == NULL ) {
return;
@@ -246,13 +247,30 @@ void eFW_StopFirewall(eurephiaCTX *ctx) {
kill(ctx->fwcfg->fwproc_pid, SIGABRT);
}
+ //
// Wait for the firewall module process to finish
- if( waitpid(ctx->fwcfg->fwproc_pid, &childret, 0) != ctx->fwcfg->fwproc_pid ) {
+ //
+
+ // prepare a timeout - 30 secounds should be enough
+ if( clock_gettime(CLOCK_REALTIME, &tsp) == -1 ) {
+ eurephia_log(ctx, LOG_FATAL, 0, "Could not prepare timeout for firewall shutdown: %s",
+ strerror(errno));
+ sleep(3);
+ kill(ctx->fwcfg->fwproc_pid, SIGABRT);
+ }
+ tsp.tv_sec += 30;
+
+ // Wait for shutdown accepted signal
+ if( sem_timedwait(ctx->fwcfg->thrdata.semp_worker, &tsp) == -1 ) {
eurephia_log(ctx, LOG_PANIC, 0, "Failed to wait for eFW module process to quit: %s",
strerror(errno));
+ sleep(3);
kill(ctx->fwcfg->fwproc_pid, SIGABRT);
}
+ // Send acknowledge back
+ sem_post(ctx->fwcfg->thrdata.semp_master);
+
free_nullsafe((*ctx->fwcfg).thrdata.fw_command);
free_nullsafe(ctx->fwcfg);
eurephia_log(ctx, LOG_INFO, 2, "eurephia firewall interface is stopped");
diff --git a/plugin/firewall/iptables/efw_iptables.c b/plugin/firewall/iptables/efw_iptables.c
index 3d173d3..f238222 100644
--- a/plugin/firewall/iptables/efw_iptables.c
+++ b/plugin/firewall/iptables/efw_iptables.c
@@ -26,6 +26,7 @@
#include <pthread.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <time.h>
#include <eurephia_nullsafe.h>
#include <eurephia_log.h>
@@ -54,6 +55,7 @@ void eFW_RunFirewall(void *fwargs) {
int quit = 0;
unsigned int prio;
char buf[EFW_MSG_SIZE+2];
+ struct timespec tsp;
DEBUG(ctx, 28, "eFW_RunFirewall: Waiting for eFW master to get ready");
sem_wait(cfg->semp_master);
@@ -67,6 +69,8 @@ void eFW_RunFirewall(void *fwargs) {
exit(3);
}
+ eurephia_log(ctx, LOG_INFO, 1, "efw_iptables: Firewall interface started");
+
// Main loop ... grab messages of the messague queue until shutdown command is sent, or a failure happens
while( quit == 0 ) {
memset(buf, 0, EFW_MSG_SIZE+2);
@@ -98,8 +102,22 @@ void eFW_RunFirewall(void *fwargs) {
sem_post(cfg->semp_worker);
DEBUG(ctx, 28, "eFW_RunFirewall: Waiting for eFW master to acknowledge");
- sem_wait(cfg->semp_master);
-
+ // Prepare a timeout
+ if( clock_gettime(CLOCK_REALTIME, &tsp) == -1 ) {
+ eurephia_log(ctx, LOG_FATAL, 0, "eFW_RunFirewall: Could not prepare timeout for shutdown ack: %s",
+ strerror(errno));
+ sleep(10);
+ } else {
+ tsp.tv_sec += 30; // Wait up to 30 seconds for shutdown ack.
+
+ // Wait for acknowledge
+ if( sem_timedwait(cfg->semp_master, &tsp) == -1 ) {
+ eurephia_log(ctx, LOG_PANIC, 0, "eFW_RunFirewall: Did not receive any shutdown ack: %s",
+ strerror(errno));
+ } else {
+ eurephia_log(ctx, LOG_INFO, 1, "efw_iptables: Firewall interface shutdown");
+ }
+ }
efwRemoveSemaphores(ctx, fwargs);
exit(0);
}