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.
This commit is contained in:
Martin Lund 2022-07-22 16:28:33 +02:00
parent 0cdd69940f
commit de606d51ba

View file

@ -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)
{