How to make /dev/ttyACM0 (and friends) exclusive?

valdis.kletnieks at vt.edu valdis.kletnieks at vt.edu
Mon Mar 4 17:01:52 EST 2019


On Mon, 04 Mar 2019 16:38:44 +0100, Yann Droneaud said:

> O_EXCL is intended to be used to prevent opening an existing file. Said
> differently, it's used to ensure a new file is created, useful to
> prevent race condition, where multiple processes compete to create a
> file. For example think of temporary file created with random name.

Which means that if you're trying to regulate exclusive use of a character
device or similar, you use O_EXCL|O_CREAT to create a lock file, and make sure
that all the programs competing for the character device use the same pathname
to create the lock file - which has been a tried-and-true way of handling
exclusive locking for serial ports for 4 decades now.

The fact that 'strings /usr/sbin/ModemManager | grep /' proves pretty clearly
that ModemManager is trusting DBus to keep track of things rather than using
lock files on the modems is almost certainly part of the reason it's a steaming
pile of dingo's kidneys rather than a helpful piece of software.



More information about the Kernelnewbies mailing list