qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Samuel Thibault
Subject: [Qemu-devel] [PULL 63/64] slirp: call into g_debug() for DEBUG macros
Date: Wed, 19 Dec 2018 00:04:41 +0100

From: Marc-André Lureau <address@hidden>

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 <address@hidden>
Signed-off-by: Samuel Thibault <address@hidden>
---
 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",
                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 dcab564a79..a91cda8ce5 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -166,7 +166,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, '%');
@@ -188,20 +188,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 3b14684107..4a9a5b5edc 100644
--- a/slirp/tcp_subr.c
+++ b/slirp/tcp_subr.c
@@ -964,7 +964,7 @@ int tcp_ctl(struct socket *so)
                     so->chardev = ex_ptr->ex_chardev;
                     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;
     }
-- 
2.19.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]