From 0f95e0779ecbf12c9360b5fcf5e66d843b761888 Mon Sep 17 00:00:00 2001 From: Kim Woelders Date: Thu, 25 Oct 2018 07:42:08 +0200 Subject: [PATCH] Avoid close error on FD_MASTER after DCD drop --- ttynvt.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ttynvt.c b/ttynvt.c index 7337eb6..2e2fe59 100644 --- a/ttynvt.c +++ b/ttynvt.c @@ -132,6 +132,12 @@ void _log_buf(int prio, const char *txt, const void *ptr_, unsigned int len) #define DBG2_BUF(txt, ptr, len) \ if (ttynvt_param.debug > 1) _log_buf(LOG_DEBUG, txt, ptr, len) +static void _fd_close(int fd) +{ + if (fd >= 0) + close(fd); +} + static volatile char _is_interrupted = 0; static void sig_handler(int sig) @@ -184,9 +190,9 @@ 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); + _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_join(tty->ptid_poll, NULL); @@ -556,8 +562,7 @@ static void ttynvt_open(fuse_req_t req, struct fuse_file_info *info) ttynvt_param.host, ttynvt_param.port); for (n = 0; n < 3; n++) - if (tty->fds[n].fd >= 0) - close(tty->fds[n].fd); + _fd_close(tty->fds[n].fd); free(tty->tn); free(tty);