openbmc / obmc-console

OpenBMC host console infrastructure
Apache License 2.0
17 stars 25 forks source link

Console mirrored to UART drops characters frequently #10

Open rlippert opened 7 years ago

rlippert commented 7 years ago

When executing something like 'ps aux' over the UART console, much of the output at the end get dropped or mangled and obmc-console-server reports write error: resource temporarily unavailable.

I tracked it down to write_buf_to_fd not properly handling EAGAIN/EWOULDBLOCK return code. This patch works around the issue:

diff --git a/util.c b/util.c
index d6e037a..cb190c8 100644
--- a/util.c
+++ b/util.c
@@ -15,6 +15,7 @@
  */

 #include <err.h>
+#include <errno.h>
 #include <unistd.h>

 #include "console-server.h"
@@ -27,6 +28,10 @@ int write_buf_to_fd(int fd, const uint8_t *buf, size_t len)
        for (pos = 0; pos < len; pos += rc) {
                rc = write(fd, buf + pos, len - pos);
                if (rc <= 0) {
+                       if (errno == EAGAIN) {
+                               rc = 0;
+                               continue;
+                       }
                        warn("Write error");
                        return -1;
                }

Unfortunately patching it this way makes all other consoles (e.g. obmc-console-client over ssh) output as slowly as the UART console because obmc-console-server is a single threaded app and this makes it block waiting for serial port to flush output.

I'm hoping this issue will be fixed by @jk-ozlabs commit series https://gerrit.openbmc-project.xyz/#/c/2322/1 but I haven't tested it yet.