// The single-instance lock: isolated by runtime dir, not just by euid. This is the bug a // leaked test veloxd exploited — one abstract-socket name per user meant every isolated // instance (real daemon, tests, other lanes) fought over the same lock. #include #include "check.hpp" #include "rpc/single_instance.hpp" using namespace velox::daemon::rpc; void run() { // Two different runtime dirs: both acquire the lock independently. { const int a = acquire_single_instance_lock("/run/user/1000/velox-test-a"); const int b = acquire_single_instance_lock("/run/user/1000/velox-test-b"); CHECK(a >= 0); CHECK(b >= 0); if (a >= 0) ::close(a); if (b >= 0) ::close(b); } // Same runtime dir: the second attempt is refused while the first still holds it. { const int first = acquire_single_instance_lock("/run/user/1000/velox-test-shared"); CHECK(first >= 0); const int second = acquire_single_instance_lock("/run/user/1000/velox-test-shared"); CHECK(second < 0); if (first >= 0) ::close(first); if (second >= 0) ::close(second); // Releasing (closing) the fd frees the abstract-namespace name immediately — a // third attempt at the same dir succeeds once the first is gone. const int third = acquire_single_instance_lock("/run/user/1000/velox-test-shared"); CHECK(third >= 0); if (third >= 0) ::close(third); } } TEST_MAIN()