File: src/main.zig:18,48–69,204–217
Severity: MEDIUM
Status: ✅ FIXED — logFn updated to format/write messages atomically in a single write call, and log_fd is closed/nullified in the child process immediately post-fork.
var log_fd: ?std.posix.fd_t = null; // module-level static
pub fn logFn(...) void {
if (log_fd == null) {
const fd = open(path, O_WRONLY | O_CREAT | O_APPEND, 0o666);
log_fd = fd;
}
const fd = log_fd.?;
writeAllRaw(fd, msg);
...
}
When main forks to create the server daemon, the child inherits the parent’s log_fd (or opens it independently, sharing the inode). Both processes then call logFn which does c.write() to the same fd/inode without any synchronisation. For the brief period between fork and parent exit, log lines from child and parent interleave. After parent exits, only the child writes. Corrupts the first few log lines on every startup.