summaryrefslogtreecommitdiffstats
path: root/eurephiafw.c
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2008-09-14 23:02:07 +0200
committerDavid Sommerseth <dazo@users.sourceforge.net>2008-09-14 23:02:07 +0200
commitab726a0092fc2f41c347fa86c48fb5bd4e27fa89 (patch)
treec713136a1feee132aa8749a9e2e73fee175c4ca1 /eurephiafw.c
parentad0df81c0cc8f9ef813dae560679f82d2086e1bb (diff)
downloadeurephia-ab726a0092fc2f41c347fa86c48fb5bd4e27fa89.tar.gz
eurephia-ab726a0092fc2f41c347fa86c48fb5bd4e27fa89.tar.xz
eurephia-ab726a0092fc2f41c347fa86c48fb5bd4e27fa89.zip
Moved creation and destruction of semaphores and message queue into an own helper file. eFW_StartFirewall() now creates and eFW_RunFirewall() destructs, using this helper file.alpha_0.5
Diffstat (limited to 'eurephiafw.c')
-rw-r--r--eurephiafw.c52
1 files changed, 7 insertions, 45 deletions
diff --git a/eurephiafw.c b/eurephiafw.c
index a5e665e..16328eb 100644
--- a/eurephiafw.c
+++ b/eurephiafw.c
@@ -35,11 +35,8 @@
#include "eurephiafw_intf.h"
#include "eurephia_getsym.h"
#include "eurephia_nullsafe.h"
-#include "eurephiafw_intf.h"
#include "eurephia_values.h"
-
-#define MQUEUE_NAME "/eurephiaFW"
-
+#include "eurephiafw_helpers.h"
int eFW_unload(eurephiaCTX *ctx) {
if( ctx == NULL ) {
@@ -127,29 +124,14 @@ void eFW_StartFirewall(eurephiaCTX *ctx) {
eurephia_log(ctx, LOG_INFO, 3, "Starting eurephia firewall interface");
- // Initialise the main process' semaphore
- ctx->fwcfg->thrdata.semp_master = sem_open("eurephia_fwmaster", O_CREAT, 0666, 0);
- if( ctx->fwcfg->thrdata.semp_master == SEM_FAILED ) {
- eurephia_log(ctx, LOG_FATAL, 0, "Could not setup semaphore for FW driver: %s", strerror(errno));
- free_nullsafe(ctx->fwcfg);
+ // Setup semaphores we need
+ if( efwSetupSemaphores(ctx, &(*ctx->fwcfg).thrdata) == 0 ) {
+ free_nullsafe(ctx->fwcfg->thrdata.fw_command);
return;
- }
-
- // Initialise the worker process' semaphore
- ctx->fwcfg->thrdata.semp_worker = sem_open("eurephia_fwworker", O_CREAT, 0666, 0);
- if( ctx->fwcfg->thrdata.semp_worker == SEM_FAILED ) {
- eurephia_log(ctx, LOG_FATAL, 0, "Could setup semaphore in eFW_RunFirewall: %s", strerror(errno));
- return;
- }
-
+ };
- // Prepare a POSIX Message Queue
- mqattr.mq_maxmsg = 10;
- mqattr.mq_msgsize = 1024;
- mqattr.mq_flags = 0;
- (*ctx->fwcfg).thrdata.msgq = mq_open(MQUEUE_NAME, O_RDWR | O_CREAT, 0600, &mqattr);
- if( (*ctx->fwcfg).thrdata.msgq < 0 ) {
- eurephia_log(ctx, LOG_FATAL, 0, "Could not open message queue: %s", strerror(errno));
+ // Setup a message queue
+ if( efwSetupMessageQueue(ctx, &(*ctx->fwcfg).thrdata) == 0 ) {
free_nullsafe(ctx->fwcfg);
return;
}
@@ -174,9 +156,6 @@ void eFW_StartFirewall(eurephiaCTX *ctx) {
ctx->fwcfg->fwproc_pid);
}
- // Let child have time to settle
- sleep(2);
-
// Flush the message queue for old messages
if( mq_getattr((*ctx->fwcfg).thrdata.msgq, &mqattr) == 0 ) {
long i;
@@ -235,23 +214,6 @@ void eFW_StopFirewall(eurephiaCTX *ctx) {
kill(ctx->fwcfg->fwproc_pid, SIGABRT);
}
- // Close and remove the message queue used
- if( mq_close((*ctx->fwcfg).thrdata.msgq) != 0 ) {
- eurephia_log(ctx, LOG_WARNING, 0, "Could not do close the message queue used for eFW: %s",
- strerror(errno));
- }
-
- if( mq_unlink(MQUEUE_NAME) != 0 ) {
- eurephia_log(ctx, LOG_WARNING, 0, "Could not do close the message queue used for eFW: %s",
- strerror(errno));
- }
-
- // Take down the semaphore we used
- if( sem_close(ctx->fwcfg->thrdata.semp_master) != 0 ) {
- eurephia_log(ctx, LOG_WARNING, 0, "Could not do destroy the driver semaphore for eFW: %s",
- strerror(errno));
- }
- sem_unlink("eurephia_fwmaster");
free_nullsafe((*ctx->fwcfg).thrdata.fw_command);
free_nullsafe(ctx->fwcfg);
eurephia_log(ctx, LOG_INFO, 3, "eurephia firewall interface is stopped");