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 /miscutils/ooqd.c | |
parent | f8271f58d0f47f7a7ffa787512c227982eb4d6f2 (diff) |
ripe-atlas-fw: imported version 47204720
Signed-off-by: Bjørn Mork <bjorn@mork.no>
Diffstat (limited to 'miscutils/ooqd.c')
-rw-r--r-- | miscutils/ooqd.c | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/miscutils/ooqd.c b/miscutils/ooqd.c index 4317e05..85114c9 100644 --- a/miscutils/ooqd.c +++ b/miscutils/ooqd.c @@ -29,6 +29,7 @@ int ooqd_main(int argc, char *argv[]) { char *queue_file; FILE *file; + struct stat sb; char curr_qfile[256]; if (argc != 2) @@ -50,17 +51,37 @@ int ooqd_main(int argc, char *argv[]) for(;;) { - /* Try to move queue_file to curr_qfile. This provide at most - * once behavior and allows producers to create a new - * queue_file while we process the old one. - */ - if (rename(queue_file, curr_qfile) == -1) + if (stat(queue_file, &sb) == -1) { if (errno == ENOENT) { sleep(WAIT_TIME); continue; } + report_err("stat failed"); + return 1; + } + + /* 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(curr_qfile) == -1) + { + /* Expect ENOENT */ + if (errno != ENOENT) + { + report_err("unlink failed"); + return 1; + } + } + + /* Try to move queue_file to curr_qfile. This provide at most + * once behavior and allows producers to create a new + * queue_file while we process the old one. + */ + if (rename(queue_file, curr_qfile) == -1) + { report_err("rename failed"); return 1; } |