0

In case of "bug" in port driver using locking is not acceptable.

vitaly.v.ch
  • 2,485
  • 4
  • 26
  • 36
  • Is this a programming question? Are you writing the serial driver? What do you mean by "foreign"? – unwind Dec 01 '09 at 11:30
  • Yes, it's programming question. No, I'm writing application for device connected via serial port with buggy driver. Foreign - started from any other binaries. – vitaly.v.ch Dec 01 '09 at 13:23
  • See: [What is the best practice for locking serial ports and other devices in Linux?](http://stackoverflow.com/questions/30316722/what-is-the-best-practice-for-locking-serial-ports-and-other-devices-in-linux) – Craig McQueen Jan 14 '16 at 00:07

3 Answers3

1

So you need to lock out other processes from opening a device file, but file locking is unacceptable...

Well, you could rename the device file to something non-standard, so everything that tries to open /dev/ttyS0 won't step on your toes.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
1

Assuming you are guarding against mistaken opens by "foreign" binaries: in your driver's open() method, match the name of the opening binary (current->comm). And allow opens only for your binary.

This can, of course be easily circumvented (by renaming a foreign binary.)

terminus
  • 403
  • 2
  • 3
0

Or you can change the properties of the corresponding dev file, only granting access to a custom group you are a member of. If you want the serial port to be accessible to any user, this might not work.

shodanex
  • 14,975
  • 11
  • 57
  • 91