i noticed that while using minicom on a usb-serial device (PL2303), 
disconnecting it would make minicom spike using all the cpu.  looking into 
it, minicom does a simple select()/read() on the fd on the device, but those 
functions werent returning errors so it kept on looping.  a simple test 
program shows similar behavior: open a usb serial device, set the fd to 
nonblocking, and then in a loop just keep doing a read().  while the usb 
cable is plugged in, you get back the normal EAGAIN.  but when you unplug the 
device, read() just returns 0 rather than ENODEV or EIO.

i tried pokin around the usb-serial layer, but nothing obvious stands out.  
attached test case shows the issue: run it, watch the EAGAIN, and then unplug 
the device and watch no more output.
-mike

#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>

#define X(call) ({ \
                int _ret = call; \
                printf("%s = ", #call); \
                printf("%i\n", _ret); \
                _ret; \
        })

int hitit = 1;
void quitit(int sig)
{
        X(hitit = 0);
}

int main(int argc, char *argv[])
{
        const char *tty = (argc > 2 ? argv[2] : "/dev/ttyUSB0");
        int fd, ret;
        char buf[1024];

        setbuf(stdout, NULL);

        signal(SIGINT, quitit);

        fd = X(open(tty, O_RDONLY|O_NONBLOCK));

        while (hitit) {
                ret = X(read(fd, buf, sizeof(buf)));
                if (ret == -1)
                        printf("\terrno = %i (%s)\n", errno, strerror(errno));
                sleep(1);
        }

        X(close(fd));

        return 0;
}

Attachment: signature.asc
Description: This is a digitally signed message part.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Linux-usb-users@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-users

Reply via email to