ccan/io: example failure
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 4 Sep 2017 00:51:45 +0000 (10:21 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 11 Oct 2017 22:11:41 +0000 (08:41 +1030)
So many bugs in one example program!

There was an unrelated but which strace revealed (trying to write -7
bytes), but I think your issue was more prosaic: failing to zero the
from buffer.

Reported-by: Ian Zimmerman <itz@very.loosely.org>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/io/_info

index fe49df5c8d0418094b3630af88bc49e5f9493a5b..6e95e4ab9e18b7b494b4624ea53f64dd0bd95c15 100644 (file)
  * {
  *     // Remove what we just wrote.
  *     b->start += b->wlen;
+ *     b->wlen = 0;
  *     assert(b->start <= sizeof(b->buf));
  *
- *     // If we wrote something, wake writer.
+ *     // If we wrote something, wake reader.
  *     if (b->wlen != 0)
  *             io_wake(b);
  *
  *     io_new_conn(NULL, tochild[1], write_out, &to);
  *
  *     // Read from child, write to stdout.
+ *     memset(&from, 0, sizeof(from));
  *     reader = io_new_conn(NULL, fromchild[0], read_in, &from);
  *     io_set_finish(reader, finish, &from);
  *     io_new_conn(NULL, STDOUT_FILENO, write_out, &from);