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

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

 



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@xxxxxxxxxx    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

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

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]