如果端口驱动程序出现“错误”,则不能使用锁定。
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.
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.)
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.