[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH 03/10] Introduce a generic object for using network sockets



On 06/22/2011 09:33 AM, Daniel P. Berrange wrote:
> Introduces a simple wrapper around the raw POSIX sockets APIs
> and name resolution APIs. Allows for easy creation of client
> and server sockets with correct usage of name resolution APIs
> for protocol agnostic socket setup.
> 
> It can listen for UNIX and TCP stream sockets.
> 
> It can connect to UNIX, TCP streams directly, or indirectly
> to UNIX sockets via an SSH tunnel or external command
> 
> * src/Makefile.am: Add to libvirt-net-rpc.la
> * src/rpc/virnetsocket.c, src/rpc/virnetsocket.h: Generic
>   sockets APIs
> * tests/Makefile.am: Add socket test
> * tests/virnetsockettest.c: New test case
> * tests/testutils.c: Avoid overriding LIBVIRT_DEBUG settings
> * tests/ssh.c: Dumb helper program for SSH tunnelling tests

Again, problems with 'make check', first linking failures, then test
failures.

> +#ifdef IPV6_V6ONLY
> +        if (runp->ai_family == PF_INET6) {
> +            int on = 1;
> +            /*
> +             * Normally on Linux an INET6 socket will bind to the INET4
> +             * address too. If getaddrinfo returns results with INET4
> +             * first though, this will result in INET6 binding failing.
> +             * We can trivially cope with multiple server sockets, so
> +             * we force it to only listen on IPv6
> +             */
> +            if (setsockopt(fd, IPPROTO_IPV6,IPV6_V6ONLY,

Formatting nit.

> +    if (virCommandRunAsync(cmd, &pid) < 0)
> +        goto error;
> +
> +    /* Parent continues here. */
> +    VIR_FORCE_CLOSE(sv[1]);
> +    VIR_FORCE_CLOSE(errfd[1]);
> +
> +    if (!(*retsock = virNetSocketNew(NULL, NULL, true, sv[0], errfd[0], pid)))
> +        goto error;
> +
> +    virCommandFree(cmd);
> +
> +    return 0;
> +
> +error:
> +    VIR_FORCE_CLOSE(sv[0]);
> +    VIR_FORCE_CLOSE(sv[1]);
> +    VIR_FORCE_CLOSE(errfd[0]);
> +    VIR_FORCE_CLOSE(errfd[1]);
> +
> +    if (pid > 0) {
> +        kill(pid, SIGTERM);
> +        if (virCommandWait(cmd, NULL) < 0) {
> +            kill(pid, SIGKILL);
> +            if (virCommandWait(cmd, NULL) < 0) {
> +                VIR_WARN("Unable to wait for command %d", pid);
> +            }
> +        }
> +    }

This can be simplified.

Here's what I applied to get compilation to complete, but I'm still
seeing test failures (is this test too sensitive to firewalls, or
running as non-root)?

diff --git i/src/rpc/virnetsocket.c w/src/rpc/virnetsocket.c
index eedced0..5e9066f 100644
--- i/src/rpc/virnetsocket.c
+++ w/src/rpc/virnetsocket.c
@@ -206,7 +206,7 @@ int virNetSocketNewListenTCP(const char *nodename,
              * We can trivially cope with multiple server sockets, so
              * we force it to only listen on IPv6
              */
-            if (setsockopt(fd, IPPROTO_IPV6,IPV6_V6ONLY,
+            if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY,
                            (void*)&on, sizeof on) < 0) {
                 virReportSystemError(errno, "%s",
                                      _("Unable to force bind to IPv6
only"));
@@ -542,16 +542,7 @@ error:
     VIR_FORCE_CLOSE(errfd[0]);
     VIR_FORCE_CLOSE(errfd[1]);

-    if (pid > 0) {
-        kill(pid, SIGTERM);
-        if (virCommandWait(cmd, NULL) < 0) {
-            kill(pid, SIGKILL);
-            if (virCommandWait(cmd, NULL) < 0) {
-                VIR_WARN("Unable to wait for command %d", pid);
-            }
-        }
-    }
-
+    virCommandAbort(cmd);
     virCommandFree(cmd);

     return -1;
diff --git i/tests/Makefile.am w/tests/Makefile.am
index f3e2c77..5ed9d0a 100644
--- i/tests/Makefile.am
+++ w/tests/Makefile.am
@@ -414,7 +414,7 @@ virnetmessagetest_LDADD = ../src/libvirt-net-rpc.la
$(LDADDS)
 virnetsockettest_SOURCES = \
 	virnetsockettest.c testutils.h testutils.c
 virnetsockettest_CFLAGS = -Dabs_builddir="\"$(abs_builddir)\""
-virnetsockettest_LDADD = $(LDADDS)
+virnetsockettest_LDADD = ../src/libvirt-net-rpc.la $(LDADDS)


 seclabeltest_SOURCES = \


Any ideas on how best to go about debugging these test failures?


TEST: virnetsockettest
 1) Socket TCP/IPv4 Accept
... FAILED
 2) Socket TCP/IPv6 Accept
... FAILED
 3) Socket TCP/IPv4+IPv6 Accept
... FAILED
 4) Socket TCP/IPv4+IPv6 Accept
... FAILED
 5) Socket UNIX Accept                                                ... OK
 6) Socket UNIX Addrs                                                 ... OK
 7) Socket External Command /dev/zero                                 ... OK
 8) Socket External Command /dev/does-not-exist
... FAILED
 9) SSH test 1                                                        ...
Expect [somehost nc -U /tmp/socket
]
Actual []

... FAILED
10) SSH test 2                                                        ...
Expect [-p 9000 -l fred -T -o BatchMode=yes -e none somehost netcat -U
/tmp/socket
]
Actual []

... FAILED
11) SSH test 3
... FAILED
12) SSH test 4                                                        ...
Expect [crashyhost nc -U /tmp/socket
]
Actual []

... FAILED
FAIL: virnetsockettest


-- 
Eric Blake   eblake redhat com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]