open
https://gitlab.synchro.net/main/sbbs/-/work_items/1380
When two hosts' web servers append to the same HTTP access log (a shared `data/` directory over SMB, as on Vertrauen, where `git` and `VERT` both write `data/logs/http-YYYY-MM-DD.log`), entries overwrite each other. One host's line is cut off mid-field, its closing `"` and newline are lost, and the other host's line continues on the same line:
```
57.141.2.65 - - [21/Nov/2026:02:18:04 -0800] "GET /?page=001-forum.ssjs&sub=syncprog&thread=57291 HTTP/1.1" 200 - "-" "Mozilla/5.0 (...) Chrome/145.0.0.0 Safari/537.36 (compatible; meta-externalagent/1.1 (+
https://developers.facebook.com/docs/swiki.synchro.net 37.133.222.72 - - [21/Nov/2026:02:18:06 -0800] "GET /familiarize?tab_details=history&do=media... HTTP/1.1" 200 21159 "-" "Mozilla/5.0 (Macintosh; ...)"
```
`http-2026-11-21.log` (about 420K lines by 12:40) has 29 such merged lines. In 26 of them a VERT record (custom log format, no vhost) is overwritten mid-line by a `git` record (default format with vhost), in 2 the reverse, and 1 is ambiguous. Each writer is appending at a stale end-of-file offset that doesn't yet include the other host's last write. Log parsers then miscount, and those lines lose their user agent.
## Cause
`http_logging_thread()` in `src/sbbs3/websrvr.cpp` keeps the log open for the whole day as a buffered stdio stream (`fopen(filename, "ab")`), and writes each entry like this:
```c
while (lock(fileno(logfile), 0, 1) && !terminate_http_logging_thread) {
SLEEP(10);
}
/* custom or default format: */
fprintf(logfile, ...);
unlock(fileno(logfile), 0, 1);
```
`fprintf()` only fills the stdio buffer. The `write()` that actually puts the bytes in the file happens later: when the buffer fills, or at the `fflush(logfile)` that runs only once the log queue goes idle. Both happen after `unlock()`. So the byte-range lock never covers a write and doesn't serialize anything between hosts. Without it, each host's append offset is whatever that host believes the end of file to be (the Linux CIFS client's cached size, or the CRT's seek-to-end before `write()` on Windows). Neither is atomic across SMB clients, so concurrent appends land on top of each other.
## Suggested fix
Make each entry a single locked write at the true end of file:
1. After acquiring the lock, seek to the end (`fseek(logfile, 0, SEEK_END)`), so the offset is re-read while the lock is held.
2. `fprintf()` the line, then `fflush(logfile)` **before** `unlock()`.
That gives up stdio batching across entries (one `write()` per request). The alternative, keeping the batching and holding the lock across a whole batch, is more involved. A cheaper variant: format into a local buffer and issue one `write()` on the fd, with the seek, all under the lock.
A single-host install is affected too whenever more than one process appends to the same log, but the cross-host SMB case is where it shows up in practice.
— *Authored by Claude (Claude Code), on behalf of @rswindell*
--- SBBSecho 3.38-Linux
* Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)