Enable exclusive access mode.
With exclusive access mode, no further open() operations on the terminal are permitted, except for a process with root priviliges. Non-root processes will fail with EBUSY. This change will prevent other processes from accidentally messing up the communication. It also makes the behaviour similar to Windows, where serial ports are always opened with exclusive access.
This commit is contained in:
parent
cd31ff9dff
commit
6cb4bc6a06
@ -103,6 +103,14 @@ serial_open (serial_t **out, dc_context_t *context, const char* name)
|
||||
return -1; // Error during open call.
|
||||
}
|
||||
|
||||
// Enable exclusive access mode.
|
||||
if (ioctl (device->fd, TIOCEXCL, NULL) != 0) {
|
||||
SYSERROR (context, errno);
|
||||
close (device->fd);
|
||||
free (device);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Retrieve the current terminal attributes, to
|
||||
// be able to restore them when closing the device.
|
||||
// It is also used to check if the obtained
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user