Pete Zaitcev <[EMAIL PROTECTED]> writes:
> On Thu, 13 Jul 2006 16:31:35 +0400, Sergei Organov <[EMAIL PROTECTED]> wrote:
>
>> > The application will get a signal that the device has "hung up" which
>> > usually causes it to automatically close the file handle, which is about
>> > the best that the kernel can provide.
>> 
>> Well, simple test shows that an application just sees an EOF condition,
>> i.e., read() returns 0 when device is disconnected.
>
> You probably run it with effective stty -isig by zeroing termios.

Doesn't seem to be the case. Here is the code:

#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>

int main()
{
  char buf[100];
  int fd = open("/dev/ttyUSB0", O_RDWR);
  int res = read(fd, buf, 100);
  printf("res=%d errno=%d [%s]\n", res, errno, strerror(errno));
  return 0;
}

And I run it immediately after I reboot the host, device is connected to
the bus, and associated with /dev/ttyUSB0. As device doesn't send
anything, the app sleeps in read() until I disconnect the device from
the bus, and then it prints:

res=0 errno=0 [Success]

Here is another run:

[EMAIL PROTECTED] tmp$ stty -F /dev/ttyUSB0 -a | grep isig
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
[EMAIL PROTECTED] tmp$ ./t
res=0 errno=0 [Success]
[EMAIL PROTECTED] tmp$

>
>> Not that it's a huge problem, but I do feel somewhat uneasy about it.
>
>> > Can you think of a better way to handle this?
>> 
>> No, not yet, -- I first wanted to see if there is some known
>> show-stopper here. If nobody sees any fundamental thing why it
>> shouldn't or just can't behave differently then now, I'll probably take
>> a closer look at it.
>
> Be my guest. We used to have a similar mechanism for storage devices
> in 2.4, but dropped it. It was complicated.

Seems you are saving me some time ;)

>
>> On the other hand, using udev rules to get stable names like
>> /dev/usb/iProduct:iSerial could be a better idea even though there are
>> other problems there, I think.
>
> The udev can do it. Unfortunately, I do not have an example of a rule
> right now, but I saw them flying by. Usually owners of multiply printers
> use those, so google for usblp+udev.

No wonder udev can do it, but it's more a solution that distros should
provide, and I'm afraid it's not that simple to provide a general one
due to possible collisions between different devices, at least I recall
I did see some discussions of the involved issues.

-- 
Sergei.


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to