]> granicus.if.org Git - vnstat/commitdiff
improve daemon resiliency against database locks caused by reads from other processes...
authorTeemu Toivola <git@humdi.net>
Sun, 28 Jul 2019 15:11:17 +0000 (18:11 +0300)
committerTeemu Toivola <git@humdi.net>
Sun, 28 Jul 2019 15:11:17 +0000 (18:11 +0300)
src/dbsql.c

index 9c4845db07f3336e522d0478fbe6d11198b83371..7e2683dd4bf01ecfd802cada16fb4767bdfd521a 100644 (file)
@@ -101,6 +101,7 @@ int db_open(const int createifnotfound, const int readonly)
 
        /* set pragmas */
        if (!readonly) {
+               sqlite3_busy_timeout(db, cfg.updateinterval * 1000);
                if (!db_setpragmas()) {
                        db_close();
                        return 0;
@@ -1045,9 +1046,13 @@ int db_committransaction(void)
 
        rc = sqlite3_exec(db, "COMMIT", 0, 0, 0);
        if (rc) {
-               db_errcode = rc;
                snprintf(errorstring, 1024, "Commit transaction to database failed (%d): %s", rc, sqlite3_errmsg(db));
                printe(PT_Error);
+               /* execute rollback if commit failure left the transaction open */
+               if (!sqlite3_get_autocommit(db)) {
+                       db_rollbacktransaction();
+               }
+               db_errcode = rc;
                db_intransaction = 0;
                return 0;
        }