The goal is to βblockβ access to a serial device or other Linux device in order to provide exclusive access to the device during its use. This prevents, for example, two programs opening the same serial device and βcompetingβ to read bytes from the device.
The tip was to use SYSV-style UUCP device lock files, such as /var/lock/LCK..ttyS1 . This is what Linux Serial HOTWO recommends: blocking others . It is also documented in the Heirarchy File System Standard . It is implemented by serial terminal programs such as gtkterm, picocom. Libraries exist such as liblockdev and liblockfile to support this (although implementation details vary between the two libraries).
However, I found a Debian bug # 734086 that talks about Linux, SYSV style UUCP device locks are outdated, and flock() should use locks instead.
However, I cannot find a reliable document source to describe the obsolescence of these SYSV-style UUCP device locks and the flock() recommendation, except for the Debian error itself.
I also found ioctl(fd, TIOCEXCL) , which is used by the screen utility to lock the terminal.
What is the current "best practice" for blocking serial ports and other devices on Linux? Where can we find the latest documentation describing this?
source share