sockets: Drop sockets_debug debug code
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 <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
ef0c4a0d89
commit
136faa362d
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user