summaryrefslogtreecommitdiff
path: root/qemu-sockets.c
diff options
context:
space:
mode:
authorAmos Kong <akong@redhat.com>2012-05-11 00:28:26 +0800
committerAnthony Liguori <aliguori@us.ibm.com>2012-05-10 12:37:57 -0500
commit029409e5a9568e9032634847587e24bba66b252b (patch)
treefa2755104ae2a554d90575ae3e744d16f3397ee6 /qemu-sockets.c
parenta6ba35b3be9d3d2874cd00930c954347e6be764c (diff)
sockets: use error class to pass listen error
Add a new argument in inet_listen()/inet_listen_opts() to pass back listen error. Change nbd, qemu-char, vnc to use new interface. Signed-off-by: Amos Kong <akong@redhat.com> Reviewed-by: Orit Wasserman <owasserm@redhat.com> Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'qemu-sockets.c')
-rw-r--r--qemu-sockets.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/qemu-sockets.c b/qemu-sockets.c
index ce3f06cac..46c7619c7 100644
--- a/qemu-sockets.c
+++ b/qemu-sockets.c
@@ -103,7 +103,7 @@ const char *inet_strfamily(int family)
return "unknown";
}
-int inet_listen_opts(QemuOpts *opts, int port_offset)
+int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp)
{
struct addrinfo ai,*res,*e;
const char *addr;
@@ -120,6 +120,7 @@ int inet_listen_opts(QemuOpts *opts, int port_offset)
if ((qemu_opt_get(opts, "host") == NULL) ||
(qemu_opt_get(opts, "port") == NULL)) {
fprintf(stderr, "%s: host and/or port not specified\n", __FUNCTION__);
+ error_set(errp, QERR_SOCKET_CREATE_FAILED);
return -1;
}
pstrcpy(port, sizeof(port), qemu_opt_get(opts, "port"));
@@ -138,6 +139,7 @@ int inet_listen_opts(QemuOpts *opts, int port_offset)
if (rc != 0) {
fprintf(stderr,"getaddrinfo(%s,%s): %s\n", addr, port,
gai_strerror(rc));
+ error_set(errp, QERR_SOCKET_CREATE_FAILED);
return -1;
}
@@ -150,6 +152,9 @@ int inet_listen_opts(QemuOpts *opts, int port_offset)
if (slisten < 0) {
fprintf(stderr,"%s: socket(%s): %s\n", __FUNCTION__,
inet_strfamily(e->ai_family), strerror(errno));
+ if (!e->ai_next) {
+ error_set(errp, QERR_SOCKET_CREATE_FAILED);
+ }
continue;
}
@@ -173,6 +178,9 @@ int inet_listen_opts(QemuOpts *opts, int port_offset)
fprintf(stderr,"%s: bind(%s,%s,%d): %s\n", __FUNCTION__,
inet_strfamily(e->ai_family), uaddr, inet_getport(e),
strerror(errno));
+ if (!e->ai_next) {
+ error_set(errp, QERR_SOCKET_BIND_FAILED);
+ }
}
}
closesocket(slisten);
@@ -183,6 +191,7 @@ int inet_listen_opts(QemuOpts *opts, int port_offset)
listen:
if (listen(slisten,1) != 0) {
+ error_set(errp, QERR_SOCKET_LISTEN_FAILED);
perror("listen");
closesocket(slisten);
freeaddrinfo(res);
@@ -446,7 +455,7 @@ static int inet_parse(QemuOpts *opts, const char *str)
}
int inet_listen(const char *str, char *ostr, int olen,
- int socktype, int port_offset)
+ int socktype, int port_offset, Error **errp)
{
QemuOpts *opts;
char *optstr;
@@ -454,7 +463,7 @@ int inet_listen(const char *str, char *ostr, int olen,
opts = qemu_opts_create(&dummy_opts, NULL, 0);
if (inet_parse(opts, str) == 0) {
- sock = inet_listen_opts(opts, port_offset);
+ sock = inet_listen_opts(opts, port_offset, errp);
if (sock != -1 && ostr) {
optstr = strchr(str, ',');
if (qemu_opt_get_bool(opts, "ipv6", 0)) {
@@ -469,6 +478,8 @@ int inet_listen(const char *str, char *ostr, int olen,
optstr ? optstr : "");
}
}
+ } else {
+ error_set(errp, QERR_SOCKET_CREATE_FAILED);
}
qemu_opts_del(opts);
return sock;