diff options
author | David Sommerseth <dazo@users.sourceforge.net> | 2008-09-14 12:39:39 +0200 |
---|---|---|
committer | David Sommerseth <dazo@users.sourceforge.net> | 2008-09-14 12:39:39 +0200 |
commit | fa657fbcb1ef92f5d542a4ab21e6ee777117b346 (patch) | |
tree | df2caa6d8e22103a9921ea97926962a16eb85ba3 /eurephiafw.c | |
parent | 9709234c8ce4373670720adc03a8aa37dc48fc9f (diff) | |
download | eurephia-fa657fbcb1ef92f5d542a4ab21e6ee777117b346.tar.gz eurephia-fa657fbcb1ef92f5d542a4ab21e6ee777117b346.tar.xz eurephia-fa657fbcb1ef92f5d542a4ab21e6ee777117b346.zip |
Flushing message queue for firewall updates before telling firewall thread we are ready
Diffstat (limited to 'eurephiafw.c')
-rw-r--r-- | eurephiafw.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/eurephiafw.c b/eurephiafw.c index e4cb35a..72caa04 100644 --- a/eurephiafw.c +++ b/eurephiafw.c @@ -102,6 +102,7 @@ int eFW_load(eurephiaCTX *ctx, const char *intf) { void eFW_StartFirewall(eurephiaCTX *ctx) { struct mq_attr mqattr; eurephiaCTX *shadowctx = NULL; + struct mq_attr mqatrs; ctx->fwcfg = (eurephiaFWINTF *) malloc(sizeof(eurephiaFWINTF)+2); memset(ctx->fwcfg, 0, sizeof(eurephiaFWINTF)+2); @@ -157,6 +158,31 @@ void eFW_StartFirewall(eurephiaCTX *ctx) { // Let child have time to settle and create a semaphore for us sleep(1); + // Flush the message queue for old messages + if( mq_getattr((*ctx->fwcfg).thrdata.msgq, &mqatrs) == 0 ) { + long i; + char buf[1026]; + unsigned int prio; + + memset(&buf, 0, 1026); + if( mqatrs.mq_curmsgs > 0 ) { + for( i = 0; i < mqatrs.mq_curmsgs; i++ ) { + if( mq_receive((*ctx->fwcfg).thrdata.msgq, &buf[0], 1024, &prio) == -1 ) { + eurephia_log(ctx, LOG_CRITICAL, 0, + "Error while emptying messages from queue: %s", + strerror(errno)); + } else { + eurephia_log(ctx, LOG_DEBUG, 22, + "Removed message on queue: %s", buf); + } + } + } + eurephia_log(ctx, LOG_INFO, 3, "Message queue for firewall updates is empty"); + } else { + eurephia_log(ctx, LOG_WARNING, 0, "Could not retrieve message queue attributes (%s)", + strerror(errno)); + } + // Indicate for the FW module that we are ready sem_post(&(*ctx->fwcfg).thrdata.semp_driver); |