[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 07/19] sockets: Drop sockets_debug debug code
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PATCH 07/19] sockets: Drop sockets_debug debug code |
Date: |
Tue, 7 Feb 2012 15:09:14 +0100 |
I'm trying to improve this code's error reporting, and the debug code
is getting in my way: it clutters the code, it clobbers errno in
inconvenient places, and it uses the same fprintf() both for error
reporting and debug output in a few places.
Get rid of it. Once decent error reporting is in place, adding back
whatever debug code we need shouldn't be hard.
Signed-off-by: Markus Armbruster <address@hidden>
---
qemu-sockets.c | 43 ++-----------------------------------------
1 files changed, 2 insertions(+), 41 deletions(-)
diff --git a/qemu-sockets.c b/qemu-sockets.c
index 61b2247..e6e6c72 100644
--- a/qemu-sockets.c
+++ b/qemu-sockets.c
@@ -26,7 +26,6 @@
# define AI_ADDRCONFIG 0
#endif
-static int sockets_debug = 0;
static const int on=1, off=0;
/* used temporarely until all users are converted to QemuOpts */
@@ -101,21 +100,6 @@ const char *inet_strfamily(int family)
return "unknown";
}
-static void inet_print_addrinfo(const char *tag, struct addrinfo *res)
-{
- struct addrinfo *e;
- char uaddr[INET6_ADDRSTRLEN+1];
- char uport[33];
-
- for (e = res; e != NULL; e = e->ai_next) {
- getnameinfo((struct sockaddr*)e->ai_addr,e->ai_addrlen,
- uaddr,INET6_ADDRSTRLEN,uport,32,
- NI_NUMERICHOST | NI_NUMERICSERV);
- fprintf(stderr,"%s: getaddrinfo: family %s, host %s, port %s\n",
- tag, inet_strfamily(e->ai_family), uaddr, uport);
- }
-}
-
int inet_listen_opts(QemuOpts *opts, int port_offset)
{
struct addrinfo ai,*res,*e;
@@ -153,8 +137,6 @@ int inet_listen_opts(QemuOpts *opts, int port_offset)
gai_strerror(rc));
return -1;
}
- if (sockets_debug)
- inet_print_addrinfo(__FUNCTION__, res);
/* create socket + bind */
for (e = res; e != NULL; e = e->ai_next) {
@@ -179,13 +161,10 @@ int inet_listen_opts(QemuOpts *opts, int port_offset)
for (;;) {
if (bind(slisten, e->ai_addr, e->ai_addrlen) == 0) {
- if (sockets_debug)
- fprintf(stderr,"%s: bind(%s,%s,%d): OK\n", __FUNCTION__,
- inet_strfamily(e->ai_family), uaddr, inet_getport(e));
goto listen;
}
try_next = to && (inet_getport(e) <= to + port_offset);
- if (!try_next || sockets_debug)
+ if (!try_next)
fprintf(stderr,"%s: bind(%s,%s,%d): %s\n", __FUNCTION__,
inet_strfamily(e->ai_family), uaddr, inet_getport(e),
strerror(errno));
@@ -249,8 +228,6 @@ int inet_connect_opts(QemuOpts *opts)
gai_strerror(rc));
return -1;
}
- if (sockets_debug)
- inet_print_addrinfo(__FUNCTION__, res);
for (e = res; e != NULL; e = e->ai_next) {
if (getnameinfo((struct sockaddr*)e->ai_addr,e->ai_addrlen,
@@ -269,17 +246,13 @@ int inet_connect_opts(QemuOpts *opts)
/* connect to peer */
if (connect(sock,e->ai_addr,e->ai_addrlen) < 0) {
- if (sockets_debug || NULL == e->ai_next)
+ if (NULL == e->ai_next)
fprintf(stderr, "%s: connect(%s,%s,%s,%s): %s\n", __FUNCTION__,
inet_strfamily(e->ai_family),
e->ai_canonname, uaddr, uport, strerror(errno));
closesocket(sock);
continue;
}
- if (sockets_debug)
- fprintf(stderr, "%s: connect(%s,%s,%s,%s): OK\n", __FUNCTION__,
- inet_strfamily(e->ai_family),
- e->ai_canonname, uaddr, uport);
freeaddrinfo(res);
return sock;
}
@@ -322,10 +295,6 @@ int inet_dgram_opts(QemuOpts *opts)
gai_strerror(rc));
return -1;
}
- if (sockets_debug) {
- fprintf(stderr, "%s: peer (%s:%s)\n", __FUNCTION__, addr, port);
- inet_print_addrinfo(__FUNCTION__, peer);
- }
/* lookup local addr */
memset(&ai,0, sizeof(ai));
@@ -346,10 +315,6 @@ int inet_dgram_opts(QemuOpts *opts)
gai_strerror(rc));
return -1;
}
- if (sockets_debug) {
- fprintf(stderr, "%s: local (%s:%s)\n", __FUNCTION__, addr, port);
- inet_print_addrinfo(__FUNCTION__, local);
- }
/* create socket */
sock = qemu_socket(peer->ai_family, peer->ai_socktype, peer->ai_protocol);
@@ -541,8 +506,6 @@ int unix_listen_opts(QemuOpts *opts)
goto err;
}
- if (sockets_debug)
- fprintf(stderr, "bind(unix:%s): OK\n", un.sun_path);
return sock;
err:
@@ -576,8 +539,6 @@ int unix_connect_opts(QemuOpts *opts)
return -1;
}
- if (sockets_debug)
- fprintf(stderr, "connect(unix:%s): OK\n", path);
return sock;
}
--
1.7.6.5
- Re: [Qemu-devel] [PATCH 09/19] sockets: Chardev open error reporting, sockets part, (continued)
[Qemu-devel] [PATCH 16/19] spice-qemu-char: Chardev open error reporting, spicevmc part, Markus Armbruster, 2012/02/07
[Qemu-devel] [PATCH 12/19] qemu-char: Chardev open error reporting, tty part, Markus Armbruster, 2012/02/07
[Qemu-devel] [PATCH 02/19] qemu-char: Use qemu_open() to avoid leaking fds to children, Markus Armbruster, 2012/02/07
[Qemu-devel] [PATCH 13/19] qemu-char: Chardev open error reporting, parport part, Markus Armbruster, 2012/02/07
[Qemu-devel] [PATCH 08/19] sockets: Clean up inet_listen_opts()'s convoluted bind() loop, Markus Armbruster, 2012/02/07
[Qemu-devel] [PATCH 04/19] qemu-char: qemu_chr_open_fd() can't fail, don't check, Markus Armbruster, 2012/02/07
[Qemu-devel] [PATCH 07/19] sockets: Drop sockets_debug debug code,
Markus Armbruster <=
[Qemu-devel] [PATCH 06/19] gdbstub: Error locations for -gdb, Markus Armbruster, 2012/02/07
[Qemu-devel] [PATCH 14/19] console: Eliminate text_consoles[], Markus Armbruster, 2012/02/07
[Qemu-devel] [PATCH 10/19] qemu-char: Chardev open error reporting, !_WIN32 part, Markus Armbruster, 2012/02/07
- Re: [Qemu-devel] [PATCH 10/19] qemu-char: Chardev open error reporting, !_WIN32 part, Kevin Wolf, 2012/02/07
- Re: [Qemu-devel] [PATCH 10/19] qemu-char: Chardev open error reporting, !_WIN32 part, Markus Armbruster, 2012/02/09
- Re: [Qemu-devel] [PATCH 10/19] qemu-char: Chardev open error reporting, !_WIN32 part, Kevin Wolf, 2012/02/09
- Re: [Qemu-devel] [PATCH 10/19] qemu-char: Chardev open error reporting, !_WIN32 part, Markus Armbruster, 2012/02/09
- Re: [Qemu-devel] [PATCH 10/19] qemu-char: Chardev open error reporting, !_WIN32 part, Luiz Capitulino, 2012/02/09