]> rtime.felk.cvut.cz Git - sojka/can-utils.git/commitdiff
slcanpty: detect that master PTY descriptor closed
authorOliver Hartkopp <socketcan@hartkopp.net>
Fri, 7 Jun 2013 18:02:57 +0000 (20:02 +0200)
committerOliver Hartkopp <socketcan@hartkopp.net>
Fri, 7 Jun 2013 18:02:57 +0000 (20:02 +0200)
Terminate slcanpty when the pty file descriptor is closed instead of performing
an endless loop in the select() statement.

Reported-by: Janusz Uzycki <j.uzycki@elproma.com.pl>
Signed-off-by: Janusz Uzycki <j.uzycki@elproma.com.pl>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
slcanpty.c

index f3628b9e9701c260d5d86eafa31d5750c31dbe26..028bf214bef76f1dee406c5e8aba7f42a34441d2 100644 (file)
@@ -75,8 +75,11 @@ int pty2can(int pty, int socket, struct can_filter *fi,
        int tmp, i;
 
        nbytes = read(pty, &buf, sizeof(buf)-1);
-       if (nbytes < 0) {
-               perror("read pty");
+       if (nbytes <= 0) {
+               /* nbytes == 0 : no error but pty decriptor has been closed */
+               if (nbytes < 0)
+                       perror("read pty");
+
                return 1;
        }