Expand description
Cross-platform single-instance process guard.
On startup a process tries to acquire an exclusive, non-blocking lock on a
named file under the user’s data dir. Holding the lock keeps a second
invocation of the same role from running — the GUI uses it to avoid a
duplicate window, the background agent to avoid two processes fighting over
the same devices and IPC socket. Each Role has its own lock file, so
the GUI and the agent don’t lock each other out. The lock is released by the
OS when the process exits, so crash-recovery is free: the next launch
reclaims the lock on the leftover file without any cleanup ceremony.
Structs§
- Instance
Guard - Held by
mainfor the duration of the run; dropped on exit (the OS releases the underlying file lock at the same time). The_handlefield is intentionally unused — the value is alive only for itsDropside effect of closing the fd.
Enums§
- Instance
Error - Failure acquiring the single-instance lock.
InstanceError::AlreadyRunningis the expected “another copy is open” signal; every other variant indicates filesystem trouble. - Role
- The processes that must run at most once per user, each on its own lock.
Functions§
- acquire
- Acquire the single-instance lock for
role(a file underpaths::config_dir). ReturnsOk(guard)on success — keep the guard alive until the process is about to exit.