[PATCH] commandtest: Comply with FreeBSD poll()

Michal Privoznik posted 1 patch 1 year, 5 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/b8ae4ec0f1af69e2779a28c79af435b7bf6deada.1669910287.git.mprivozn@redhat.com
tests/commandtest.c | 3 +++
1 file changed, 3 insertions(+)
[PATCH] commandtest: Comply with FreeBSD poll()
Posted by Michal Privoznik 1 year, 5 months ago
In one of recent commits I've introduced a new test case to
commandtest. In the test case I'm using poll() to wait for data
on a pipe (the write end is passed to commandhelper). However, on
FreeBSD the POLLIN semantic is a bit different:

  POLLIN        Data other than high priority data may be read
                without blocking.

Well, the pipe is non-blocking, so even if there's no data to be
read the flag is set (and subsequent read() returns 0). On the
other hand, POLLHUP is set too, BUT, if the commandhelper manages
to write everything into the pipe and die right after we'd get
both POLLIN and POLLHUP after the very first time poll() returns.
That's very unfortunate, but okay - we can just check whether
read() returned zero and break from the reading loop.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 tests/commandtest.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tests/commandtest.c b/tests/commandtest.c
index 62275ba96d..688cf59160 100644
--- a/tests/commandtest.c
+++ b/tests/commandtest.c
@@ -1205,6 +1205,9 @@ test29(const void *unused G_GNUC_UNUSED)
                 goto cleanup;
             }
 
+            if (rc == 0)
+                break;
+
             outactual = g_renew(char, outactual, outactuallen + rc + 1);
             memcpy(outactual + outactuallen, buf, rc);
             outactuallen += rc;
-- 
2.37.4
Re: [PATCH] commandtest: Comply with FreeBSD poll()
Posted by Martin Kletzander 1 year, 5 months ago
On Thu, Dec 01, 2022 at 04:58:07PM +0100, Michal Privoznik wrote:
>In one of recent commits I've introduced a new test case to
>commandtest. In the test case I'm using poll() to wait for data
>on a pipe (the write end is passed to commandhelper). However, on
>FreeBSD the POLLIN semantic is a bit different:
>
>  POLLIN        Data other than high priority data may be read
>                without blocking.
>
>Well, the pipe is non-blocking, so even if there's no data to be
>read the flag is set (and subsequent read() returns 0). On the

if the other end is closed and there is no data

Reviewed-by: Martin Kletzander <mkletzan@redhat.com>

>other hand, POLLHUP is set too, BUT, if the commandhelper manages
>to write everything into the pipe and die right after we'd get
>both POLLIN and POLLHUP after the very first time poll() returns.
>That's very unfortunate, but okay - we can just check whether
>read() returned zero and break from the reading loop.
>
>Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>---
> tests/commandtest.c | 3 +++
> 1 file changed, 3 insertions(+)
>
>diff --git a/tests/commandtest.c b/tests/commandtest.c
>index 62275ba96d..688cf59160 100644
>--- a/tests/commandtest.c
>+++ b/tests/commandtest.c
>@@ -1205,6 +1205,9 @@ test29(const void *unused G_GNUC_UNUSED)
>                 goto cleanup;
>             }
>
>+            if (rc == 0)
>+                break;
>+
>             outactual = g_renew(char, outactual, outactuallen + rc + 1);
>             memcpy(outactual + outactuallen, buf, rc);
>             outactuallen += rc;
>-- 
>2.37.4
>