diff options
author | Markus Armbruster <armbru@redhat.com> | 2017-04-26 09:36:36 +0200 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2017-05-09 09:14:40 +0200 |
commit | 4db5c619a2f03c2ee25105b4f6359075c825aecc (patch) | |
tree | 18df24c8616416fa175b97c3cabeeb17c4c1ddb4 /util | |
parent | 5229564b832e979f480011bae372ff849dbf320a (diff) |
sockets: Prepare vsock_parse() for flattened SocketAddress
I'm going to flatten SocketAddress: rename SocketAddress to
SocketAddressLegacy, SocketAddressFlat to SocketAddress, eliminate
SocketAddressLegacy except in external interfaces.
vsock_parse() returns a newly allocated VsockSocketAddress. Lift the
allocation from vsock_parse() into its caller socket_parse() to
prepare for flattening SocketAddress.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1493192202-3184-2-git-send-email-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'util')
-rw-r--r-- | util/qemu-sockets.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 8188d9a8d7..1abe095493 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -793,26 +793,25 @@ static int vsock_listen_saddr(VsockSocketAddress *vaddr, return slisten; } -static VsockSocketAddress *vsock_parse(const char *str, Error **errp) +static int vsock_parse(VsockSocketAddress *addr, const char *str, + Error **errp) { - VsockSocketAddress *addr = NULL; char cid[33]; char port[33]; int n; if (sscanf(str, "%32[^:]:%32[^,]%n", cid, port, &n) != 2) { error_setg(errp, "error parsing address '%s'", str); - return NULL; + return -1; } if (str[n] != '\0') { error_setg(errp, "trailing characters in address '%s'", str); - return NULL; + return -1; } - addr = g_new0(VsockSocketAddress, 1); addr->cid = g_strdup(cid); addr->port = g_strdup(port); - return addr; + return 0; } #else static void vsock_unsupported(Error **errp) @@ -835,10 +834,11 @@ static int vsock_listen_saddr(VsockSocketAddress *vaddr, return -1; } -static VsockSocketAddress *vsock_parse(const char *str, Error **errp) +static int vsock_parse(VsockSocketAddress *addr, const char *str, + Error **errp) { vsock_unsupported(errp); - return NULL; + return -1; } #endif /* CONFIG_AF_VSOCK */ @@ -1060,8 +1060,8 @@ SocketAddress *socket_parse(const char *str, Error **errp) } } else if (strstart(str, "vsock:", NULL)) { addr->type = SOCKET_ADDRESS_KIND_VSOCK; - addr->u.vsock.data = vsock_parse(str + strlen("vsock:"), errp); - if (addr->u.vsock.data == NULL) { + addr->u.vsock.data = g_new(VsockSocketAddress, 1); + if (vsock_parse(addr->u.vsock.data, str + strlen("vsock:"), errp)) { goto fail; } } else { |