[libvirt] [PATCH v2 06/10] tests: qemuxml2argvmock: Allow 'safe' file descriptors in mocked virCommandPassFD

Peter Krempa posted 10 patches 6 years, 2 months ago
[libvirt] [PATCH v2 06/10] tests: qemuxml2argvmock: Allow 'safe' file descriptors in mocked virCommandPassFD
Posted by Peter Krempa 6 years, 2 months ago
Allow FDs which are marked as safe for FD passing.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 tests/qemuxml2argvmock.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/tests/qemuxml2argvmock.c b/tests/qemuxml2argvmock.c
index 4df92cf396..581f720227 100644
--- a/tests/qemuxml2argvmock.c
+++ b/tests/qemuxml2argvmock.c
@@ -184,12 +184,26 @@ virNetDevRunEthernetScript(const char *ifname ATTRIBUTE_UNUSED,
     return 0;
 }

+static void (*real_virCommandPassFD)(virCommandPtr cmd, int fd, unsigned int flags);
+
+static const int testCommandPassSafeFDs[] = { -1 };
+
 void
-virCommandPassFD(virCommandPtr cmd ATTRIBUTE_UNUSED,
-                 int fd ATTRIBUTE_UNUSED,
-                 unsigned int flags ATTRIBUTE_UNUSED)
+virCommandPassFD(virCommandPtr cmd,
+                 int fd,
+                 unsigned int flags)
 {
-    /* nada */
+    size_t i;
+
+    for (i = 0; i < ARRAY_CARDINALITY(testCommandPassSafeFDs); i++) {
+        if (testCommandPassSafeFDs[i] == fd) {
+            if (!real_virCommandPassFD)
+                VIR_MOCK_REAL_INIT(virCommandPassFD);
+
+            real_virCommandPassFD(cmd, fd, flags);
+            return;
+        }
+    }
 }

 int
-- 
2.16.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 06/10] tests: qemuxml2argvmock: Allow 'safe' file descriptors in mocked virCommandPassFD
Posted by John Ferlan 6 years, 1 month ago

On 08/15/2018 05:18 AM, Peter Krempa wrote:
> Allow FDs which are marked as safe for FD passing.
> 
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>  tests/qemuxml2argvmock.c | 22 ++++++++++++++++++----
>  1 file changed, 18 insertions(+), 4 deletions(-)
> 

Reviewed-by: John Ferlan <jferlan@redhat.com>

John

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list