From 8a76f6d2556e4b471a77bb07e698d1f1fdb48898 Mon Sep 17 00:00:00 2001 From: Preston Pfarner Date: Thu, 6 May 2010 04:09:25 +0000 Subject: [PATCH] Changing queue_to_journal such that it cleanly exits on QUIT, rather than listening forever. git-svn-id: https://lwes.svn.sourceforge.net/svnroot/lwes/lwes-journaller/trunk@473 a2f82657-cdd2-4550-bd36-68a8e7111808 --- src/queue_mqueue.c | 9 +++++++-- src/queue_to_journal.c | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/queue_mqueue.c b/src/queue_mqueue.c index 80e18f2..be19afc 100644 --- a/src/queue_mqueue.c +++ b/src/queue_mqueue.c @@ -25,6 +25,7 @@ #include "perror.h" #include "opt.h" +#include "sig.h" #if defined(HAVE_MQUEUE_H) @@ -37,6 +38,7 @@ #include #include #include +#include /* The following is for Solaris. */ #if !defined(MQ_PRIO_MAX) && defined(_POSIX_MQ_PRIO_MAX) @@ -133,6 +135,7 @@ static int xread (struct queue* this_queue, void* buf, struct mq_attr attr; int mq_rec_rtrn; unsigned int pri; + struct timespec time_buf = { time(NULL)+1, 500000000 }; if ( 0 == buf ) { @@ -145,10 +148,11 @@ static int xread (struct queue* this_queue, void* buf, return -1; } - LOG_PROG("about to call mq_receive().\n"); + LOG_PROG("about to call mq_receive(). gbl_done=%d\n", gbl_done); - if ( (mq_rec_rtrn = mq_receive (ppriv->mq, buf, count, &pri)) < 0 ) + if ( (mq_rec_rtrn = mq_timedreceive (ppriv->mq, buf, count, &pri, &time_buf)) < 0 ) { + LOG_PROG("errno: %d %s\n", errno, strerror(errno)); switch ( errno ) { default: @@ -156,6 +160,7 @@ static int xread (struct queue* this_queue, void* buf, /* If we've been interrupted it's likely that we're shutting down, so no need to print errors. */ + case ETIMEDOUT: case EINTR: return mq_rec_rtrn; } diff --git a/src/queue_to_journal.c b/src/queue_to_journal.c index 1ecb745..0cac85a 100644 --- a/src/queue_to_journal.c +++ b/src/queue_to_journal.c @@ -104,7 +104,7 @@ void* queue_to_journal(void* arg) } /* Read a packet from the queue, write it to the journal. */ - while ( ! gbl_done ) + while ( 1 ) { int que_read_ret; int jrn_write_ret; @@ -169,6 +169,8 @@ void* queue_to_journal(void* arg) if ( (que_read_ret = que.vtbl->read(&que, buf, bufsiz, &pending)) < 0 ) { + /* queue is empty; if we're shutting down, exit this loop. */ + if (gbl_done) break; /* queue is empty, is panic over? */ if ( journaller_panic_mode == PANIC_IN_EFFECT ) { -- 2.11.4.GIT