diff options
author | Eric Blake <eblake@redhat.com> | 2016-03-03 09:16:48 -0700 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2016-03-05 10:41:52 +0100 |
commit | 0399293e5b9e5443b82103fa8e2c97deadef9825 (patch) | |
tree | 51743f16ff479c5e1ff013f7d4a9176b4a9609b8 /qemu-char.c | |
parent | f194a1ae530e232b994d23aa8651696dd6664b5d (diff) | |
download | qemu-0399293e5b9e5443b82103fa8e2c97deadef9825.zip qemu-0399293e5b9e5443b82103fa8e2c97deadef9825.tar.gz qemu-0399293e5b9e5443b82103fa8e2c97deadef9825.tar.bz2 |
util: Shorten references into SocketAddress
An upcoming patch will alter how simple unions, like SocketAddress,
are laid out, which will impact all lines of the form 'addr->u.XXX'
(expanding it to the longer 'addr->u.XXX.data'). For better
legibility in that patch, and less need for line wrapping, it's better
to use a temporary variable to reduce the effect of a layout change to
just the variable initializations, rather than every reference within
a SocketAddress. Also, take advantage of some C99 initialization where
it makes sense (simplifying g_new0() to g_new()).
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1457021813-10704-7-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'qemu-char.c')
-rw-r--r-- | qemu-char.c | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/qemu-char.c b/qemu-char.c index 5ea1d34..af31102 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -3659,20 +3659,23 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend, addr = g_new0(SocketAddress, 1); if (path) { + UnixSocketAddress *q_unix; addr->type = SOCKET_ADDRESS_KIND_UNIX; - addr->u.q_unix = g_new0(UnixSocketAddress, 1); - addr->u.q_unix->path = g_strdup(path); + q_unix = addr->u.q_unix = g_new0(UnixSocketAddress, 1); + q_unix->path = g_strdup(path); } else { addr->type = SOCKET_ADDRESS_KIND_INET; - addr->u.inet = g_new0(InetSocketAddress, 1); - addr->u.inet->host = g_strdup(host); - addr->u.inet->port = g_strdup(port); - addr->u.inet->has_to = qemu_opt_get(opts, "to"); - addr->u.inet->to = qemu_opt_get_number(opts, "to", 0); - addr->u.inet->has_ipv4 = qemu_opt_get(opts, "ipv4"); - addr->u.inet->ipv4 = qemu_opt_get_bool(opts, "ipv4", 0); - addr->u.inet->has_ipv6 = qemu_opt_get(opts, "ipv6"); - addr->u.inet->ipv6 = qemu_opt_get_bool(opts, "ipv6", 0); + addr->u.inet = g_new(InetSocketAddress, 1); + *addr->u.inet = (InetSocketAddress) { + .host = g_strdup(host), + .port = g_strdup(port), + .has_to = qemu_opt_get(opts, "to"), + .to = qemu_opt_get_number(opts, "to", 0), + .has_ipv4 = qemu_opt_get(opts, "ipv4"), + .ipv4 = qemu_opt_get_bool(opts, "ipv4", 0), + .has_ipv6 = qemu_opt_get(opts, "ipv6"), + .ipv6 = qemu_opt_get_bool(opts, "ipv6", 0), + }; } sock->addr = addr; } @@ -3711,22 +3714,26 @@ static void qemu_chr_parse_udp(QemuOpts *opts, ChardevBackend *backend, addr = g_new0(SocketAddress, 1); addr->type = SOCKET_ADDRESS_KIND_INET; - addr->u.inet = g_new0(InetSocketAddress, 1); - addr->u.inet->host = g_strdup(host); - addr->u.inet->port = g_strdup(port); - addr->u.inet->has_ipv4 = qemu_opt_get(opts, "ipv4"); - addr->u.inet->ipv4 = qemu_opt_get_bool(opts, "ipv4", 0); - addr->u.inet->has_ipv6 = qemu_opt_get(opts, "ipv6"); - addr->u.inet->ipv6 = qemu_opt_get_bool(opts, "ipv6", 0); + addr->u.inet = g_new(InetSocketAddress, 1); + *addr->u.inet = (InetSocketAddress) { + .host = g_strdup(host), + .port = g_strdup(port), + .has_ipv4 = qemu_opt_get(opts, "ipv4"), + .ipv4 = qemu_opt_get_bool(opts, "ipv4", 0), + .has_ipv6 = qemu_opt_get(opts, "ipv6"), + .ipv6 = qemu_opt_get_bool(opts, "ipv6", 0), + }; udp->remote = addr; if (has_local) { udp->has_local = true; addr = g_new0(SocketAddress, 1); addr->type = SOCKET_ADDRESS_KIND_INET; - addr->u.inet = g_new0(InetSocketAddress, 1); - addr->u.inet->host = g_strdup(localaddr); - addr->u.inet->port = g_strdup(localport); + addr->u.inet = g_new(InetSocketAddress, 1); + *addr->u.inet = (InetSocketAddress) { + .host = g_strdup(localaddr), + .port = g_strdup(localport), + }; udp->local = addr; } } |