diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-01-25 16:10:21 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-01-25 16:10:21 +0000 |
commit | 0fa975e21b80eb1423d0bdbcaa825ab01025d6c5 (patch) | |
tree | 8481108d117c9fe9d701926469e0a48f1d075b11 | |
parent | 5eb9938636b0ef004df7038eeae4fa98c0cb208e (diff) | |
download | rspamd-0fa975e21b80eb1423d0bdbcaa825ab01025d6c5.tar.gz rspamd-0fa975e21b80eb1423d0bdbcaa825ab01025d6c5.zip |
Fix locking issues with sqlite
-rw-r--r-- | src/libutil/sqlite_utils.c | 27 | ||||
-rw-r--r-- | src/lua/lua_sqlite3.c | 2 |
2 files changed, 16 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; diff --git a/src/lua/lua_sqlite3.c b/src/lua/lua_sqlite3.c index 1f8eac143..34a5a9e19 100644 --- a/src/lua/lua_sqlite3.c +++ b/src/lua/lua_sqlite3.c @@ -59,6 +59,8 @@ static const struct luaL_reg sqlitelib_f[] = { static const struct luaL_reg sqlitelib_m[] = { LUA_INTERFACE_DEF (sqlite3, sql), + {"query", lua_sqlite3_sql}, + {"exec", lua_sqlite3_sql}, LUA_INTERFACE_DEF (sqlite3, rows), {"__tostring", rspamd_lua_class_tostring}, {"__gc", lua_sqlite3_close}, |