Skip to main content

Module lock

Module lock 

Source
Expand description

UUCP-style lock files.

Multiple programs sharing a serial port is a recipe for corrupt data and confused users. The UUCP convention — adopted by uucp, picocom, tio, minicom, and most modems-with-fortunes utilities since the 1980s — solves this with a per-device flag file:

  • Path: /var/lock/LCK..<basename> for <basename> derived from the device path (/dev/ttyUSB0ttyUSB0).
  • Content: the owning process’s PID, formatted as 10 ASCII characters right-aligned with leading spaces, followed by \n.
  • Stale-lock recovery: a process opening the device reads the PID, sends signal 0 with kill(pid, 0). Ok means the holder is alive, refuse to open. ESRCH means the holder is gone, remove the file and proceed.

/var/lock is typically root:lock 1775 on modern distros, so an unprivileged user without group lock cannot create files there. UucpLock::acquire falls back to /tmp in that case (with a tracing::warn) — the lock is then per-user instead of system-wide, but still protects the same user from racing themselves.

On Windows, UucpLock is a no-op shim — the OS already serialises CreateFile on a COM port via SHARE_MODE = 0. v0.1 leaves the Windows path empty so the call site stays cross-platform.

Structs§

UucpLock
RAII handle for a UUCP lock file. Drops it when this value goes out of scope.