From 704d5f22d1d2502ddcd4e231b733eeb642112653 Mon Sep 17 00:00:00 2001 From: Oliver Hartkopp Date: Fri, 7 Jun 2013 20:02:57 +0200 Subject: [PATCH] slcanpty: detect that master PTY descriptor closed Terminate slcanpty when the pty file descriptor is closed instead of performing an endless loop in the select() statement. Reported-by: Janusz Uzycki Signed-off-by: Janusz Uzycki Signed-off-by: Oliver Hartkopp --- slcanpty.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/slcanpty.c b/slcanpty.c index f3628b9..028bf21 100644 --- a/slcanpty.c +++ b/slcanpty.c @@ -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; } -- 2.7.4