S
S
scream3r2011-12-22 20:09:13
C++ / C#
scream3r, 2011-12-22 20:09:13

Strange behavior of TIOCEXCL on Solaris?

First, let me explain what I need to do. I want to set the serial port I'm working on to exclusive mode, i.e. so that no one else can access it while I work with it. Of course, root can get access, and I will say right away that I am not working as root.
So, to implement this, I use the following code:

int fd;<br/>
fd = open(portName, O_RDWR | O_NOCTTY | O_NDELAY);<br/>
if(fd != -1){<br/>
 ioctl(fd, TIOCEXCL);<br/>
 int flags = fcntl(fd, F_GETFL, 0);<br/>
 flags &= ~O_NDELAY;<br/>
 fcntl(fd, F_SETFL, flags);<br/>
}<br/>

So, then I launch the first application and open a port in it, everything is fine so far, after that I launch the second application and try to open a port in it, which I get EBUSY and this is also normal. But at this very moment, my first application stops working, I can neither write nor read, nor close the port. In response, I get ENXIO (No such device or address). In other words, after any other application has tried to open a port already in use, I can no longer use the fd(file descriptor) received by the first application, it feels like the port just closes at that point.
For the second day I've been struggling with Solaris, in Linux and Mac OS X this code works without problems, but here such a misfortune, I ask for your help, gentlemen.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question