From 02986f8623e02b5afba41f7f593710e74b3c8a7f Mon Sep 17 00:00:00 2001 From: Stefan Zegenhagen Date: Wed, 29 May 2013 16:50:43 +0200 Subject: Fix changing terminal parameters in to_erl One of our devices does not like 'to_erl' to be run over a serial port. When to_erl is started, we see "Attaching to /tm<0xFF>" being printed and the device then refuses to accept any input. Occasionally, we have seen a linux kernel error message "serial8250: too much work for irq16" simultaneously. After some debugging we found out that cause is a call to tcsetattr() by to_erl, immediately preceeded by some printf(). The UART in our device doesn't like hardware parameters to be changed while output is concurrently active. In fact, the GNU libc manual also mentions that it might be dangerous to change UART hardware parameters when a transmission is ongoing. The patch attached to this e-mail changes the behaviour of to_erl to use TCSADRAIN instead of TCSANOW when changing terminal parameters. This makes the serial driver wait for the output queues to be empty before applying the terminal parameter change. --- erts/etc/unix/to_erl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'erts') diff --git a/erts/etc/unix/to_erl.c b/erts/etc/unix/to_erl.c index 094006c5fd..5a8c9f77d4 100644 --- a/erts/etc/unix/to_erl.c +++ b/erts/etc/unix/to_erl.c @@ -339,7 +339,7 @@ int main(int argc, char **argv) tty_smode.c_cc[VTIME] =0;/* Note that VTIME is the same as VEOL! */ tty_smode.c_cc[VINTR] =3; - tcsetattr(0, TCSANOW, &tty_smode); + tcsetattr(0, TCSADRAIN, &tty_smode); #ifdef DEBUG show_terminal_settings(&tty_smode); @@ -484,7 +484,7 @@ int main(int argc, char **argv) * Reset terminal characterstics * XXX */ - tcsetattr(0, TCSANOW, &tty_rmode); + tcsetattr(0, TCSADRAIN, &tty_rmode); return 0; } -- cgit v1.2.3