Fix write in non-interactive piping mode

So that piping does not break when write buffer is full because e.g.
device has flow control enabled and can't keep up.
This commit is contained in:
Martin Lund 2025-05-11 07:11:07 +02:00
parent f887756a71
commit d1328e694e

View file

@ -2641,6 +2641,19 @@ int tty_connect(void)
/* If stdin is a pipe forward all input to tty device */
if (interactive_mode == false)
{
// Set blocking mode for serial device (blocking write)
int flags = fcntl(device_fd, F_GETFL, 0);
if (flags == -1)
{
tio_error_printf("Could not read descriptor flags (%s)", strerror(errno));
exit(EXIT_FAILURE);
}
if (fcntl(device_fd, F_SETFL, flags & ~O_NONBLOCK) == -1)
{
tio_error_printf("Could not set descriptor flags (%s)", strerror(errno));
exit(EXIT_FAILURE);
}
while (true)
{
int ret = read(pipefd[0], &input_char, 1);