https://gitlab.synchro.net/main/sbbs/-/commit/68112b033c7a90087bf44096
Modified Files:
docs/v322_new.md src/sbbs3/scfgsave.c
Log Message:
SCFG: rewrite config files in place under a lock instead of renaming
Saving a configuration file wrote <name>.ini.tmp and renamed it over the
live file. On an SMB/CIFS share (such as a ctrl directory shared with
Samba), renaming over a file that another program has open fails, and
the target is deleted when that program closes it; the save then
removed its .tmp file too, so a server or utility loading the
configuration during a save could leave the file missing altogether.
write_cfg_file() now copies the live file to its backup, opens it with
fnopen() (an exclusive lock, waiting while a reader holds its shared
lock) without truncating it, truncates it once locked, and writes the
new contents in place. Programs loading the configuration open it with
fnopen() too, so they wait for the save and read either the whole old
file or the whole new one. The file is never renamed or removed.
Tested on the CIFS-mounted /sbbs, saving msgs.ini five times while two
readers polled it continuously: with the rename, msgs.ini was deleted on
the first save; now a reader that locks like fnopen() saw no missing or truncated file in about 100,000 reads. A save without competing readers
takes about 20 ms longer than the original rename-and-rewrite code (the
backup is now a copy).
A reader that does not lock (a Windows host reading over SMB while a
*nix host saves) can still get a read error during the write itself, as
with any file Synchronet shares between hosts.
Co-Authored-By: Claude Opus 5.5 <
noreply@anthropic.com>
---
þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net