From de606d51ba4173641f1f2aaa57608e09693b3ebb Mon Sep 17 00:00:00 2001 From: Martin Lund Date: Fri, 22 Jul 2022 16:28:33 +0200 Subject: [PATCH] Fix sync output to serial port Using fsync() on filedescriptors for serial ports can not be relied on. Add use of tcdrain() to make sure data has been written by the serial port before proceeding. This fixes a problem with tio sometimes not writing piped input data to the serial port before exiting which results in the pending writes being cancelled / flushed. --- src/tty.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tty.c b/src/tty.c index f8ab5b6..bf3e68d 100644 --- a/src/tty.c +++ b/src/tty.c @@ -165,6 +165,7 @@ void tty_flush(int fd) } tty_buffer_count -= count; fsync(fd); + tcdrain(fd); } // Reset @@ -206,6 +207,7 @@ ssize_t tty_write(int fd, const void *buffer, size_t count) } fsync(fd); + tcdrain(fd); if (option.output_delay) {