[Qemu-devel] [PULL 63/65] slirp: call into g_debug() for DEBUG macros

2019-01-14 Thread Samuel Thibault
From: Marc-André Lureau 

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 
Signed-off-by: Samuel Thibault 
---
 slirp/cksum.c  |  4 ++--
 slirp/debug.h  | 17 -
 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/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/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/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",
  

[Qemu-devel] [PULL 63/65] slirp: call into g_debug() for DEBUG macros

2019-01-13 Thread Samuel Thibault
From: Marc-André Lureau 

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 
Signed-off-by: Samuel Thibault 
---
 slirp/cksum.c  |  4 ++--
 slirp/debug.h  | 17 -
 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/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/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/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",