#pragma once // Single-instance guard: bind an abstract-namespace Unix socket whose name is derived // from the canonical runtime directory (resolve_runtime_dir's result — already the // per-user default, /run/user//velox, unless XDG_RUNTIME_DIR says otherwise). A // second daemon pointed at the same runtime dir gets EADDRINUSE and exits; one pointed at // a different (isolated / test) runtime dir gets its own lock and starts fine. The kernel // reclaims an abstract-namespace address when the holding process dies, so a crash never // wedges it (docs/01 §2). // // Naming this "velox-daemon-" alone (the old scheme) meant exactly one name per // user system-wide, so XDG_RUNTIME_DIR isolation never reached it: a leaked test veloxd // with the same euid held the lock for every isolated instance too, real or test, until // it was killed. Hashing the resolved runtime dir path instead keeps the real per-user // daemon unique (its runtime dir is unique to it) while letting isolated instances that // each point at their own runtime dir coexist. #include namespace velox::daemon::rpc { // Returns the held fd (kept open for the process lifetime; closing it releases the lock) // or -1 if another process already holds the lock for this exact `runtime_dir`, or on any // other socket error. int acquire_single_instance_lock(const std::string& runtime_dir); } // namespace velox::daemon::rpc