]> source.dussan.org Git - rspamd.git/commitdiff
Fix locking issues with sqlite
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 25 Jan 2016 16:10:21 +0000 (16:10 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 25 Jan 2016 16:10:21 +0000 (16:10 +0000)
src/libutil/sqlite_utils.c
src/lua/lua_sqlite3.c

index 270922eb6459b85cb52cb4fb9a2149ac522f9025..d9b4417617d8de900d7237e633c041e4359db5fd 100644 (file)
@@ -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;
index 1f8eac1439945ae2d9add45bc4f73ea7575bd0e1..34a5a9e1940c5b8f3aa2690dd7dee42817071e57 100644 (file)
@@ -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},