Commit a159d620 authored by Anthony Foiani's avatar Anthony Foiani Committed by Greg Kroah-Hartman

staging: usbip: improve error reporting

Give useful error messages when we can't create server sockets.
Signed-Off-By: default avatarAnthony Foiani <anthony.foiani@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2568dd1b
...@@ -328,52 +328,68 @@ int process_request(int listenfd) ...@@ -328,52 +328,68 @@ int process_request(int listenfd)
return 0; return 0;
} }
static void log_addrinfo(struct addrinfo *ai) static void addrinfo_to_text(struct addrinfo *ai, char buf[],
const size_t buf_size)
{ {
char hbuf[NI_MAXHOST]; char hbuf[NI_MAXHOST];
char sbuf[NI_MAXSERV]; char sbuf[NI_MAXSERV];
int rc; int rc;
buf[0] = '\0';
rc = getnameinfo(ai->ai_addr, ai->ai_addrlen, hbuf, sizeof(hbuf), rc = getnameinfo(ai->ai_addr, ai->ai_addrlen, hbuf, sizeof(hbuf),
sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV); sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV);
if (rc) if (rc)
err("getnameinfo: %s", gai_strerror(rc)); err("getnameinfo: %s", gai_strerror(rc));
info("listening on %s:%s", hbuf, sbuf); snprintf(buf, buf_size, "%s:%s", hbuf, sbuf);
} }
static int listen_all_addrinfo(struct addrinfo *ai_head, int sockfdlist[]) static int listen_all_addrinfo(struct addrinfo *ai_head, int sockfdlist[])
{ {
struct addrinfo *ai; struct addrinfo *ai;
int ret, nsockfd = 0; int ret, nsockfd = 0;
const size_t ai_buf_size = NI_MAXHOST + NI_MAXSERV + 2;
char ai_buf[ai_buf_size];
for (ai = ai_head; ai && nsockfd < MAXSOCKFD; ai = ai->ai_next) { for (ai = ai_head; ai && nsockfd < MAXSOCKFD; ai = ai->ai_next) {
int sock = socket(ai->ai_family, ai->ai_socktype, int sock;
ai->ai_protocol); addrinfo_to_text(ai, ai_buf, ai_buf_size);
if (sock < 0) dbg("opening %s", ai_buf);
sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (sock < 0) {
err("socket: %s: %d (%s)",
ai_buf, errno, strerror(errno));
continue; continue;
}
usbip_net_set_reuseaddr(sock); usbip_net_set_reuseaddr(sock);
usbip_net_set_nodelay(sock); usbip_net_set_nodelay(sock);
if (sock >= FD_SETSIZE) { if (sock >= FD_SETSIZE) {
err("FD_SETSIZE: %s: sock=%d, max=%d",
ai_buf, sock, FD_SETSIZE);
close(sock); close(sock);
continue; continue;
} }
ret = bind(sock, ai->ai_addr, ai->ai_addrlen); ret = bind(sock, ai->ai_addr, ai->ai_addrlen);
if (ret < 0) { if (ret < 0) {
err("bind: %s: %d (%s)",
ai_buf, errno, strerror(errno));
close(sock); close(sock);
continue; continue;
} }
ret = listen(sock, SOMAXCONN); ret = listen(sock, SOMAXCONN);
if (ret < 0) { if (ret < 0) {
err("listen: %s: %d (%s)",
ai_buf, errno, strerror(errno));
close(sock); close(sock);
continue; continue;
} }
log_addrinfo(ai); info("listening on %s", ai_buf);
sockfdlist[nsockfd++] = sock; sockfdlist[nsockfd++] = sock;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment