Busybox echo buffers lines to stdout
authorBarret Rhoden <brho@cs.berkeley.edu>
Mon, 2 Mar 2015 16:45:23 +0000 (11:45 -0500)
committerBarret Rhoden <brho@cs.berkeley.edu>
Mon, 2 Mar 2015 16:45:23 +0000 (11:45 -0500)
In some cases, echo would split a line up into several write calls,
which would lead to incomplete commands sent to the kernel.

Since it's surprisingly non-deterministic (though consistent per boot),
I haven't confirmed this is the fix.  If you have weird failures with
echo, try and get a syscall trace and let me know.

You'll need to rebuild busybox:
$ cd tools/apps/busybox/
$ make

And remake the kernel.

tools/apps/busybox/akaros-patches/1.17.3/0006-echo-linebuffered.patch [new file with mode: 0644]

diff --git a/tools/apps/busybox/akaros-patches/1.17.3/0006-echo-linebuffered.patch b/tools/apps/busybox/akaros-patches/1.17.3/0006-echo-linebuffered.patch
new file mode 100644 (file)
index 0000000..99c279a
--- /dev/null
@@ -0,0 +1,14 @@
+diff -ur busybox-1.17.3-akaros-orig/coreutils/echo.c busybox-1.17.3-akaros/coreutils/echo.c
+--- busybox-1.17.3-akaros-orig/coreutils/echo.c        2015-03-02 11:35:58.782323515 -0500
++++ busybox-1.17.3-akaros/coreutils/echo.c     2015-03-02 11:37:31.122641120 -0500
+@@ -96,6 +96,10 @@
+       }
+  just_echo:
+ #endif
++      /* brho: need to buffer a full line at a time.  not sure if glibc should
++       * have this set for stdout or not. */
++      if (setvbuf(stdout, 0, _IOLBF, 0))
++              perror("Failed to setvbuf");
+       while (1) {
+               /* arg is already == *argv and isn't NULL */
+               int c;