[libvirt] [PATCH 3/3] Fix race in finding available vnc port

Eric Blake eblake at redhat.com
Fri May 21 16:17:23 UTC 2010


On 05/21/2010 10:00 AM, Jim Fehlig wrote:
> +        if (virBitmapGetBit(driver->reservedVNCPorts,
> +                            i - QEMU_VNC_PORT_MIN, &used) < 0)
> +            VIR_DEBUG("virBitmapGetBit failed on bit %d", i - QEMU_VNC_PORT_MIN);
> +
> +        if (used)
> +            continue;
> +
>          addr.sin_family = AF_INET;
>          addr.sin_port = htons(i);
>          addr.sin_addr.s_addr = htonl(INADDR_ANY);
> @@ -2654,6 +2669,8 @@ static int qemudNextFreeVNCPort(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
>          if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) == 0) {
>              /* Not in use, lets grab it */
>              close(fd);
> +            /* Add port to bitmap of reserved ports */
> +            virBitmapSetBit(driver->reservedVNCPorts, i - QEMU_VNC_PORT_MIN);

We might as well be consistent, and check for failure here, too (adding
ATTRIBUTE_RETURN_CHECK in bitmap.h would have caught this automatically).

ACK with that squashed in.

-- 
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/20100521/5fd68afe/attachment-0001.sig>


More information about the libvir-list mailing list