From 7f8d8aa7a9e542524e9edfcca1fe1220abbf8e40 Mon Sep 17 00:00:00 2001 From: Bjørn Mork Date: Wed, 20 Jan 2016 18:46:57 +0100 Subject: ripe-atlas-fw: imported version 4720 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bjørn Mork --- eperd/eooqd.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'eperd/eooqd.c') diff --git a/eperd/eooqd.c b/eperd/eooqd.c index 04bfcd6..ed8ea64 100644 --- a/eperd/eooqd.c +++ b/eperd/eooqd.c @@ -189,20 +189,44 @@ static void checkQueue(evutil_socket_t fd UNUSED_PARAM, short what UNUSED_PARAM, void *arg UNUSED_PARAM) { int r; + struct stat sb; char filename[80]; if (!state->curr_file) { + if (stat(state->queue_file, &sb) == -1) + { + if (errno == ENOENT) + { + return; + } + report_err("stat failed"); + return; + } + + /* Remove curr_qfile. Renaming queue_file to curr_qfile + * will silently fail to delete queue_file if queue_file and + * curr_qfile are hard links. + */ + if (unlink(state->curr_qfile) == -1) + { + /* Expect ENOENT */ + if (errno != ENOENT) + { + report_err("unlink failed"); + return; + } + } + /* Try to move queue_file to curr_qfile. This provides at most * once behavior and allows producers to create a new * queue_file while we process the old one. */ if (rename(state->queue_file, state->curr_qfile) == -1) { - if (errno == ENOENT) - { - return; - } + /* We verified queue_file is there so any failure is + * fatal. + */ report_err("rename failed"); return; } -- cgit v1.2.3