Skip to content

Commit

Permalink
Allow building for OSes that don't support TIOCNXCL and TIOCEXCL
Browse files Browse the repository at this point in the history
Issue: DOTNET-106
  • Loading branch information
Jason Curl committed May 25, 2017
1 parent 1d490d5 commit 86eeb55
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dll/serialunix/CMakeModules/serial.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ check_symbol_exists(TIOCCBRK "sys/ioctl.h" HAVE_TERMIOS_TIOCCBRK)
check_symbol_exists(TIOCINQ "sys/ioctl.h" HAVE_TERMIOS_TIOCINQ)
check_symbol_exists(FIONREAD "sys/ioctl.h" HAVE_TERMIOS_FIONREAD)
check_symbol_exists(TIOCOUTQ "sys/ioctl.h" HAVE_TERMIOS_TIOCOUTQ)
check_symbol_exists(TIOCNXCL "sys/ioctl.h" HAVE_TERMIOS_TIOCNXCL)
check_symbol_exists(TIOCEXCL "sys/ioctl.h" HAVE_TERMIOS_TIOCEXCL)

check_symbol_exists(TIOCGICOUNT "sys/ioctl.h" HAVE_TERMIOS_TIOCGICOUNT)
check_symbol_exists(TIOCMIWAIT "sys/ioctl.h" HAVE_TERMIOS_TIOCMIWAIT)
Expand Down
7 changes: 7 additions & 0 deletions dll/serialunix/libnserial/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,10 @@
#define HAVE_TERMIOS_TIOCINQ
#define TIOCINQ FIONREAD
#endif

#cmakedefine HAVE_TERMIOS_TIOCNXCL
#cmakedefine HAVE_TERMIOS_TIOCEXCL
#if defined(HAVE_TERMIOS_TIOCEXCL) && defined(HAVE_TERMIOS_TIOCNXCL)
#define HAVE_TERMIOS_EXCLUSIVE
#endif

4 changes: 4 additions & 0 deletions dll/serialunix/libnserial/openserial.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ static int closeserial(struct serialhandle *handle)
int result;

nslog(handle, NSLOG_DEBUG, "close: closing serial port");
#if defined HAVE_TERMIOS_EXCLUSIVE
if (ioctl(handle->fd, TIOCNXCL)) {
nslog(handle, NSLOG_NOTICE, "close: error setting TIOCNXCL: errno=%d", errno);
}
#endif

result = close(handle->fd);
nslog(handle, NSLOG_DEBUG, "close: closed");
Expand Down Expand Up @@ -73,9 +75,11 @@ NSERIAL_EXPORT int WINAPI serial_open(struct serialhandle *handle)
return -1;
}

#if defined HAVE_TERMIOS_EXCLUSIVE
if (ioctl(handle->fd, TIOCEXCL)) {
nslog(handle, NSLOG_NOTICE, "open: error setting TIOCEXCL: errno=%d", errno);
}
#endif

int pipefd[2];
if (pipe(pipefd) == -1) {
Expand Down

0 comments on commit 86eeb55

Please sign in to comment.