From 540ddd5659c156754145419d70c094516864517c Mon Sep 17 00:00:00 2001 From: Kim Woelders Date: Mon, 15 Oct 2018 11:47:43 +0200 Subject: [PATCH] Fix polling of pty slave --- ttynvt.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/ttynvt.c b/ttynvt.c index 1e51608..e4763c0 100644 --- a/ttynvt.c +++ b/ttynvt.c @@ -32,8 +32,8 @@ #define TMP_BUF_SIZE 1024 #define FD_NET 0 -#define FD_SLAVE 1 -#define FD_MASTER 2 +#define FD_MASTER 1 +#define FD_SLAVE 2 #define _PRF_N_(no) __attribute__((__format__(__printf__, (no), (no) + 1))) #define _PRF2_ _PRF_N_(2) @@ -60,6 +60,7 @@ typedef struct { struct fuse_pollhandle *ph; + volatile char n_fds; struct pollfd fds[3]; char net_buf[NET_BUF_SIZE]; @@ -178,6 +179,7 @@ static void ttynvt_release(fuse_req_t req, struct fuse_file_info *info) _log(LOG_INFO, "connection closed\n"); + tty->n_fds = 0; close(tty->fds[FD_NET].fd); close(tty->fds[FD_MASTER].fd); close(tty->fds[FD_SLAVE].fd); @@ -226,10 +228,13 @@ static void *_read_net(void *arg) pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); DBG2("%s: net_cnt=%d\n", __func__, tty->net_cnt); - while (1) + while (tty->n_fds > 0) { - res = poll(tty->fds, 3, -1); - DBG2("%s: res=%d events-N/M/S=%#x/%#x/%#x\n", __func__, res, + tty->fds[FD_NET].revents = tty->fds[FD_MASTER].revents = + tty->fds[FD_SLAVE].revents = 0; + res = poll(tty->fds, tty->n_fds, -1); + DBG2("%s: res=%d N=%d events-N/M/S=%#x/%#x/%#x\n", __func__, + res, tty->n_fds, tty->fds[FD_NET].revents, tty->fds[FD_MASTER].revents, tty->fds[FD_SLAVE].revents); if (res < 0) @@ -238,6 +243,8 @@ static void *_read_net(void *arg) continue; break; } + if (tty->n_fds == 0) + break; if (tty->fds[FD_NET].revents & POLLIN) { @@ -286,6 +293,7 @@ static void *_read_net(void *arg) if (tty->fds[FD_SLAVE].revents & POLLIN) { tty->pollin = 1; + tty->n_fds = 2; /* Disable polling of Slave */ _notify(tty); } } @@ -496,6 +504,8 @@ static void ttynvt_open(fuse_req_t req, struct fuse_file_info *info) goto open_err; } + tty->n_fds = 3; /* Initially poll Net, Master, and Slave */ + info->fh = (uintptr_t) tty; info->nonseekable = 1; info->direct_io = 1; @@ -552,6 +562,7 @@ ttynvt_read(fuse_req_t req, size_t size, off_t off, res = _is_interrupted ? -2 : read(tty->fds[FD_SLAVE].fd, tty->tmp_buf, size); _is_interrupted = 0; + tty->n_fds = 3; /* Enable polling of Slave */ fuse_req_interrupt_func(req, NULL, NULL); if (res < 0) {