From aaf3dc6ac3e3a38b0dd3508d72594214ede27c5c Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 30 Oct 2020 13:45:28 -0400 Subject: [PATCH] serialqueue: Fix registration of serial fd in debug mode When in debug output mode, make sure to register the fd correctly. Otherwise, the poll() call will use the 0 fd which could cause random results. Signed-off-by: Kevin O'Connor --- klippy/chelper/serialqueue.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/klippy/chelper/serialqueue.c b/klippy/chelper/serialqueue.c index 779156ce..ec6dd014 100644 --- a/klippy/chelper/serialqueue.c +++ b/klippy/chelper/serialqueue.c @@ -88,10 +88,11 @@ pollreactor_free(struct pollreactor *pr) // Add a callback for when a file descriptor (fd) becomes readable static void -pollreactor_add_fd(struct pollreactor *pr, int pos, int fd, void *callback) +pollreactor_add_fd(struct pollreactor *pr, int pos, int fd, void *callback + , int write_only) { pr->fds[pos].fd = fd; - pr->fds[pos].events = POLLIN|POLLHUP; + pr->fds[pos].events = POLLHUP | (write_only ? 0 : POLLIN); pr->fds[pos].revents = 0; pr->fd_callbacks[pos] = callback; } @@ -838,9 +839,9 @@ serialqueue_alloc(int serial_fd, int write_only) if (ret) goto fail; pollreactor_setup(&sq->pr, SQPF_NUM, SQPT_NUM, sq); - if (!write_only) - pollreactor_add_fd(&sq->pr, SQPF_SERIAL, serial_fd, input_event); - pollreactor_add_fd(&sq->pr, SQPF_PIPE, sq->pipe_fds[0], kick_event); + pollreactor_add_fd(&sq->pr, SQPF_SERIAL, serial_fd, input_event + , write_only); + pollreactor_add_fd(&sq->pr, SQPF_PIPE, sq->pipe_fds[0], kick_event, 0); pollreactor_add_timer(&sq->pr, SQPT_RETRANSMIT, retransmit_event); pollreactor_add_timer(&sq->pr, SQPT_COMMAND, command_event); set_non_blocking(serial_fd);