• docs/v322_new.md src/sbbs3/scfgsave.c

    From Rob Swindell (on Debian Linux)@VERT to Git commit to main/sbbs/master on Mon Nov 23 22:45:05 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/b8a498150de718792f8c006a
    Modified Files:
    docs/v322_new.md src/sbbs3/scfgsave.c
    Log Message:
    SCFG: replace a config file only once its new contents are written

    Each write_*_cfg() (main, node, msgs, file, xtrn and chat .ini) first
    renamed the live file to its backup name, then built the new contents
    and wrote them in place. For the whole save the file was missing, then incomplete, and a program loading the configuration meanwhile got "No
    such file or directory" or a partial file: seen live with sbbsecho
    (FIDOIN event) loading during a save of file.ini.

    They now share write_cfg_file(), which writes <name>.ini.tmp, takes the
    backup with a copy instead of a rename, and then replaces the live file
    with xp_replace_file() (a rename on *nix, MoveFileEx() with MOVEFILE_REPLACE_EXISTING on Windows). A reader sees either the whole
    old file or the whole new one. In a test with a reader polling msgs.ini
    during `scfg -import`, the old code produced 1376 failed opens and 12
    truncated reads, the new code none.

    Fixes #1404

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Rob Swindell (on Debian Linux)@VERT to Git commit to main/sbbs/master on Mon Nov 23 22:45:05 2026
    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