From 2ed8bae4f603e1086c2a1056c108209893b541ba Mon Sep 17 00:00:00 2001 From: Paul LeoNerd Evans Date: Fri, 20 Jan 2012 20:01:11 +0000 Subject: Don't try to write() the start/stop string if the fd is a pipe, because this will never work --- driver-ti.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/driver-ti.c b/driver-ti.c index af46769..d827bdf 100644 --- a/driver-ti.c +++ b/driver-ti.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include /* To be efficient at lookups, we store the byte sequence => keyinfo mapping * in a trie. This avoids a slow linear search through a flat list of @@ -292,6 +294,7 @@ abort_free_ti: static int start_driver(TermKey *tk, void *info) { TermKeyTI *ti = info; + struct stat statbuf; char *start_string = ti->start_string; size_t len; @@ -302,6 +305,13 @@ static int start_driver(TermKey *tk, void *info) * We may need to enable that mode */ + /* There's no point trying to write() to a pipe */ + if(fstat(tk->fd, &statbuf) == -1) + return 0; + + if(S_ISFIFO(statbuf.st_mode)) + return 1; + // Can't call putp or tputs because they suck and don't give us fd control len = strlen(start_string); while(len) { @@ -317,12 +327,20 @@ static int start_driver(TermKey *tk, void *info) static int stop_driver(TermKey *tk, void *info) { TermKeyTI *ti = info; + struct stat statbuf; char *stop_string = ti->stop_string; size_t len; if(tk->fd == -1 || !stop_string) return 1; + /* There's no point trying to write() to a pipe */ + if(fstat(tk->fd, &statbuf) == -1) + return 0; + + if(S_ISFIFO(statbuf.st_mode)) + return 1; + /* The terminfo database will contain keys in application cursor key mode. * We may need to enable that mode */ -- cgit v1.2.3-70-g09d2