ttynvt: Avoid potential "net read error" in _read_net() when closing

ttynvt_release() may be called when the poll thread is blocked in a
read(FD_NET) (maybe also read(FD_MASTER) - not sure).
So ttynvt_release() sets rel_pending before closing the fd, but too late
as the read() will return an error when the fd is closed, and before the
thread is cancelled.

Now we cancel/join the thread before closing the file descriptor(s).
This commit is contained in:
Kim Woelders
2023-02-10 11:27:15 +01:00
parent 94bd59e1e0
commit 3ab1dd5cc7
+4 -3
View File
@@ -141,15 +141,16 @@ static void ttynvt_release(fuse_req_t req, struct fuse_file_info *info)
DBG("%s\n", __func__); DBG("%s\n", __func__);
tty->rel_pending = 1; tty->rel_pending = 1;
_fd_close(tty->fds[FD_NET].fd);
_fd_close(tty->fds[FD_MASTER].fd);
_fd_close(tty->fds[FD_SLAVE].fd);
pthread_cancel(tty->ptid_poll); pthread_cancel(tty->ptid_poll);
pthread_join(tty->ptid_poll, NULL); pthread_join(tty->ptid_poll, NULL);
pthread_mutex_destroy(&tty->tty_lock); pthread_mutex_destroy(&tty->tty_lock);
pthread_mutex_destroy(&tty->poll_lock); pthread_mutex_destroy(&tty->poll_lock);
_fd_close(tty->fds[FD_NET].fd);
_fd_close(tty->fds[FD_MASTER].fd);
_fd_close(tty->fds[FD_SLAVE].fd);
if (tty->ph) if (tty->ph)
fuse_pollhandle_destroy(tty->ph); fuse_pollhandle_destroy(tty->ph);