From 6cb4bc6a063a60d5865fb202529b87ae3fbe11fe Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 15 Feb 2011 21:40:24 +0100 Subject: [PATCH] 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. --- src/serial_posix.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/serial_posix.c b/src/serial_posix.c index 3f20186..d9ad4e7 100644 --- a/src/serial_posix.c +++ b/src/serial_posix.c @@ -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