From patchwork Wed Nov 21 22:06:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001449 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cf85cCqz9s29 for ; Thu, 22 Nov 2018 09:28:00 +1100 (AEDT) Received: from localhost ([::1]:42662 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPayT-0005Ll-PA for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:27:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51738) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPahO-0006od-VP for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:10:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPahK-0005Rd-Ih for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:10:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46742) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPahI-0004xN-Hj for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:10:13 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1497C89ADD; Wed, 21 Nov 2018 22:09:52 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 734329F7A; Wed, 21 Nov 2018 22:09:47 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:41 +0400 Message-Id: <20181121220647.18844-25-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 21 Nov 2018 22:09:52 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 24/30] slirp: call into g_debug() for DEBUG macros X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Make slirp use GLib logging, instead of fprintf(), so that applications can filter log, process it etc. With recent versions of glib, G_MESSAGES_DEBUG must be set to "all" or "Slirp" to see slirp debug messages. Reformat DEBUG_MISC & DEBUG_ERROR calls to not need \n ending. Signed-off-by: Marc-André Lureau --- slirp/debug.h | 17 ++++------------- slirp/cksum.c | 4 ++-- slirp/dhcpv6.c | 6 +++--- slirp/ip_icmp.c | 10 +++++----- slirp/slirp.c | 10 ++++------ slirp/socket.c | 24 ++++++++++++------------ slirp/tcp_input.c | 7 +++---- slirp/tcp_output.c | 2 +- slirp/tcp_subr.c | 2 +- slirp/udp.c | 5 ++--- slirp/udp6.c | 5 ++--- 11 files changed, 39 insertions(+), 53 deletions(-) diff --git a/slirp/debug.h b/slirp/debug.h index 50f30898fb..25a5d59439 100644 --- a/slirp/debug.h +++ b/slirp/debug.h @@ -12,38 +12,29 @@ #define DBG_MISC 0x2 #define DBG_ERROR 0x4 -#define dfd stderr - extern int slirp_debug; #define DEBUG_CALL(fmt, ...) do { \ if (slirp_debug & DBG_CALL) { \ - fprintf(dfd, fmt, ##__VA_ARGS__); \ - fprintf(dfd, "...\n"); \ - fflush(dfd); \ + g_debug(fmt "...", ##__VA_ARGS__); \ } \ } while (0) #define DEBUG_ARG(fmt, ...) do { \ if (slirp_debug & DBG_CALL) { \ - fputc(' ', dfd); \ - fprintf(dfd, fmt, ##__VA_ARGS__); \ - fputc('\n', dfd); \ - fflush(dfd); \ + g_debug(" " fmt, ##__VA_ARGS__); \ } \ } while (0) #define DEBUG_MISC(fmt, ...) do { \ if (slirp_debug & DBG_MISC) { \ - fprintf(dfd, fmt, ##__VA_ARGS__); \ - fflush(dfd); \ + g_debug(fmt, ##__VA_ARGS__); \ } \ } while (0) #define DEBUG_ERROR(fmt, ...) do { \ if (slirp_debug & DBG_ERROR) { \ - fprintf(dfd, fmt, ##__VA_ARGS__); \ - fflush(dfd); \ + g_debug(fmt, ##__VA_ARGS__); \ } \ } while (0) diff --git a/slirp/cksum.c b/slirp/cksum.c index 0a988b845d..84c858fafb 100644 --- a/slirp/cksum.c +++ b/slirp/cksum.c @@ -121,8 +121,8 @@ int cksum(struct mbuf *m, int len) cont: if (len) { - DEBUG_ERROR("cksum: out of data\n"); - DEBUG_ERROR(" len = %d\n", len); + DEBUG_ERROR("cksum: out of data"); + DEBUG_ERROR(" len = %d", len); } if (mlen == -1) { /* The last mbuf has odd # of bytes. Follow the diff --git a/slirp/dhcpv6.c b/slirp/dhcpv6.c index 5d703e8ae6..752df40536 100644 --- a/slirp/dhcpv6.c +++ b/slirp/dhcpv6.c @@ -92,13 +92,13 @@ static int dhcpv6_parse_info_request(Slirp *slirp, uint8_t *odata, int olen, ri->want_boot_url = true; break; default: - DEBUG_MISC("dhcpv6: Unsupported option request %d\n", + DEBUG_MISC("dhcpv6: Unsupported option request %d", req_opt); } } break; default: - DEBUG_MISC("dhcpv6 info req: Unsupported option %d, len=%d\n", + DEBUG_MISC("dhcpv6 info req: Unsupported option %d, len=%d", option, len); } @@ -203,6 +203,6 @@ void dhcpv6_input(struct sockaddr_in6 *srcsas, struct mbuf *m) dhcpv6_info_request(m->slirp, srcsas, xid, &data[4], data_len - 4); break; default: - DEBUG_MISC("dhcpv6_input: Unsupported message type 0x%x\n", data[0]); + DEBUG_MISC("dhcpv6_input: Unsupported message type 0x%x", data[0]); } } diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c index cd2faeacb6..7c7e042049 100644 --- a/slirp/ip_icmp.c +++ b/slirp/ip_icmp.c @@ -103,7 +103,7 @@ static int icmp_send(struct socket *so, struct mbuf *m, int hlen) if (sendto(so->s, m->m_data + hlen, m->m_len - hlen, 0, (struct sockaddr *)&addr, sizeof(addr)) == -1) { - DEBUG_MISC("icmp_input icmp sendto tx errno = %d-%s\n", + DEBUG_MISC("icmp_input icmp sendto tx errno = %d-%s", errno, strerror(errno)); icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno)); icmp_detach(so); @@ -169,7 +169,7 @@ icmp_input(struct mbuf *m, int hlen) return; } if (udp_attach(so, AF_INET) == -1) { - DEBUG_MISC("icmp_input udp_attach errno = %d-%s\n", + DEBUG_MISC("icmp_input udp_attach errno = %d-%s", errno,strerror(errno)); sofree(so); m_free(m); @@ -192,7 +192,7 @@ icmp_input(struct mbuf *m, int hlen) if(sendto(so->s, icmp_ping_msg, strlen(icmp_ping_msg), 0, (struct sockaddr *)&addr, sockaddr_size(&addr)) == -1) { - DEBUG_MISC("icmp_input udp sendto tx errno = %d-%s\n", + DEBUG_MISC("icmp_input udp sendto tx errno = %d-%s", errno,strerror(errno)); icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno)); udp_detach(so); @@ -261,7 +261,7 @@ icmp_send_error(struct mbuf *msrc, u_char type, u_char code, int minsize, char bufa[20], bufb[20]; strcpy(bufa, inet_ntoa(ip->ip_src)); strcpy(bufb, inet_ntoa(ip->ip_dst)); - DEBUG_MISC(" %.16s to %.16s\n", bufa, bufb); + DEBUG_MISC(" %.16s to %.16s", bufa, bufb); } if(ip->ip_off & IP_OFFMASK) goto end_error; /* Only reply to fragment 0 */ @@ -458,7 +458,7 @@ void icmp_receive(struct socket *so) } else { error_code = ICMP_UNREACH_HOST; } - DEBUG_MISC(" udp icmp rx errno = %d-%s\n", errno, + DEBUG_MISC(" udp icmp rx errno = %d-%s", errno, strerror(errno)); icmp_send_error(so->so_m, ICMP_UNREACH, error_code, 0, strerror(errno)); } else { diff --git a/slirp/slirp.c b/slirp/slirp.c index 12aad702c2..f254a23a5a 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -165,7 +165,7 @@ static int get_dns_addr_resolv_conf(int af, void *pdns_addr, void *cached_addr, if (!f) return -1; - DEBUG_MISC("IP address of your DNS(s): "); + DEBUG_MISC("IP address of your DNS(s):"); while (fgets(buff, 512, f) != NULL) { if (sscanf(buff, "nameserver%*[ \t]%256s", buff2) == 1) { char *c = strchr(buff2, '%'); @@ -187,20 +187,18 @@ static int get_dns_addr_resolv_conf(int af, void *pdns_addr, void *cached_addr, *scope_id = if_index; } *cached_time = curtime; - } else { - DEBUG_MISC(", "); } if (++found > 3) { - DEBUG_MISC("(more)"); + DEBUG_MISC(" (more)"); break; } else if (slirp_debug & DBG_MISC) { char s[INET6_ADDRSTRLEN]; const char *res = inet_ntop(af, tmp_addr, s, sizeof(s)); if (!res) { - res = "(string conversion error)"; + res = " (string conversion error)"; } - DEBUG_MISC("%s", res); + DEBUG_MISC(" %s", res); } } } diff --git a/slirp/socket.c b/slirp/socket.c index 08a065f6a7..5ffbaa064a 100644 --- a/slirp/socket.c +++ b/slirp/socket.c @@ -208,7 +208,8 @@ soread(struct socket *so) } } - DEBUG_MISC(" --- soread() disconnected, nn = %d, errno = %d-%s\n", nn, errno,strerror(errno)); + DEBUG_MISC(" --- soread() disconnected, nn = %d, errno = %d-%s", + nn, errno,strerror(errno)); sofcantrcvmore(so); if (err == ECONNRESET || err == ECONNREFUSED @@ -237,7 +238,7 @@ soread(struct socket *so) nn += ret; } - DEBUG_MISC(" ... read nn = %d bytes\n", nn); + DEBUG_MISC(" ... read nn = %d bytes", nn); /* Update fields */ sb->sb_cc += nn; @@ -370,7 +371,7 @@ sosendoob(struct socket *so) n = slirp_send(so, buff, len, (MSG_OOB)); /* |MSG_DONTWAIT)); */ #ifdef DEBUG if (n != len) { - DEBUG_ERROR("Didn't send all data urgently XXXXX\n"); + DEBUG_ERROR("Didn't send all data urgently XXXXX"); } #endif } @@ -379,7 +380,7 @@ sosendoob(struct socket *so) return n; } so->so_urgc -= n; - DEBUG_MISC(" ---2 sent %d bytes urgent data, %d urgent bytes left\n", n, so->so_urgc); + DEBUG_MISC(" ---2 sent %d bytes urgent data, %d urgent bytes left", n, so->so_urgc); sb->sb_cc -= n; sb->sb_rptr += n; @@ -460,7 +461,7 @@ sowrite(struct socket *so) if (ret > 0) nn += ret; } - DEBUG_MISC(" ... wrote nn = %d bytes\n", nn); + DEBUG_MISC(" ... wrote nn = %d bytes", nn); /* Update sbuf */ sb->sb_cc -= nn; @@ -478,7 +479,7 @@ sowrite(struct socket *so) return nn; err_disconnected: - DEBUG_MISC(" --- sowrite disconnected, so->so_state = %x, errno = %d\n", + DEBUG_MISC(" --- sowrite disconnected, so->so_state = %x, errno = %d", so->so_state, errno); sofcantsendmore(so); tcp_sockclosed(sototcpcb(so)); @@ -512,7 +513,7 @@ sorecvfrom(struct socket *so) if(errno == EHOSTUNREACH) code=ICMP_UNREACH_HOST; else if(errno == ENETUNREACH) code=ICMP_UNREACH_NET; - DEBUG_MISC(" udp icmp rx errno = %d-%s\n", + DEBUG_MISC(" udp icmp rx errno = %d-%s", errno,strerror(errno)); icmp_send_error(so->so_m, ICMP_UNREACH, code, 0, strerror(errno)); } else { @@ -564,7 +565,7 @@ sorecvfrom(struct socket *so) m->m_len = recvfrom(so->s, m->m_data, len, 0, (struct sockaddr *)&addr, &addrlen); - DEBUG_MISC(" did recvfrom %d, errno = %d-%s\n", + DEBUG_MISC(" did recvfrom %d, errno = %d-%s", m->m_len, errno,strerror(errno)); if(m->m_len<0) { /* Report error as ICMP */ @@ -579,7 +580,7 @@ sorecvfrom(struct socket *so) code = ICMP_UNREACH_NET; } - DEBUG_MISC(" rx error, tx icmp ICMP_UNREACH:%i\n", code); + DEBUG_MISC(" rx error, tx icmp ICMP_UNREACH:%i", code); icmp_send_error(so->so_m, ICMP_UNREACH, code, 0, strerror(errno)); break; case AF_INET6: @@ -591,7 +592,7 @@ sorecvfrom(struct socket *so) code = ICMP6_UNREACH_NO_ROUTE; } - DEBUG_MISC(" rx error, tx icmp6 ICMP_UNREACH:%i\n", code); + DEBUG_MISC(" rx error, tx icmp6 ICMP_UNREACH:%i", code); icmp6_send_error(so->so_m, ICMP6_UNREACH, code); break; default: @@ -839,8 +840,7 @@ void sotranslate_out(struct socket *so, struct sockaddr_storage *addr) } } - DEBUG_MISC(" addr.sin_port=%d, " - "addr.sin_addr.s_addr=%.16s\n", + DEBUG_MISC(" addr.sin_port=%d, addr.sin_addr.s_addr=%.16s", ntohs(sin->sin_port), inet_ntoa(sin->sin_addr)); break; diff --git a/slirp/tcp_input.c b/slirp/tcp_input.c index d24295813a..a6596b63ac 100644 --- a/slirp/tcp_input.c +++ b/slirp/tcp_input.c @@ -641,8 +641,7 @@ findso: (errno != EINPROGRESS) && (errno != EWOULDBLOCK) ) { uint8_t code; - DEBUG_MISC(" tcp fconnect errno = %d-%s\n", - errno,strerror(errno)); + DEBUG_MISC(" tcp fconnect errno = %d-%s", errno, strerror(errno)); if(errno == ECONNREFUSED) { /* ACK the SYN, send RST to refuse the connection */ tcp_respond(tp, ti, m, ti->ti_seq + 1, (tcp_seq) 0, @@ -1011,7 +1010,7 @@ trimthenstep6: if (SEQ_LEQ(ti->ti_ack, tp->snd_una)) { if (ti->ti_len == 0 && tiwin == tp->snd_wnd) { - DEBUG_MISC(" dup ack m = %p so = %p\n", m, so); + DEBUG_MISC(" dup ack m = %p so = %p", m, so); /* * If we have outstanding data (other than * a window probe), this is a completely @@ -1550,7 +1549,7 @@ tcp_mss(struct tcpcb *tp, u_int offer) (mss - (TCP_RCVSPACE % mss)) : 0)); - DEBUG_MISC(" returning mss = %d\n", mss); + DEBUG_MISC(" returning mss = %d", mss); return mss; } diff --git a/slirp/tcp_output.c b/slirp/tcp_output.c index 44da8a4e47..2f7f90d67e 100644 --- a/slirp/tcp_output.c +++ b/slirp/tcp_output.c @@ -92,7 +92,7 @@ again: flags = tcp_outflags[tp->t_state]; - DEBUG_MISC(" --- tcp_output flags = 0x%x\n", flags); + DEBUG_MISC(" --- tcp_output flags = 0x%x", flags); /* * If in persist timeout with window of 0, send 1 byte. diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c index 042fa1e4fb..5dcf979c3c 100644 --- a/slirp/tcp_subr.c +++ b/slirp/tcp_subr.c @@ -964,7 +964,7 @@ int tcp_ctl(struct socket *so) so->guestfwd = ex_ptr; return 1; } - DEBUG_MISC(" executing %s\n", ex_ptr->ex_exec); + DEBUG_MISC(" executing %s", ex_ptr->ex_exec); return fork_exec(so, ex_ptr->ex_exec); } } diff --git a/slirp/udp.c b/slirp/udp.c index a45ad81dda..4cf0d34d64 100644 --- a/slirp/udp.c +++ b/slirp/udp.c @@ -172,8 +172,7 @@ udp_input(register struct mbuf *m, int iphlen) */ so = socreate(slirp); if (udp_attach(so, AF_INET) == -1) { - DEBUG_MISC(" udp_attach errno = %d-%s\n", - errno, strerror(errno)); + DEBUG_MISC(" udp_attach errno = %d-%s", errno, strerror(errno)); sofree(so); goto bad; } @@ -209,7 +208,7 @@ udp_input(register struct mbuf *m, int iphlen) m->m_len += iphlen; m->m_data -= iphlen; *ip=save_ip; - DEBUG_MISC("udp tx errno = %d-%s\n", errno, strerror(errno)); + DEBUG_MISC("udp tx errno = %d-%s", errno, strerror(errno)); icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno)); goto bad; diff --git a/slirp/udp6.c b/slirp/udp6.c index 8cdb1892e2..fa531e03c4 100644 --- a/slirp/udp6.c +++ b/slirp/udp6.c @@ -92,8 +92,7 @@ void udp6_input(struct mbuf *m) /* If there's no socket for this packet, create one. */ so = socreate(slirp); if (udp_attach(so, AF_INET6) == -1) { - DEBUG_MISC(" udp6_attach errno = %d-%s\n", - errno, strerror(errno)); + DEBUG_MISC(" udp6_attach errno = %d-%s", errno, strerror(errno)); sofree(so); goto bad; } @@ -119,7 +118,7 @@ void udp6_input(struct mbuf *m) m->m_len += iphlen; m->m_data -= iphlen; *ip = save_ip; - DEBUG_MISC("udp tx errno = %d-%s\n", errno, strerror(errno)); + DEBUG_MISC("udp tx errno = %d-%s", errno, strerror(errno)); icmp6_send_error(m, ICMP6_UNREACH, ICMP6_UNREACH_NO_ROUTE); goto bad; }