[libvirt] [PATCH 03/12] Introduce a generic object for using network sockets

Eric Blake eblake at redhat.com
Tue Mar 22 22:58:09 UTC 2011


On 03/18/2011 12:54 PM, 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.

> +int virNetSocketNewConnectCommand(virCommandPtr cmd,
> +                                  virNetSocketPtr *retsock)
> +{

> +
> +    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);
> +            }
> +        }
> +    }
> +
> +    virCommandFree(cmd);

This looks like a perfect candidate to use my proposed
virCommandAbort():
https://www.redhat.com/archives/libvir-list/2011-March/msg01045.html

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20110322/1c06ae8b/attachment-0001.sig>


More information about the libvir-list mailing list