daemon: Phase 0 platform seams (ADR 0020) — eventfd/SO_PEERCRED/instance-lock/XDG behind platform/, zero behaviour change
Introduces the four rpc-layer seams docs/08-porting.md calls for this lane: platform::Wakeup (eventfd), platform::peer_of (SO_PEERCRED/struct ucred, same-UID check preserved unchanged), platform::acquire_instance_lock (abstract-namespace socket), platform::runtime_base_dir/data_base_dir (XDG lookups). Today's Linux code moves unchanged into daemon/src/rpc/platform/linux/; the seam headers carry no OS types and no #ifdef. No fifth interface for timerfd: EventLoop gains a portable add_timer() that folds the next deadline into poll()'s own timeout, replacing both timerfd instances in main.cpp — the loop already computes a deadline, so this needs no per-OS backend at all. Full suite 59/59 green; no #ifdef outside platform/linux/, no behaviour change. Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#include "rpc/platform/runtime_paths.hpp"
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace velox::daemon::rpc::platform {
|
||||
|
||||
namespace {
|
||||
std::error_code errc(int e) { return std::error_code(e, std::generic_category()); }
|
||||
} // namespace
|
||||
|
||||
std::error_code runtime_base_dir(std::string& out) {
|
||||
if (const char* xdg = ::getenv("XDG_RUNTIME_DIR"); xdg != nullptr && xdg[0] != '\0') {
|
||||
out = xdg;
|
||||
return {};
|
||||
}
|
||||
const std::string base = "/run/user/" + std::to_string(::geteuid());
|
||||
struct stat st{};
|
||||
if (::stat(base.c_str(), &st) != 0 || !S_ISDIR(st.st_mode)) {
|
||||
// No XDG_RUNTIME_DIR and no /run/user/<uid>: refuse rather than pick an insecure
|
||||
// fallback. The caller surfaces this as "cannot start".
|
||||
return errc(ENOENT);
|
||||
}
|
||||
out = base;
|
||||
return {};
|
||||
}
|
||||
|
||||
std::error_code data_base_dir(std::string& out) {
|
||||
if (const char* xdg = ::getenv("XDG_DATA_HOME"); xdg != nullptr && xdg[0] != '\0') {
|
||||
out = xdg;
|
||||
return {};
|
||||
}
|
||||
if (const char* home = ::getenv("HOME"); home != nullptr && home[0] != '\0') {
|
||||
out = std::string(home) + "/.local/share";
|
||||
return {};
|
||||
}
|
||||
return errc(ENOENT);
|
||||
}
|
||||
|
||||
} // namespace velox::daemon::rpc::platform
|
||||
Reference in New Issue
Block a user