From: Rusty Russell Date: Mon, 4 Sep 2017 00:51:45 +0000 (+0930) Subject: ccan/io: example failure X-Git-Url: https://git.ozlabs.org/?a=commitdiff_plain;h=b57bf03422363dfc2f5d2aa28a5fd2062192c70e;hp=759ac0f0564104d5028acd47c3e9fdb858c96d1d;p=ccan ccan/io: example failure 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 Signed-off-by: Rusty Russell --- diff --git a/ccan/io/_info b/ccan/io/_info index fe49df5c..6e95e4ab 100644 --- a/ccan/io/_info +++ b/ccan/io/_info @@ -61,9 +61,10 @@ * { * // 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); * @@ -114,6 +115,7 @@ * 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);