From: Vsevolod Stakhov Date: Fri, 29 Jul 2016 10:07:25 +0000 (+0100) Subject: [Fix] Fix another locking issue in sqlite X-Git-Tag: 1.3.1~29 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=81de74b0031756bf388466514ffead549335e930;p=rspamd.git [Fix] Fix another locking issue in sqlite --- 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);