[PATCH] tests: avoid close of bad file handle in commandtest

Daniel P. Berrangé posted 1 patch 3 years, 7 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20200921173854.1987219-1-berrange@redhat.com
tests/commandtest.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] tests: avoid close of bad file handle in commandtest
Posted by Daniel P. Berrangé 3 years, 7 months ago
Closed file handles need to be initialized to -1, not 0. This caused a
inappropriate double close of stdin, which is not desirable, although
it had no ill effects.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 tests/commandtest.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/commandtest.c b/tests/commandtest.c
index 42225a8ef2..cbbcda4e5f 100644
--- a/tests/commandtest.c
+++ b/tests/commandtest.c
@@ -1091,8 +1091,8 @@ static int test27(const void *unused G_GNUC_UNUSED)
         printf("Could not set send buffers\n");
         goto cleanup;
     }
-    pipe1[1] = 0;
-    pipe2[1] = 0;
+    pipe1[1] = -1;
+    pipe2[1] = -1;
     buffer1 = NULL;
     buffer2 = NULL;
 
-- 
2.26.2

Re: [PATCH] tests: avoid close of bad file handle in commandtest
Posted by Eric Blake 3 years, 7 months ago
On 9/21/20 12:38 PM, Daniel P. Berrangé wrote:
> Closed file handles need to be initialized to -1, not 0. This caused a
> inappropriate double close of stdin, which is not desirable, although
> it had no ill effects.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   tests/commandtest.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Eric Blake <eblake@redhat.com>

> 
> diff --git a/tests/commandtest.c b/tests/commandtest.c
> index 42225a8ef2..cbbcda4e5f 100644
> --- a/tests/commandtest.c
> +++ b/tests/commandtest.c
> @@ -1091,8 +1091,8 @@ static int test27(const void *unused G_GNUC_UNUSED)
>           printf("Could not set send buffers\n");
>           goto cleanup;
>       }
> -    pipe1[1] = 0;
> -    pipe2[1] = 0;
> +    pipe1[1] = -1;
> +    pipe2[1] = -1;
>       buffer1 = NULL;
>       buffer2 = NULL;
>   
> 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org