pcloudcc-lneely/pclsync/debug
Levi Neely 90945b8817
Fix debug build: compile error, false-positive abort, crash DB lock (#372)
* Fix debug build: compile error, false-positive abort, and crash DB lock

- psql_debug.c: add forward declaration for psql_do_prepare to fix
  conflicting-types compile error (BUILD=debug was broken entirely)

- pfs_debug.c: change pfs_debug_check_lock_order from abort to log-only;
  write paths legitimately take file lock before SQL and handle ordering
  via psql_trylock()+relock in pfs_reopen_file_for_writing — no actual
  deadlock risk, the check was a false positive

- psignal.c/h: add psignal_register_cleanup() hook mechanism; change
  panic() to use _exit(1) instead of abort() so all file descriptors are
  closed on crash, releasing SQLite WAL POSIX advisory locks immediately
  and preventing ASan from hanging the process as a zombie

- psql.c: register psql_panic_cleanup() hook to close the DB on panic
  (belt-and-suspenders alongside _exit fd cleanup)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Fix debug psql_trylock: missing strong override left lockctr unupdated

The weak psql_trylock() stub in psql.c called plocks_trywrlock() directly
without updating lockctr. In the debug build, psql_unlock() asserts
lockctr > 0, so when trylock succeeded (lock acquired, lockctr still 0)
the assert fired with SIGABRT on write ops via pfs_inc_writeid_locked.

Add a strong psql_trylock() override in psql_debug.c that delegates to
psql_do_trylock(), which properly acquires the rwlock and updates lockctr.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 20:49:09 +01:00
..
pfs_debug.c Fix debug build: compile error, false-positive abort, crash DB lock (#372) 2026-03-09 20:49:09 +01:00
pfstasks_debug.c Fix debug build segfault: add strong overrides for psql_lock/unlock functions (#177) 2026-03-03 07:59:30 +01:00
pnetlibs_debug.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
psock_debug.c Fix debug build segfault: add strong overrides for psql_lock/unlock functions (#177) 2026-03-03 07:59:30 +01:00
psql_debug.c Fix debug build: compile error, false-positive abort, crash DB lock (#372) 2026-03-09 20:49:09 +01:00
psys_debug.c Fix debug build segfault: add strong overrides for psql_lock/unlock functions (#177) 2026-03-03 07:59:30 +01:00