Skip to content

Commit

Permalink
sockets: remove obsolete code that updated listen address
Browse files Browse the repository at this point in the history
When listening on unix/tcp sockets there was optional code that would update
the original SocketAddress struct with the info about the actual address that
was listened on. Since the conversion of everything to QIOChannelSocket, no
remaining caller made use of this feature. It has been replaced with the ability
to query the listen address after the fact using the function
qio_channel_socket_get_local_address. This is a better model when the input
address can result in listening on multiple distinct sockets.

Signed-off-by: Daniel P. Berrange <[email protected]>
Reviewed-by: Peter Xu <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
berrange authored and bonzini committed Dec 21, 2017
1 parent 1ef7c96 commit 6247351
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 28 deletions.
2 changes: 1 addition & 1 deletion include/qemu/sockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int inet_connect_saddr(InetSocketAddress *saddr, Error **errp);

NetworkAddressFamily inet_netfamily(int family);

int unix_listen(const char *path, char *ostr, int olen, Error **errp);
int unix_listen(const char *path, Error **errp);
int unix_connect(const char *path, Error **errp);

SocketAddress *socket_parse(const char *str, Error **errp);
Expand Down
2 changes: 1 addition & 1 deletion qga/channel-posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path,
if (fd < 0) {
Error *local_err = NULL;

fd = unix_listen(path, NULL, strlen(path), &local_err);
fd = unix_listen(path, &local_err);
if (local_err != NULL) {
g_critical("%s", error_get_pretty(local_err));
error_free(local_err);
Expand Down
31 changes: 5 additions & 26 deletions util/qemu-sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ static int try_bind(int socket, InetSocketAddress *saddr, struct addrinfo *e)

static int inet_listen_saddr(InetSocketAddress *saddr,
int port_offset,
bool update_addr,
Error **errp)
{
struct addrinfo ai,*res,*e;
Expand Down Expand Up @@ -326,15 +325,6 @@ static int inet_listen_saddr(InetSocketAddress *saddr,
return -1;

listen_ok:
if (update_addr) {
g_free(saddr->host);
saddr->host = g_strdup(uaddr);
g_free(saddr->port);
saddr->port = g_strdup_printf("%d",
inet_getport(e) - port_offset);
saddr->has_ipv6 = saddr->ipv6 = e->ai_family == PF_INET6;
saddr->has_ipv4 = saddr->ipv4 = e->ai_family != PF_INET6;
}
freeaddrinfo(res);
return slisten;
}
Expand Down Expand Up @@ -790,7 +780,6 @@ static int vsock_parse(VsockSocketAddress *addr, const char *str,
#ifndef _WIN32

static int unix_listen_saddr(UnixSocketAddress *saddr,
bool update_addr,
Error **errp)
{
struct sockaddr_un un;
Expand Down Expand Up @@ -855,12 +844,7 @@ static int unix_listen_saddr(UnixSocketAddress *saddr,
goto err;
}

if (update_addr && pathbuf) {
g_free(saddr->path);
saddr->path = pathbuf;
} else {
g_free(pathbuf);
}
g_free(pathbuf);
return sock;

err:
Expand Down Expand Up @@ -920,7 +904,6 @@ static int unix_connect_saddr(UnixSocketAddress *saddr, Error **errp)
#else

static int unix_listen_saddr(UnixSocketAddress *saddr,
bool update_addr,
Error **errp)
{
error_setg(errp, "unix sockets are not available on windows");
Expand All @@ -937,7 +920,7 @@ static int unix_connect_saddr(UnixSocketAddress *saddr, Error **errp)
#endif

/* compatibility wrapper */
int unix_listen(const char *str, char *ostr, int olen, Error **errp)
int unix_listen(const char *str, Error **errp)
{
char *path, *optstr;
int sock, len;
Expand All @@ -957,11 +940,7 @@ int unix_listen(const char *str, char *ostr, int olen, Error **errp)
saddr->path = g_strdup(str);
}

sock = unix_listen_saddr(saddr, true, errp);

if (sock != -1 && ostr) {
snprintf(ostr, olen, "%s%s", saddr->path, optstr ? optstr : "");
}
sock = unix_listen_saddr(saddr, errp);

qapi_free_UnixSocketAddress(saddr);
return sock;
Expand Down Expand Up @@ -1052,11 +1031,11 @@ int socket_listen(SocketAddress *addr, Error **errp)

switch (addr->type) {
case SOCKET_ADDRESS_TYPE_INET:
fd = inet_listen_saddr(&addr->u.inet, 0, false, errp);
fd = inet_listen_saddr(&addr->u.inet, 0, errp);
break;

case SOCKET_ADDRESS_TYPE_UNIX:
fd = unix_listen_saddr(&addr->u.q_unix, false, errp);
fd = unix_listen_saddr(&addr->u.q_unix, errp);
break;

case SOCKET_ADDRESS_TYPE_FD:
Expand Down

0 comments on commit 6247351

Please sign in to comment.