r = sqlite3_open_v2(dbpath, &db,
readonly ? SQLITE_OPEN_READONLY :
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
+
+ if (db_exist && r == SQLITE_CORRUPT) {
+ bxt_err("Open '%s' failed: %s", dbpath, sqlite3_errmsg(db));
+
+ if (!strncmp("/etc", dbpath, 4))
+ return NULL;
+
+ bxt_err("Try to remove %s and restore to default value.",
+ dbpath);
+
+ if (unlink(dbpath))
+ return NULL;
+
+ db_exist = false;
+ r = sqlite3_open_v2(dbpath, &db,
+ readonly ? SQLITE_OPEN_READONLY :
+ SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
+ }
+
if (r) {
bxt_err("Open '%s' failed: %s", dbpath, sqlite3_errmsg(db));
errno = EIO;