- Replay recovers every complete record before a torn final record (the normal result of a crash mid-append) and reports it through err, instead of rejecting the whole journal. SwapReplay_TruncatedLog is updated to the new behaviour. - A record that cannot be written (open/write failure, breaker open) marks the journal as having a gap. Later position-based records are dropped until a checkpoint re-establishes the content; recorders request one on the next edit (at most once per second). - A failed append is truncated back off the file, and a failed header write closes the file so the next attempt starts fresh. - Inserts over the 24-bit record limit are split into consecutive records; buffers too large to checkpoint are no longer snapshotted and rejected on every checkpoint. - Declining to delete an unreadable swap moves it to .corrupt so new edits are not appended behind the bad data. - NotifyFilenameChanged no longer writes a full checkpoint into the journal it is about to delete. Audit findings D7, P5. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015rcVQiiWyTzoNrsvLSaAfB
52 lines
1.7 KiB
C++
52 lines
1.7 KiB
C++
// SyscallWrappers.h - EINTR-safe syscall wrappers for kte
|
|
#pragma once
|
|
|
|
#include <string>
|
|
#include <cstddef>
|
|
#include <sys/stat.h>
|
|
|
|
namespace kte {
|
|
namespace syscall {
|
|
// EINTR-safe wrapper for open(2).
|
|
// Returns file descriptor on success, -1 on failure (errno set).
|
|
// Automatically retries on EINTR.
|
|
int Open(const char *path, int flags, mode_t mode = 0);
|
|
|
|
// EINTR-safe wrapper for close(2).
|
|
// Returns 0 on success, -1 on failure (errno set).
|
|
// Automatically retries on EINTR.
|
|
// Note: Some systems may not restart close() on EINTR, but we retry anyway
|
|
// as recommended by POSIX.1-2008.
|
|
int Close(int fd);
|
|
|
|
// EINTR-safe wrapper for fsync(2).
|
|
// Returns 0 on success, -1 on failure (errno set).
|
|
// Automatically retries on EINTR.
|
|
int Fsync(int fd);
|
|
|
|
// EINTR-safe wrapper for fstat(2).
|
|
// Returns 0 on success, -1 on failure (errno set).
|
|
// Automatically retries on EINTR.
|
|
int Fstat(int fd, struct stat *buf);
|
|
|
|
// EINTR-safe wrapper for fchmod(2).
|
|
// Returns 0 on success, -1 on failure (errno set).
|
|
// Automatically retries on EINTR.
|
|
int Fchmod(int fd, mode_t mode);
|
|
|
|
// EINTR-safe wrapper for ftruncate(2).
|
|
// Returns 0 on success, -1 on failure (errno set).
|
|
// Automatically retries on EINTR.
|
|
int Ftruncate(int fd, off_t length);
|
|
|
|
// EINTR-safe wrapper for mkstemp(3).
|
|
// Returns file descriptor on success, -1 on failure (errno set).
|
|
// Automatically retries on EINTR.
|
|
// Note: template_str must be a mutable buffer ending in "XXXXXX".
|
|
int Mkstemp(char *template_str);
|
|
|
|
// Note: rename(2) and unlink(2) are not wrapped because they operate on
|
|
// filesystem metadata and typically complete atomically without EINTR.
|
|
// If interrupted, they either succeed or fail without partial state.
|
|
} // namespace syscall
|
|
} // namespace kte
|