From 81de74b0031756bf388466514ffead549335e930 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 29 Jul 2016 11:07:25 +0100 Subject: [PATCH] [Fix] Fix another locking issue in sqlite --- src/libutil/sqlite_utils.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/libutil/sqlite_utils.c b/src/libutil/sqlite_utils.c index 04b71ca63..e2a530e2f 100644 --- a/src/libutil/sqlite_utils.c +++ b/src/libutil/sqlite_utils.c @@ -212,21 +212,13 @@ rspamd_sqlite3_wait (rspamd_mempool_t *pool, const gchar *lock) .tv_nsec = 1000000 }; - fd = open (lock, O_RDONLY); - - if (fd == -1) { + while ((fd = open (lock, O_WRONLY|O_CREAT|O_EXCL, 00600)) == -1) { + if (errno != EBUSY && errno != EEXIST) { + msg_err_pool_check ("cannot open lock file %s: %s", lock, + strerror (errno)); - if (errno == ENOENT) { - /* Lock is already released, so we can continue */ - return TRUE; + return FALSE; } - - msg_err_pool_check ("cannot open lock file %s: %s", lock, strerror (errno)); - - return FALSE; - } - - while (!rspamd_file_lock (fd, TRUE)) { if (nanosleep (&sleep_ts, NULL) == -1 && errno != EINTR) { close (fd); msg_err_pool_check ("cannot sleep open lock file %s: %s", lock, @@ -236,7 +228,6 @@ rspamd_sqlite3_wait (rspamd_mempool_t *pool, const gchar *lock) } } - rspamd_file_unlock (fd, FALSE); unlink (lock); close (fd); -- 2.39.5