aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--safetitle.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/safetitle.c b/safetitle.c
index b1e49b4..03a1456 100644
--- a/safetitle.c
+++ b/safetitle.c
@@ -29,7 +29,6 @@ blacklisted(int fd)
int i, r;
struct timeval timeout;
- /* setup */
if((buf = malloc(200*sizeof(char)))==NULL)
err(1, "malloc");
@@ -47,12 +46,11 @@ blacklisted(int fd)
buf[i] = '\0';
screen = strcmp(buf, SCREEN_DA)==0;
+ /* ignore strange trailing nul before reading response */
FD_ZERO(&fds);
FD_SET(fd, &fds);
timeout.tv_sec = 0;
timeout.tv_usec = 0;
-
- /* ignore strange trailing nul */
while(select(fd+1, &fds, NULL, NULL, &timeout)>0)
read(fd, &c, 1);
@@ -82,14 +80,15 @@ check:
FD_ZERO(&fds);
FD_SET(fd, &fds);
timeout.tv_sec = 0;
- timeout.tv_usec = 1;
+ timeout.tv_usec = 1; /* it takes a millisecond sometimes */
if(screen && select(fd+1, &fds, NULL, NULL, &timeout)>0){
- i = 0;
+ /* ignore strange trailing nul before reading response */
if(read(fd, &c, 1)==-1){
warn("read");
return 1;
}
- if(c==0) goto check; /* ignore strange trailing nul */
+ i = 0;
+ if(c==0) goto check;
else goto loop;
}