When switching to libnbd in commit ab7760fcfd, I mistakenly assumed
that after a POLLIN event fires on the pipe-to-self, then read() will
return either 1 or -1. But this is not true; read() can also return 0
(if the pipe hits EOF), in which case POSIX says errno has an
unspecified value, and we should not be deciding whether to log an
error based on a random value. I did not manage to fix the bug even
when later refactoring the pipe-to-self to be non-blocking, although
it appears to be latent as long as the pipe is non-blocking and the
write end is not closed.
Fixes: e0d32468
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
plugins/nbd/nbd.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/plugins/nbd/nbd.c b/plugins/nbd/nbd.c
index d020beec..e5b8f338 100644
--- a/plugins/nbd/nbd.c
+++ b/plugins/nbd/nbd.c
@@ -332,9 +332,11 @@ nbdplug_reader (void *handle)
/* Check if we were kicked because a command was started */
if (fds[1].revents & POLLIN) {
- while (read (h->fds[0], &c, 1) == 1)
+ int r;
+
+ while ((r = read (h->fds[0], &c, 1)) == 1)
/* Drain any backlog */;
- if (errno != EAGAIN) {
+ if (r == -1 && errno != EAGAIN) {
nbdkit_error ("failed to read pipe: %m");
break;
}
--
2.26.0.rc2