From 60665ec633f57c8aa2ba3836e4451c08c508a401 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 3 Nov 2014 15:53:04 +0100 Subject: [PATCH] Disable exclusive access mode during close. When closing the slave side of a pseudo terminal, the exclusive access mode will persists on the master side. The result is that re-opening the slave side will fail with EBUSY, unless the process has root priviliges. To workaround this problem, we already introduced an option that enables better compatibility with pseudo terminals. See commmit fab606b00a44ea2114a4029ad09b70c66c3049f7 for details. In my development environment, I always have this option enabled. But occasionally I also need to test release builds. And then I usually end up with inaccessible pty's again, because the pty support is disabled by default for release build. This problem can easily be avoided by disabling the exclusive access mode, just before closing the file descriptor. --- src/serial_posix.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/serial_posix.c b/src/serial_posix.c index aebcdc5..2b0c3fa 100644 --- a/src/serial_posix.c +++ b/src/serial_posix.c @@ -205,6 +205,11 @@ serial_close (serial_t *device) return -1; } +#ifndef ENABLE_PTY + // Disable exclusive access mode. + ioctl (device->fd, TIOCNXCL, NULL); +#endif + // Close the device. if (close (device->fd) != 0) { SYSERROR (device->context, errno);