aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil/sqlite_utils.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-07-29 11:07:25 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-07-29 11:07:25 +0100
commit81de74b0031756bf388466514ffead549335e930 (patch)
tree33e83d66d54d698c1c014584bcd6c05df72b2482 /src/libutil/sqlite_utils.c
parenta69d2f2d7245edd5a9d0bd041ac900b43110cc57 (diff)
downloadrspamd-81de74b0031756bf388466514ffead549335e930.tar.gz
rspamd-81de74b0031756bf388466514ffead549335e930.zip
[Fix] Fix another locking issue in sqlite
Diffstat (limited to 'src/libutil/sqlite_utils.c')
-rw-r--r--src/libutil/sqlite_utils.c19
1 files 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);