diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2012-10-02 09:25:14 +0200 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2012-10-23 13:54:57 +0200 |
commit | 4f085c822947068c785be8c1f27d1ad4e3215149 (patch) | |
tree | dd63cba7b0c065cca2a3d9bc06d8174499699154 /qemu-sockets.c | |
parent | 11663b553b0815b266b6a9060ab9702cf7a5334c (diff) | |
download | qemu-4f085c822947068c785be8c1f27d1ad4e3215149.zip qemu-4f085c822947068c785be8c1f27d1ad4e3215149.tar.gz qemu-4f085c822947068c785be8c1f27d1ad4e3215149.tar.bz2 |
qemu-sockets: add error propagation to inet_dgram_opts
Before:
$ qemu-system-x86_64 -monitor udp:localhost:631@localhost:631
inet_dgram_opts: bind(ipv4,127.0.0.1,631): OK
inet_dgram_opts failed
chardev: opening backend "udp" failed
After:
$ x86_64-softmmu/qemu-system-x86_64 -monitor udp:localhost:631@localhost:631
qemu-system-x86_64: -monitor udp:localhost:631@localhost:631: Failed to bind socket: Address already in use
chardev: opening backend "udp" failed
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'qemu-sockets.c')
-rw-r--r-- | qemu-sockets.c | 34 |
1 files changed, 8 insertions, 26 deletions
diff --git a/qemu-sockets.c b/qemu-sockets.c index 88d58fe..078f7c1 100644 --- a/qemu-sockets.c +++ b/qemu-sockets.c @@ -396,8 +396,6 @@ int inet_dgram_opts(QemuOpts *opts, Error **errp) struct addrinfo ai, *peer = NULL, *local = NULL; const char *addr; const char *port; - char uaddr[INET6_ADDRSTRLEN+1]; - char uport[33]; int sock = -1, rc; /* lookup peer addr */ @@ -412,7 +410,7 @@ int inet_dgram_opts(QemuOpts *opts, Error **errp) addr = "localhost"; } if (port == NULL || strlen(port) == 0) { - fprintf(stderr, "inet_dgram: port not specified\n"); + error_setg(errp, "remote port not specified"); return -1; } @@ -422,8 +420,8 @@ int inet_dgram_opts(QemuOpts *opts, Error **errp) ai.ai_family = PF_INET6; if (0 != (rc = getaddrinfo(addr, port, &ai, &peer))) { - fprintf(stderr,"getaddrinfo(%s,%s): %s\n", addr, port, - gai_strerror(rc)); + error_setg(errp, "address resolution failed for %s:%s: %s", addr, port, + gai_strerror(rc)); return -1; } @@ -442,44 +440,28 @@ int inet_dgram_opts(QemuOpts *opts, Error **errp) port = "0"; if (0 != (rc = getaddrinfo(addr, port, &ai, &local))) { - fprintf(stderr,"getaddrinfo(%s,%s): %s\n", addr, port, - gai_strerror(rc)); + error_setg(errp, "address resolution failed for %s:%s: %s", addr, port, + gai_strerror(rc)); goto err; } /* create socket */ sock = qemu_socket(peer->ai_family, peer->ai_socktype, peer->ai_protocol); if (sock < 0) { - fprintf(stderr,"%s: socket(%s): %s\n", __FUNCTION__, - inet_strfamily(peer->ai_family), strerror(errno)); + error_set_errno(errp, errno, QERR_SOCKET_CREATE_FAILED); goto err; } setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,(void*)&on,sizeof(on)); /* bind socket */ - if (getnameinfo((struct sockaddr*)local->ai_addr,local->ai_addrlen, - uaddr,INET6_ADDRSTRLEN,uport,32, - NI_NUMERICHOST | NI_NUMERICSERV) != 0) { - fprintf(stderr, "%s: getnameinfo: oops\n", __FUNCTION__); - goto err; - } if (bind(sock, local->ai_addr, local->ai_addrlen) < 0) { - fprintf(stderr,"%s: bind(%s,%s,%d): OK\n", __FUNCTION__, - inet_strfamily(local->ai_family), uaddr, inet_getport(local)); + error_set_errno(errp, errno, QERR_SOCKET_BIND_FAILED); goto err; } /* connect to peer */ - if (getnameinfo((struct sockaddr*)peer->ai_addr, peer->ai_addrlen, - uaddr, INET6_ADDRSTRLEN, uport, 32, - NI_NUMERICHOST | NI_NUMERICSERV) != 0) { - fprintf(stderr, "%s: getnameinfo: oops\n", __FUNCTION__); - goto err; - } if (connect(sock,peer->ai_addr,peer->ai_addrlen) < 0) { - fprintf(stderr, "%s: connect(%s,%s,%s,%s): %s\n", __FUNCTION__, - inet_strfamily(peer->ai_family), - peer->ai_canonname, uaddr, uport, strerror(errno)); + error_set_errno(errp, errno, QERR_SOCKET_CONNECT_FAILED); goto err; } |