From 9671efdf0f9ebe5a1a98d1cf81c50e575192d285 Mon Sep 17 00:00:00 2001 From: Percy Wegmann Date: Wed, 4 Mar 2026 15:36:02 -0600 Subject: [PATCH] conditionally compile released SQLite on ifndef SQLITE_TRUNK Also log a warning when SQLite trunk detects when the WAL is wrapped after the header was read for a checkpoint. Updates tailscale/corp#37997 Signed-off-by: Percy Wegmann --- cgosqlite/cgosqlite.go | 1 - cgosqlite/sqlite3.c | 2 +- cgosqlite/sqlite3_trunk.c | 1 + update-sqlite.sh | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cgosqlite/cgosqlite.go b/cgosqlite/cgosqlite.go index a9ef37e..c060f51 100644 --- a/cgosqlite/cgosqlite.go +++ b/cgosqlite/cgosqlite.go @@ -8,7 +8,6 @@ package cgosqlite // One exception is we do not use SQLITE_OMIT_DECLTYPE, as the design // of the database/sql driver seems to require it. -#cgo !sqlite_trunk CFLAGS: -DSQLITE_RELEASE #cgo sqlite_trunk CFLAGS: -DSQLITE_TRUNK #cgo CFLAGS: -DSQLITE_THREADSAFE=2 #cgo CFLAGS: -DSQLITE_DQS=0 diff --git a/cgosqlite/sqlite3.c b/cgosqlite/sqlite3.c index 5f82bc7..00b742e 100644 --- a/cgosqlite/sqlite3.c +++ b/cgosqlite/sqlite3.c @@ -1,4 +1,4 @@ -#ifdef SQLITE_RELEASE +#ifndef SQLITE_TRUNK /****************************************************************************** ** This file is an amalgamation of many separate C source files from SQLite diff --git a/cgosqlite/sqlite3_trunk.c b/cgosqlite/sqlite3_trunk.c index 07ad841..7b3949f 100644 --- a/cgosqlite/sqlite3_trunk.c +++ b/cgosqlite/sqlite3_trunk.c @@ -69164,6 +69164,7 @@ static int walCheckpoint( ** the wal file. It would also be dangerous to proceed, as there may be ** fewer than pWal->hdr.mxFrame valid frames in the wal file. */ int bChg = memcmp(pLive->aSalt, pWal->hdr.aSalt, sizeof(pWal->hdr.aSalt)); + if( bChg ) sqlite3_log(SQLITE_WARNING, "wal wrapped after header was read for this checkpoint"); if( 0==bChg ){ pInfo->nBackfillAttempted = mxSafeFrame; SEH_INJECT_FAULT; diff --git a/update-sqlite.sh b/update-sqlite.sh index 3bd9dc2..4e24e67 100755 --- a/update-sqlite.sh +++ b/update-sqlite.sh @@ -42,7 +42,7 @@ unzip "$filename" || fatal "Unzip of $filename failed" mv "$dirname"/*.{c,h} . mv shell.c shell.c.disabled mv sqlite3.c sqlite3.c_partial -printf "#ifdef SQLITE_RELEASE\n\n" > sqlite3.c +printf "#ifndef SQLITE_TRUNK\n\n" > sqlite3.c cat sqlite3.c_partial >> sqlite3.c printf "\n\n#endif\n" >> sqlite3.c rm sqlite3.c_partial