Hi Alon,
The socket should be closed if connect() fails.
Please see below.
Looks good otherwise.
Thanks,
Uri.
Signed-off-by: Alon Levy <alevy@xxxxxxxxxx>
---
src/vdagent-virtio-port.c | 53 +++++++++++++++++++++++++++++++++++++++++------
1 file changed, 47 insertions(+), 6 deletions(-)
diff --git a/src/vdagent-virtio-port.c b/src/vdagent-virtio-port.c
index 05bd344..bdd22d9 100644
--- a/src/vdagent-virtio-port.c
+++ b/src/vdagent-virtio-port.c
@@ -85,16 +91,33 @@ struct vdagent_virtio_port *vdagent_virtio_port_create(const char *portname,
vport->fd = open(portname, O_RDWR);
if (vport->fd == -1) {
- syslog(LOG_ERR, "open %s: %m", portname);
- free(vport);
- return NULL;
- }
+ syslog(LOG_INFO, "open %s: %m; trying as socket", portname);
+ vport->fd = socket(PF_UNIX, SOCK_STREAM, 0);
+ if (vport->fd == -1) {
+ goto error;
+ }
+ address.sun_family = AF_UNIX;
+ snprintf(address.sun_path, sizeof(address.sun_path), "%s", portname);
+ c = connect(vport->fd, (struct sockaddr *)&address, sizeof(address));
+ if (c == 0) {
+ vport->is_uds = 1;
+ } else {
+ goto error;
+ }
+ } else {
+ vport->is_uds = 0;
+ }
vport->opening = 1;
vport->read_callback = read_callback;
vport->disconnect_callback = disconnect_callback;
return vport;
+
+error:
+ syslog(LOG_ERR, "open %s: %m", portname);
if (vport->fd != -1) {
close(vport->fd);
}
+ free(vport);
+ return NULL;
}
void vdagent_virtio_port_destroy(struct vdagent_virtio_port **vportp)
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel