diff options
author | Bjørn Mork <bjorn@mork.no> | 2016-01-20 18:46:57 +0100 |
---|---|---|
committer | Bjørn Mork <bjorn@mork.no> | 2016-01-20 18:46:57 +0100 |
commit | 7f8d8aa7a9e542524e9edfcca1fe1220abbf8e40 (patch) | |
tree | 3e8f99b8bc981a3254e3c78b84fedfa883ad8f9a /eperd/eooqd.c | |
parent | f8271f58d0f47f7a7ffa787512c227982eb4d6f2 (diff) |
ripe-atlas-fw: imported version 47204720
Signed-off-by: Bjørn Mork <bjorn@mork.no>
Diffstat (limited to 'eperd/eooqd.c')
-rw-r--r-- | eperd/eooqd.c | 32 |
1 files changed, 28 insertions, 4 deletions
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; } |