summaryrefslogtreecommitdiffstats
path: root/src/libutil/sqlite_utils.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-01-25 16:10:21 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-01-25 16:10:21 +0000
commit0fa975e21b80eb1423d0bdbcaa825ab01025d6c5 (patch)
tree8481108d117c9fe9d701926469e0a48f1d075b11 /src/libutil/sqlite_utils.c
parent5eb9938636b0ef004df7038eeae4fa98c0cb208e (diff)
downloadrspamd-0fa975e21b80eb1423d0bdbcaa825ab01025d6c5.tar.gz
rspamd-0fa975e21b80eb1423d0bdbcaa825ab01025d6c5.zip
Fix locking issues with sqlite
Diffstat (limited to 'src/libutil/sqlite_utils.c')
-rw-r--r--src/libutil/sqlite_utils.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/libutil/sqlite_utils.c b/src/libutil/sqlite_utils.c
index 270922eb6..d9b441761 100644
--- a/src/libutil/sqlite_utils.c
+++ b/src/libutil/sqlite_utils.c
@@ -243,7 +243,7 @@ rspamd_sqlite3_wait (rspamd_mempool_t *pool, const gchar *lock)
}
rspamd_file_unlock (fd, FALSE);
-
+ unlink (lock);
close (fd);
return TRUE;
@@ -346,7 +346,7 @@ rspamd_sqlite3_open_or_create (rspamd_mempool_t *pool, const gchar *path, const
return NULL;
}
- if (create) {
+ if (create && has_lock) {
if (sqlite3_exec (sqlite, sqlite_wal, NULL, NULL, NULL) != SQLITE_OK) {
msg_warn_pool_check ("WAL mode is not supported (%s), locking issues might occur",
sqlite3_errmsg (sqlite));
@@ -357,21 +357,22 @@ rspamd_sqlite3_open_or_create (rspamd_mempool_t *pool, const gchar *path, const
sqlite3_errmsg (sqlite));
}
- if (sqlite3_exec (sqlite, create_sql, NULL, NULL, NULL) != SQLITE_OK) {
- g_set_error (err, rspamd_sqlite3_quark (),
- -1, "cannot execute create sql `%s`: %s",
- create_sql, sqlite3_errmsg (sqlite));
- sqlite3_close (sqlite);
- rspamd_file_unlock (lock_fd, FALSE);
- unlink (lock_path);
- close (lock_fd);
-
- return NULL;
+ if (create_sql) {
+ if (sqlite3_exec (sqlite, create_sql, NULL, NULL, NULL) != SQLITE_OK) {
+ g_set_error (err, rspamd_sqlite3_quark (),
+ -1, "cannot execute create sql `%s`: %s",
+ create_sql, sqlite3_errmsg (sqlite));
+ sqlite3_close (sqlite);
+ rspamd_file_unlock (lock_fd, FALSE);
+ unlink (lock_path);
+ close (lock_fd);
+
+ return NULL;
+ }
}
sqlite3_close (sqlite);
-
/* Reopen in normal mode */
msg_debug_pool_check ("reopening %s in normal mode", path);
flags &= ~SQLITE_OPEN_CREATE;