]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Code clean up in common source files.
authorOliver Kurth <okurth@vmware.com>
Mon, 28 Oct 2019 23:12:40 +0000 (16:12 -0700)
committerOliver Kurth <okurth@vmware.com>
Mon, 28 Oct 2019 23:12:40 +0000 (16:12 -0700)
Fix macros so they work in the world of Log Facility newlining.

The Log Facility no longer accepts appending calls into a single
line.  As such, some macros need to be "fixed up".

open-vm-tools/lib/asyncsocket/asyncSocketBase.c
open-vm-tools/lib/asyncsocket/asyncsocket.c
open-vm-tools/lib/include/asyncsocket.h
open-vm-tools/lib/stubs/stub-log.c
open-vm-tools/libvmtools/vmtoolsLog.c

index 2cffea909ace5475e9689b3759ac5b99147a5f62..f707af2075345cf7b5020522749787d79f56cc1c 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2016 VMware, Inc. All rights reserved.
+ * Copyright (C) 2016-2019 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
  * implicitly calls.  We don't log fd as that isn't available at the
  * base class level.
  */
-#define ASOCKLOG_NORECURSION(_level, _asock, _logargs)                  \
+#define ASOCKLOG_NORECURSION(_level, _asock, ...)                       \
    do {                                                                 \
       if (((_level) == 0) || DOLOG_BYNAME(asyncsocket, (_level))) {     \
-         Log(ASOCKPREFIX "%d ", (_asock)->id);                          \
-         Log _logargs;                                                  \
+         void *acc = Log_BufBegin();                                    \
+                                                                        \
+         Log_BufAppend(acc, ASOCKPREFIX "%d ", (_asock)->id);           \
+         Log_BufAppend(acc, __VA_ARGS__);                               \
+         Log_BufEndLevel(acc, VMW_LOG_INFO);                            \
       }                                                                 \
    } while(0)
 
@@ -125,10 +128,10 @@ AsyncSocketInternalDecRef(AsyncSocket *s, // IN
 
    ASSERT(count >= 0);
    if (UNLIKELY(count == 0)) {
-      ASOCKLOG_NORECURSION(1, s, ("Final release; freeing asock struct\n"));
+      ASOCKLOG_NORECURSION(1, s, "Final release; freeing asock struct\n");
       VT(s)->destroy(s);
    } else {
-      ASOCKLOG_NORECURSION(1, s, ("Release (count now %d)\n", count));
+      ASOCKLOG_NORECURSION(1, s, "Release (count now %d)\n", count);
    }
 }
 
@@ -477,12 +480,12 @@ AsyncSocketHandleError(AsyncSocket *asock,   // IN
    ASSERT(asock);
    asock->errorSeen = TRUE;
    if (asock->errorFn) {
-      ASOCKLOG(3, asock, ("firing error callback (%s)\n",
-                          AsyncSocket_Err2String(asockErr)));
+      ASOCKLOG(3, asock, "firing error callback (%s)\n",
+               AsyncSocket_Err2String(asockErr));
       asock->errorFn(asockErr, asock, asock->errorClientData);
    } else {
-      ASOCKLOG(3, asock, ("no error callback, closing socket (%s)\n",
-                          AsyncSocket_Err2String(asockErr)));
+      ASOCKLOG(3, asock, "no error callback, closing socket (%s)\n",
+               AsyncSocket_Err2String(asockErr));
       AsyncSocket_Close(asock);
    }
 }
@@ -529,7 +532,7 @@ AsyncSocketCheckAndDispatchRecv(AsyncSocket *s,  // IN
 
    if (s->recvPos == s->recvLen || s->recvFireOnPartial) {
       void *recvBuf = s->recvBuf;
-      ASOCKLOG(3, s, ("recv buffer full, calling recvFn\n"));
+      ASOCKLOG(3, s, "recv buffer full, calling recvFn\n");
 
       /*
        * We do this dance in case the handler frees the buffer (so
@@ -544,7 +547,7 @@ AsyncSocketCheckAndDispatchRecv(AsyncSocket *s,  // IN
       s->recvBuf = NULL;
       s->recvFn(recvBuf, s->recvPos, s, s->recvClientData);
       if (s->state == AsyncSocketClosed) {
-         ASOCKLG0(s, ("owner closed connection in recv callback\n"));
+         ASOCKLG0(s, "owner closed connection in recv callback\n");
          *result = ASOCKERR_CLOSED;
          return TRUE;
       } else if (s->recvFn == NULL && s->recvLen == 0) {
@@ -605,22 +608,22 @@ AsyncSocketSetRecvBuf(AsyncSocket *asock,  // IN:
    ASSERT(AsyncSocketIsLocked(asock));
 
    if (!asock->errorFn) {
-      ASOCKWARN(asock, ("%s: no registered error handler!\n", __FUNCTION__));
+      ASOCKWARN(asock, "%s: no registered error handler!\n", __FUNCTION__);
       return ASOCKERR_INVAL;
    }
 
    if (!buf || !cb || len <= 0) {
-      ASOCKWARN(asock, ("Recv called with invalid arguments!\n"));
+      ASOCKWARN(asock, "Recv called with invalid arguments!\n");
       return ASOCKERR_INVAL;
    }
 
    if (AsyncSocketGetState(asock) != AsyncSocketConnected) {
-      ASOCKWARN(asock, ("recv called but state is not connected!\n"));
+      ASOCKWARN(asock, "recv called but state is not connected!\n");
       return ASOCKERR_NOTCONNECTED;
    }
 
    if (asock->recvBuf && asock->recvPos != 0) {
-      ASOCKWARN(asock, ("Recv called -- partially read buffer discarded.\n"));
+      ASOCKWARN(asock, "Recv called -- partially read buffer discarded.\n");
    }
 
    asock->recvBuf = buf;
index 6e6fff0c1371930f0384c6250eb9e0e0d0ddff8f..a4318db858a1a93ce6391ab1c2359f6d7c5a97d5 100644 (file)
@@ -545,9 +545,9 @@ AsyncTCPSocketHandleError(AsyncTCPSocket *asock, int error)
  *----------------------------------------------------------------------
  */
 
-#define TCPSOCKWARN(a,b) ASOCKWARN(BaseSocket(a), b)
-#define TCPSOCKLOG(a,b,c) ASOCKLOG(a, BaseSocket(b), c)
-#define TCPSOCKLG0(a,b) ASOCKLG0(BaseSocket(a), b)
+#define TCPSOCKWARN(a, ...)   ASOCKWARN(BaseSocket(a), __VA_ARGS__)
+#define TCPSOCKLOG(a, b, ...) ASOCKLOG(a, BaseSocket(b), __VA_ARGS__)
+#define TCPSOCKLG0(a, ...)    ASOCKLG0(BaseSocket(a), __VA_ARGS__)
 
 
 /*
@@ -671,7 +671,7 @@ AsyncTCPSocketGetAddr(AsyncTCPSocket *asock,             // IN
       *outAddrLen = addrLen;
       return ASOCKERR_SUCCESS;
    } else {
-      TCPSOCKWARN(tempAsock, ("%s: could not locate socket.\n", __FUNCTION__));
+      TCPSOCKWARN(tempAsock, "%s: could not locate socket.\n", __FUNCTION__);
       return ASOCKERR_GENERIC;
    }
 }
@@ -767,15 +767,14 @@ AsyncTCPSocketGetINETIPStr(AsyncSocket *base,   // IN
       char addrBuf[NI_MAXHOST];
 
       if (ipRetStr == NULL) {
-         TCPSOCKWARN(asock, ("%s: Output string is not usable.\n",
-                             __FUNCTION__));
+         TCPSOCKWARN(asock, "%s: Output string is not usable.\n", __FUNCTION__);
          ret = ASOCKERR_INVAL;
       } else if (Posix_GetNameInfo((struct sockaddr *)&addr, addrLen, addrBuf,
                                    sizeof addrBuf, NULL, 0,
                                    NI_NUMERICHOST) == 0) {
          *ipRetStr = Util_SafeStrdup(addrBuf);
       } else {
-         TCPSOCKWARN(asock, ("%s: could not find IP address.\n", __FUNCTION__));
+         TCPSOCKWARN(asock, "%s: could not find IP address.\n", __FUNCTION__);
          ret = ASOCKERR_GENERIC;
       }
    }
@@ -949,9 +948,9 @@ AsyncTCPSocketListenerCreateImpl(
 
       if (asock) {
          TCPSOCKLG0(asock,
-                  ("Created new %s %s listener for (%s)\n",
-                   addr.ss_family == AF_INET ? "IPv4" : "IPv6",
-                   "socket", ipString));
+                  "Created new %s %s listener for (%s)\n",
+                  addr.ss_family == AF_INET ? "IPv4" : "IPv6",
+                  "socket", ipString);
       } else {
          Log(ASOCKPREFIX "Could not create %s listener socket, error %d: %s\n",
              addr.ss_family == AF_INET ? "IPv4" : "IPv6", *outError,
@@ -1459,7 +1458,7 @@ AsyncTCPSocketBind(AsyncTCPSocket *asock,          // IN
    ASSERT(NULL != addr);
 
    port = AsyncTCPSocketGetPortFromAddr(addr);
-   TCPSOCKLG0(asock, ("creating new listening socket on port %d\n", port));
+   TCPSOCKLG0(asock, "creating new listening socket on port %d\n", port);
 
 #ifndef _WIN32
    /*
@@ -1949,8 +1948,8 @@ AsyncTCPSocketConnectErrorCheck(void *data)  // IN: AsyncTCPSocket *
       } else {
          asock->genericErrno = ASOCK_LASTERROR();
       }
-      TCPSOCKLG0(asock, ("Connection failed: %s\n",
-                       Err_Errno2String(asock->genericErrno)));
+      TCPSOCKLG0(asock, "Connection failed: %s\n",
+                 Err_Errno2String(asock->genericErrno));
       /* Remove connect callback. */
       removed = AsyncTCPSocketPollRemove(asock, TRUE, POLL_FLAG_WRITE,
                                       asock->internalConnectFn);
@@ -2304,7 +2303,7 @@ AsyncTCPSocketAttachToSSLSock(SSLSock sslSock,                   // IN
 
    /* From now on socket is ours. */
    SSL_SetCloseOnShutdownFlag(sslSock);
-   TCPSOCKLOG(1, s, ("new asock id %u attached to fd %d\n", s->base.id, s->fd));
+   TCPSOCKLOG(1, s, "new asock id %u attached to fd %d\n", s->base.id, s->fd);
 
    return s;
 
@@ -2535,7 +2534,7 @@ AsyncTCPSocketRecv(AsyncSocket *base,   // IN:
    int retVal;
 
    if (!asock->base.errorFn) {
-      TCPSOCKWARN(asock, ("%s: no registered error handler!\n", __FUNCTION__));
+      TCPSOCKWARN(asock, "%s: no registered error handler!\n", __FUNCTION__);
       return ASOCKERR_INVAL;
    }
 
@@ -2554,12 +2553,12 @@ AsyncTCPSocketRecv(AsyncSocket *base,   // IN:
    ASSERT(AsyncTCPSocketIsLocked(asock));
 
    if (AsyncTCPSocketGetState(asock) != AsyncSocketConnected) {
-      TCPSOCKWARN(asock, ("recv called but state is not connected!\n"));
+      TCPSOCKWARN(asock, "recv called but state is not connected!\n");
       return ASOCKERR_NOTCONNECTED;
    }
 
    if (asock->inBlockingRecv && !asock->inRecvLoop) {
-      TCPSOCKWARN(asock, ("Recv called while a blocking recv is pending.\n"));
+      TCPSOCKWARN(asock, "Recv called while a blocking recv is pending.\n");
       return ASOCKERR_INVAL;
    }
 
@@ -2602,7 +2601,7 @@ AsyncTCPSocketRecvPassedFd(AsyncSocket *base,   // IN/OUT: socket
    int err;
 
    if (!asock->base.errorFn) {
-      TCPSOCKWARN(asock, ("%s: no registered error handler!\n", __FUNCTION__));
+      TCPSOCKWARN(asock, "%s: no registered error handler!\n", __FUNCTION__);
 
       return ASOCKERR_INVAL;
    }
@@ -2733,8 +2732,8 @@ AsyncTCPSocketPollWork(AsyncTCPSocket **asock,     // IN:
          /*
           * No sockets were ready within the specified time.
           */
-         TCPSOCKLG0(warnSock, ("%s: Timeout waiting for a ready socket.\n",
-                      __FUNCTION__));
+         TCPSOCKLG0(warnSock, "%s: Timeout waiting for a ready socket.\n",
+                    __FUNCTION__);
          return ASOCKERR_TIMEOUT;
 
       case -1: {
@@ -2746,8 +2745,8 @@ AsyncTCPSocketPollWork(AsyncTCPSocket **asock,     // IN:
              * XXX: update the timeout by the amount we had previously waited.
              */
 
-            TCPSOCKLG0(warnSock, ("%s: Socket interrupted by a signal.\n",
-                         __FUNCTION__));
+            TCPSOCKLG0(warnSock, "%s: Socket interrupted by a signal.\n",
+                       __FUNCTION__);
             continue;
          }
 
@@ -2759,8 +2758,8 @@ AsyncTCPSocketPollWork(AsyncTCPSocket **asock,     // IN:
             }
          }
 
-         TCPSOCKLG0(warnSock, ("%s: Failed with error %d: %s\n", __FUNCTION__,
-                   sysErr, Err_Errno2String(sysErr)));
+         TCPSOCKLG0(warnSock, "%s: Failed with error %d: %s\n", __FUNCTION__,
+                    sysErr, Err_Errno2String(sysErr));
          return ASOCKERR_GENERIC;
       }
       default: {
@@ -2791,16 +2790,15 @@ AsyncTCPSocketPollWork(AsyncTCPSocket **asock,     // IN:
                   if (sockErr) {
                      asock[i]->genericErrno = sockErr;
                      TCPSOCKLG0(asock[i],
-                              ("%s: Socket error lookup returned %d: %s\n",
-                               __FUNCTION__, sockErr,
-                               Err_Errno2String(sockErr)));
+                              "%s: Socket error lookup returned %d: %s\n",
+                              __FUNCTION__, sockErr,
+                              Err_Errno2String(sockErr));
                   }
                } else {
                   sysErr = ASOCK_LASTERROR();
                   asock[i]->genericErrno = sysErr;
-                  TCPSOCKLG0(asock[i],
-                           ("%s: Last socket error %d: %s\n",
-                            __FUNCTION__, sysErr, Err_Errno2String(sysErr)));
+                  TCPSOCKLG0(asock[i], "%s: Last socket error %d: %s\n",
+                             __FUNCTION__, sysErr, Err_Errno2String(sysErr));
                }
             }
 
@@ -2828,8 +2826,8 @@ AsyncTCPSocketPollWork(AsyncTCPSocket **asock,     // IN:
          }
 #endif
 
-         TCPSOCKWARN(warnSock, ("%s: Failed to return a ready socket.\n",
-                         __FUNCTION__));
+         TCPSOCKWARN(warnSock, "%s: Failed to return a ready socket.\n",
+                     __FUNCTION__);
          return ASOCKERR_GENERIC;
       }
       }
@@ -2876,7 +2874,7 @@ AsyncTCPSocketPoll(AsyncTCPSocket *s,          // IN:
 
    if (read && s->fd == -1) {
       if (!s->listenAsock4 && !s->listenAsock6) {
-         TCPSOCKLG0(s, ("%s: Failed to find listener socket.\n", __FUNCTION__));
+         TCPSOCKLG0(s, "%s: Failed to find listener socket.\n", __FUNCTION__);
          return ASOCKERR_GENERIC;
       }
 
@@ -3071,13 +3069,13 @@ AsyncTCPSocketBlockingWork(AsyncTCPSocket *s,  // IN:
          }
          buf = (uint8*)buf + numBytes;
       } else if (numBytes == 0) {
-         TCPSOCKLG0(s, ("blocking %s detected peer closed connection\n",
-                        read ? "recv" : "send"));
+         TCPSOCKLG0(s, "blocking %s detected peer closed connection\n",
+                    read ? "recv" : "send");
          return ASOCKERR_REMOTE_DISCONNECT;
       } else if ((sysErr = ASOCK_LASTERROR()) != ASOCK_EWOULDBLOCK) {
          s->genericErrno = sysErr;
-         TCPSOCKWARN(s, ("blocking %s error %d: %s\n", read ? "recv" : "send",
-                         sysErr, Err_Errno2String(sysErr)));
+         TCPSOCKWARN(s, "blocking %s error %d: %s\n", read ? "recv" : "send",
+                     sysErr, Err_Errno2String(sysErr));
 
          return ASOCKERR_GENERIC;
       }
@@ -3171,7 +3169,7 @@ AsyncTCPSocketSend(AsyncSocket *base,         // IN
    ASSERT(asock->inLowLatencySendCb < 2);
 
    if (AsyncTCPSocketGetState(asock) != AsyncSocketConnected) {
-      TCPSOCKWARN(asock, ("send called but state is not connected!\n"));
+      TCPSOCKWARN(asock, "send called but state is not connected!\n");
       return ASOCKERR_NOTCONNECTED;
    }
 
@@ -3233,8 +3231,7 @@ AsyncTCPSocketSend(AsyncSocket *base,         // IN
                                    != NULL ? 1 : 0)
              != VMWARE_STATUS_SUCCESS) {
             retVal = ASOCKERR_POLL;
-            TCPSOCKLOG(1, asock,
-                       ("Failed to register poll callback for send\n"));
+            TCPSOCKLOG(1, asock, "Failed to register poll callback for send\n");
             goto outUndoAppend;
          }
          asock->sendCbTimer = TRUE;
@@ -3244,8 +3241,7 @@ AsyncTCPSocketSend(AsyncSocket *base,         // IN
                                    asock->internalSendFn)
              != VMWARE_STATUS_SUCCESS) {
             retVal = ASOCKERR_POLL;
-            TCPSOCKLOG(1, asock,
-                       ("Failed to register poll callback for send\n"));
+            TCPSOCKLOG(1, asock, "Failed to register poll callback for send\n");
             goto outUndoAppend;
          }
          asock->sendCb = TRUE;
@@ -3469,15 +3465,15 @@ AsyncTCPSocketFillRecvBuffer(AsyncTCPSocket *s)         // IN
        * unless you can preserve the system error number
        */
       if (recvd > 0) {
-         TCPSOCKLOG(3, s, ("need\t%d\trecv\t%d\tremain\t%d\n", needed, recvd,
-                           needed - recvd));
+         TCPSOCKLOG(3, s, "need\t%d\trecv\t%d\tremain\t%d\n", needed, recvd,
+                    needed - recvd);
          s->sslConnected = TRUE;
          s->base.recvPos += recvd;
          if (AsyncSocketCheckAndDispatchRecv(&s->base, &result)) {
             goto exit;
          }
       } else if (recvd == 0) {
-         TCPSOCKLG0(s, ("recv detected client closed connection\n"));
+         TCPSOCKLG0(s, "recv detected client closed connection\n");
          /*
           * We treat this as an error so that the owner can detect closing
           * of connection by peer (via the error handler callback).
@@ -3485,11 +3481,10 @@ AsyncTCPSocketFillRecvBuffer(AsyncTCPSocket *s)         // IN
          result = ASOCKERR_REMOTE_DISCONNECT;
          goto exit;
       } else if ((sysErr = ASOCK_LASTERROR()) == ASOCK_EWOULDBLOCK) {
-         TCPSOCKLOG(4, s, ("recv would block\n"));
+         TCPSOCKLOG(4, s, "recv would block\n");
          break;
       } else {
-         TCPSOCKLG0(s, ("recv error %d: %s\n", sysErr,
-                      Err_Errno2String(sysErr)));
+         TCPSOCKLG0(s, "recv error %d: %s\n", sysErr, Err_Errno2String(sysErr));
          s->genericErrno = sysErr;
          result = ASOCKERR_GENERIC;
          goto exit;
@@ -3581,7 +3576,7 @@ AsyncTCPSocketDispatchSentBuffer(AsyncTCPSocket *s)         // IN
       ASSERT(s->base.refCount > 1);
       tmp.sendFn(tmp.buf, tmp.len, BaseSocket(s), tmp.clientData);
       if (AsyncTCPSocketGetState(s) == AsyncSocketClosed) {
-         TCPSOCKLG0(s, ("owner closed connection in send callback\n"));
+         TCPSOCKLG0(s, "owner closed connection in send callback\n");
          result = ASOCKERR_CLOSED;
       }
    }
@@ -3620,7 +3615,7 @@ AsyncTCPSocketWriteBuffers(AsyncTCPSocket *s)         // IN
    }
 
    if (AsyncTCPSocketGetState(s) != AsyncSocketConnected) {
-      TCPSOCKWARN(s, ("write buffers on a disconnected socket!\n"));
+      TCPSOCKWARN(s, "write buffers on a disconnected socket!\n");
       return ASOCKERR_GENERIC;
    }
 
@@ -3640,8 +3635,8 @@ AsyncTCPSocketWriteBuffers(AsyncTCPSocket *s)         // IN
        * unless you can preserve the system error number
        */
       if (sent > 0) {
-         TCPSOCKLOG(3, s, ("left\t%d\tsent\t%d\tremain\t%d\n",
-                        left, sent, left - sent));
+         TCPSOCKLOG(3, s, "left\t%d\tsent\t%d\tremain\t%d\n",
+                    left, sent, left - sent);
          s->sendBufFull = FALSE;
          s->sslConnected = TRUE;
          if ((s->sendPos += sent) == sizeToSend) {
@@ -3651,10 +3646,10 @@ AsyncTCPSocketWriteBuffers(AsyncTCPSocket *s)         // IN
             }
          }
       } else if (sent == 0) {
-         TCPSOCKLG0(s, ("socket write() should never return 0.\n"));
+         TCPSOCKLG0(s, "socket write() should never return 0.\n");
          NOT_REACHED();
       } else if ((error = ASOCK_LASTERROR()) != ASOCK_EWOULDBLOCK) {
-         TCPSOCKLG0(s, ("send error %d: %s\n", error, Err_Errno2String(error)));
+         TCPSOCKLG0(s, "send error %d: %s\n", error, Err_Errno2String(error));
          s->genericErrno = error;
          if (error == ASOCK_EPIPE || error == ASOCK_ECONNRESET) {
             result = ASOCKERR_REMOTE_DISCONNECT;
@@ -3725,7 +3720,7 @@ AsyncTCPSocketAcceptInternal(AsyncTCPSocket *s)         // IN
       sysErr = ASOCK_LASTERROR();
       s->genericErrno = sysErr;
       if (sysErr == ASOCK_EWOULDBLOCK) {
-         TCPSOCKWARN(s, ("spurious accept notification\n"));
+         TCPSOCKWARN(s, "spurious accept notification\n");
 #if TARGET_OS_IPHONE
          /*
           * For iOS, while the app is suspended and device's screen is locked,
@@ -3748,13 +3743,13 @@ AsyncTCPSocketAcceptInternal(AsyncTCPSocket *s)         // IN
           */
 
       } else if (sysErr == ECONNABORTED) {
-         TCPSOCKLG0(s, ("accept: new connection was aborted\n"));
+         TCPSOCKLG0(s, "accept: new connection was aborted\n");
 
          return ASOCKERR_GENERIC;
 #endif
       } else {
-         TCPSOCKWARN(s, ("accept failed on fd %d, error %d: %s\n",
-                       s->fd, sysErr, Err_Errno2String(sysErr)));
+         TCPSOCKWARN(s, "accept failed on fd %d, error %d: %s\n",
+                     s->fd, sysErr, Err_Errno2String(sysErr));
 
          return ASOCKERR_ACCEPT;
       }
@@ -3771,9 +3766,8 @@ AsyncTCPSocketAcceptInternal(AsyncTCPSocket *s)         // IN
        */
 
       if (IN6_IS_ADDR_V4MAPPED(&(addr6->sin6_addr))) {
-         TCPSOCKWARN(s,
-                   ("accept rejected on fd %d due to a IPv4-mapped IPv6 "
-                    "remote connection address.\n", s->fd));
+         TCPSOCKWARN(s, "accept rejected on fd %d due to a IPv4-mapped IPv6 "
+                     "remote connection address.\n", s->fd);
          SSLGeneric_close(fd);
 
          return ASOCKERR_ACCEPT;
@@ -3846,7 +3840,7 @@ AsyncTCPSocketConnectInternal(AsyncTCPSocket *s)         // IN
 
    if (optval != 0) {
       s->genericErrno = optval;
-      TCPSOCKLOG(1, s, ("connection SO_ERROR: %s\n", Err_Errno2String(optval)));
+      TCPSOCKLOG(1, s, "connection SO_ERROR: %s\n", Err_Errno2String(optval));
 
       return ASOCKERR_GENERIC;
    }
@@ -3992,7 +3986,7 @@ AsyncTCPSocketWaitForConnection(AsyncSocket *base,  // IN:
 
       if (read) {
          if (AsyncTCPSocketAcceptInternal(asock) != ASOCKERR_SUCCESS) {
-            TCPSOCKLG0(s, ("wait for connection: accept failed\n"));
+            TCPSOCKLG0(s, "wait for connection: accept failed\n");
 
             /*
              * Just fall through, we'll loop and try again as long as we still
@@ -4076,7 +4070,7 @@ AsyncTCPSocketDoOneMsg(AsyncSocket *base, // IN
           * The recv loop would read the data if there is any and it is
           * not safe to proceed and race with the recv loop.
           */
-         TCPSOCKLG0(s, ("busy: another thread in recv loop\n"));
+         TCPSOCKLG0(s, "busy: another thread in recv loop\n");
          return ASOCKERR_BUSY;
       }
 
@@ -4098,8 +4092,8 @@ AsyncTCPSocketDoOneMsg(AsyncSocket *base, // IN
       retVal = AsyncTCPSocketPoll(s, read, timeoutMS, &asock);
       if (retVal != ASOCKERR_SUCCESS) {
          if (retVal == ASOCKERR_GENERIC) {
-            TCPSOCKWARN(s, ("%s: failed to poll on the socket during read.\n",
-                       __FUNCTION__));
+            TCPSOCKWARN(s, "%s: failed to poll on the socket during read.\n",
+                        __FUNCTION__);
          }
       } else {
          ASSERT(asock == s);
@@ -4137,8 +4131,8 @@ AsyncTCPSocketDoOneMsg(AsyncSocket *base, // IN
       retVal = AsyncTCPSocketPoll(s, read, timeoutMS, &asock);
       if (retVal != ASOCKERR_SUCCESS) {
          if (retVal == ASOCKERR_GENERIC) {
-            TCPSOCKWARN(s, ("%s: failed to poll on the socket during write.\n",
-                            __FUNCTION__));
+            TCPSOCKWARN(s, "%s: failed to poll on the socket during write.\n",
+                        __FUNCTION__);
          }
       } else {
          ASSERT(asock == s);
@@ -4207,7 +4201,7 @@ AsyncSocket_TCPDrainRecv(AsyncSocket *base, // IN
           * The recv loop would read the data if there is any and it is
           * not safe to proceed and race with the recv loop.
           */
-         TCPSOCKLG0(s, ("busy: another thread in recv loop\n"));
+         TCPSOCKLG0(s, "busy: another thread in recv loop\n");
          retVal = ASOCKERR_BUSY;
          /* Add a bit of backoff. */
          AsyncTCPSocketUnlock(s);
@@ -4230,8 +4224,8 @@ AsyncSocket_TCPDrainRecv(AsyncSocket *base, // IN
       retVal = AsyncTCPSocketPoll(s, TRUE, 0, &asock);
       if (retVal != ASOCKERR_SUCCESS) {
          if (retVal == ASOCKERR_GENERIC) {
-            TCPSOCKWARN(s, ("%s: failed to poll on the socket during read.\n",
-                       __FUNCTION__));
+            TCPSOCKWARN(s, "%s: failed to poll on the socket during read.\n",
+                        __FUNCTION__);
          }
       } else if (AsyncTCPSocketGetState(s) == AsyncSocketConnected) {
          ASSERT(asock == s);
@@ -4323,7 +4317,7 @@ AsyncTCPSocketFlush(AsyncSocket *base,  // IN
    AsyncTCPSocketAddRef(s);
 
    if (AsyncTCPSocketGetState(s) != AsyncSocketConnected) {
-      TCPSOCKWARN(s, ("flush called but state is not connected!\n"));
+      TCPSOCKWARN(s, "flush called but state is not connected!\n");
       retVal = ASOCKERR_INVAL;
       goto outHaveLock;
    }
@@ -4336,7 +4330,7 @@ AsyncTCPSocketFlush(AsyncSocket *base,  // IN
 
       retVal = AsyncTCPSocketPoll(s, FALSE, done - now, &asock);
       if (retVal != ASOCKERR_SUCCESS) {
-         TCPSOCKWARN(s, ("flush failed\n"));
+         TCPSOCKWARN(s, "flush failed\n");
          goto outHaveLock;
       }
 
@@ -4352,7 +4346,7 @@ AsyncTCPSocketFlush(AsyncSocket *base,  // IN
 
          /* Don't timeout if you've sent everything */
          if (now > done && s->sendBufList) {
-            TCPSOCKWARN(s, ("flush timed out\n"));
+            TCPSOCKWARN(s, "flush timed out\n");
             retVal = ASOCKERR_TIMEOUT;
             goto outHaveLock;
          }
@@ -4426,7 +4420,7 @@ AsyncTCPSocketAddListenCb(AsyncTCPSocket *asock)  // IN:
                                       AsyncTCPSocketAcceptCallback);
 
    if (pollStatus != VMWARE_STATUS_SUCCESS) {
-      TCPSOCKWARN(asock, ("failed to install listen accept callback!\n"));
+      TCPSOCKWARN(asock, "failed to install listen accept callback!\n");
    }
 
    return pollStatus == VMWARE_STATUS_SUCCESS;
@@ -4462,7 +4456,7 @@ AsyncTCPSocketCancelRecvCb(AsyncTCPSocket *asock)  // IN:
    if (asock->recvCb) {
       Bool removed;
       TCPSOCKLOG(1, asock,
-                 ("Removing poll recv callback while cancelling recv.\n"));
+                 "Removing poll recv callback while cancelling recv.\n");
       removed = AsyncTCPSocketPollRemove(asock, TRUE,
                                          POLL_FLAG_READ | POLL_FLAG_PERIODIC,
                                          asock->internalRecvFn);
@@ -4548,7 +4542,7 @@ AsyncTCPSocketCancelCbForClose(AsyncSocket *base)  // IN:
       asock->recvCbTimer = FALSE;
    }
    if (asock->recvCb) {
-      TCPSOCKLOG(1, asock, ("recvCb is non-NULL, removing recv callback\n"));
+      TCPSOCKLOG(1, asock, "recvCb is non-NULL, removing recv callback\n");
       removed = AsyncTCPSocketPollRemove(asock, TRUE,
                                          POLL_FLAG_READ | POLL_FLAG_PERIODIC,
                                          asock->internalRecvFn);
@@ -4563,7 +4557,7 @@ AsyncTCPSocketCancelCbForClose(AsyncSocket *base)  // IN:
 
    if (asock->sendCb) {
       TCPSOCKLOG(1, asock,
-                 ("sendBufList is non-NULL, removing send callback\n"));
+                 "sendBufList is non-NULL, removing send callback\n");
 
       /*
        * The send callback could be either a device or RTime callback, so
@@ -4726,8 +4720,8 @@ AsyncTCPSocketClose(AsyncSocket *base)   // IN
                                        asock->flushEnabledMaxWaitMsec);
          if (ret != ASOCKERR_SUCCESS) {
             TCPSOCKWARN(asock,
-                        ("AsyncTCPSocket_Flush failed: %s. Closing now.\n",
-                         AsyncSocket_Err2String(ret)));
+                        "AsyncTCPSocket_Flush failed: %s. Closing now.\n",
+                        AsyncSocket_Err2String(ret));
          }
       }
 
@@ -4736,34 +4730,34 @@ AsyncTCPSocketClose(AsyncSocket *base)   // IN
        * right thing accordingly
        */
 
-      TCPSOCKLOG(1, asock, ("closing socket\n"));
+      TCPSOCKLOG(1, asock, "closing socket\n");
       oldState = AsyncTCPSocketGetState(asock);
       AsyncTCPSocketSetState(asock, AsyncSocketClosed);
 
       switch(oldState) {
       case AsyncSocketListening:
-         TCPSOCKLOG(1, asock, ("old state was listening, removing accept "
-                               "callback\n"));
+         TCPSOCKLOG(1, asock,
+                    "old state was listening, removing accept callback\n");
          AsyncTCPSocketCancelListenCb(asock);
          break;
 
       case AsyncSocketConnecting:
-         TCPSOCKLOG(1, asock, ("old state was connecting, removing connect "
-                               "callback\n"));
+         TCPSOCKLOG(1, asock,
+                    "old state was connecting, removing connect callback\n");
          removed = AsyncTCPSocketCancelCbForConnectingClose(asock);
          if (!removed) {
-            TCPSOCKLOG(1, asock, ("connect callback is not present in the poll "
-                                  "list.\n"));
+            TCPSOCKLOG(1, asock,
+                       "connect callback is not present in the poll list.\n");
          }
          break;
 
       case AsyncSocketConnected:
-         TCPSOCKLOG(1, asock, ("old state was connected\n"));
+         TCPSOCKLOG(1, asock, "old state was connected\n");
          AsyncTCPSocketCancelCbForClose(BaseSocket(asock));
          break;
 
       case AsyncSocketCBCancelled:
-         TCPSOCKLOG(1, asock, ("old state was CB-cancelled\n"));
+         TCPSOCKLOG(1, asock, "old state was CB-cancelled\n");
          break;
 
       default:
@@ -5080,9 +5074,9 @@ AsyncTCPSocketIPollRecvCallback(void *clientData)  // IN:
                                 asock->internalRecvFn, asock->fd);
       }
    } else {
-      TCPSOCKLG0(asock, ("Skip recv because %s\n",
-                         asock->recvCb ? "blocking recv is in progress"
-                                       : "recv callback is cancelled"));
+      TCPSOCKLG0(asock, "Skip recv because %s\n",
+                 asock->recvCb ? "blocking recv is in progress"
+                               : "recv callback is cancelled");
    }
 
    /* This is a one-shot callback so we always release the reference taken. */
@@ -5205,7 +5199,7 @@ AsyncTCPSocketIPollSendCallback(void *clientData)  // IN:
    if (s->sendCb) {
       AsyncTCPSocketSendCallback(s);
    } else {
-      TCPSOCKLG0(s, ("cancelled send callback fired\n"));
+      TCPSOCKLG0(s, "cancelled send callback fired\n");
    }
 
    s->inIPollCb &= ~IN_IPOLL_SEND;
@@ -5671,7 +5665,7 @@ AsyncTCPSocketSslConnectCallback(void *clientData)  // IN
                                       AsyncTCPSocketSslConnectCallback);
 
       if (pollStatus != VMWARE_STATUS_SUCCESS) {
-         TCPSOCKWARN(asock, ("failed to reinstall ssl connect callback!\n"));
+         TCPSOCKWARN(asock, "failed to reinstall ssl connect callback!\n");
          asock->sslPollFlags = 0;
          (*asock->sslConnectFn)(FALSE, BaseSocket(asock), asock->clientData);
       }
@@ -5728,7 +5722,7 @@ AsyncTCPSocketStartSslConnect(AsyncSocket *base,                    // IN
    ASSERT(AsyncTCPSocketIsLocked(asock));
 
    if (asock->sslConnectFn || asock->sslAcceptFn) {
-      TCPSOCKWARN(asock, ("An SSL operation was already initiated.\n"));
+      TCPSOCKWARN(asock, "An SSL operation was already initiated.\n");
       return ASOCKERR_GENERIC;
    }
 
@@ -5797,7 +5791,7 @@ AsyncTCPSocketSslAcceptCallback(void *clientData)         // IN
                                       AsyncTCPSocketSslAcceptCallback);
 
       if (pollStatus != VMWARE_STATUS_SUCCESS) {
-         TCPSOCKWARN(asock, ("failed to reinstall ssl accept callback!\n"));
+         TCPSOCKWARN(asock, "failed to reinstall ssl accept callback!\n");
          asock->sslPollFlags = 0;
          (*asock->sslAcceptFn)(FALSE, BaseSocket(asock), asock->clientData);
       }
@@ -5851,7 +5845,7 @@ AsyncTCPSocketStartSslAccept(AsyncSocket *base,                  // IN
    ASSERT(AsyncTCPSocketIsLocked(asock));
 
    if (asock->sslAcceptFn || asock->sslConnectFn) {
-      TCPSOCKWARN(asock, ("An SSL operation was already initiated.\n"));
+      TCPSOCKWARN(asock, "An SSL operation was already initiated.\n");
       return ASOCKERR_GENERIC;
    }
 
@@ -5921,9 +5915,9 @@ AsyncTCPSocketSetOption(AsyncSocket *asyncSocket,     // IN/OUT
       break;
    default:
       TCPSOCKLG0(tcpSocket,
-                 ("%s: Option layer [%d] (option [%d]) is not "
+                 "%s: Option layer [%d] (option [%d]) is not "
                      "supported for TCP socket.\n",
-                  __FUNCTION__, (int)layer, optID));
+                  __FUNCTION__, (int)layer, optID);
       return ASOCKERR_INVAL;
    }
 
@@ -5936,9 +5930,8 @@ AsyncTCPSocketSetOption(AsyncSocket *asyncSocket,     // IN/OUT
        (optID == ASYNC_SOCKET_OPT_SEND_LOW_LATENCY_MODE)) {
       ASSERT(inBufLen == sizeof(Bool));
       tcpSocket->sendLowLatency = *((const Bool *)valuePtr);
-      TCPSOCKLG0(tcpSocket,
-                 ("%s: sendLowLatencyMode set to [%d].\n",
-                  __FUNCTION__, (int)tcpSocket->sendLowLatency));
+      TCPSOCKLG0(tcpSocket, "%s: sendLowLatencyMode set to [%d].\n",
+                 __FUNCTION__, (int)tcpSocket->sendLowLatency);
       return ASOCKERR_SUCCESS;
    }
 
@@ -5984,10 +5977,10 @@ AsyncTCPSocketSetOption(AsyncSocket *asyncSocket,     // IN/OUT
 
    if (!isSupported) {
       TCPSOCKLG0(tcpSocket,
-                 ("%s: Option layer/level [%d], option/name [%d]: "
+                 "%s: Option layer/level [%d], option/name [%d]: "
                      "could not set OS option for TCP socket; "
                      "option not supported.\n",
-                  __FUNCTION__, (int)layer, optID));
+                  __FUNCTION__, (int)layer, optID);
       return ASOCKERR_INVAL;
    }
 
@@ -5997,19 +5990,19 @@ AsyncTCPSocketSetOption(AsyncSocket *asyncSocket,     // IN/OUT
                   valuePtr, inBufLen) != 0) {
       tcpSocket->genericErrno = Err_Errno();
       TCPSOCKLG0(tcpSocket,
-                 ("%s: Option layer/level [%d], option/name [%d]: "
+                 "%s: Option layer/level [%d], option/name [%d]: "
                      "could not set OS option for TCP socket; "
                      "error [%d: %s].\n",
                   __FUNCTION__, (int)layer, optID,
                   tcpSocket->genericErrno,
-                  Err_Errno2String(tcpSocket->genericErrno)));
+                  Err_Errno2String(tcpSocket->genericErrno));
       return ASOCKERR_GENERIC;
    }
 
    TCPSOCKLG0(tcpSocket,
-              ("%s: Option layer/level [%d], option/name [%d]: successfully "
+              "%s: Option layer/level [%d], option/name [%d]: successfully "
                   "set OS option for TCP socket.\n",
-               __FUNCTION__, (int)layer, optID));
+               __FUNCTION__, (int)layer, optID);
 
    return ASOCKERR_SUCCESS;
 }
@@ -6058,9 +6051,9 @@ AsyncTCPSocketGetOption(AsyncSocket *asyncSocket,     // IN/OUT
       break;
    default:
       TCPSOCKLG0(tcpSocket,
-                 ("%s: Option layer [%d] (option [%d]) is not "
+                 "%s: Option layer [%d] (option [%d]) is not "
                      "supported for TCP socket.\n",
-                  __FUNCTION__, (int)layer, optID));
+                  __FUNCTION__, (int)layer, optID);
       return ASOCKERR_INVAL;
    }
 
@@ -6070,8 +6063,8 @@ AsyncTCPSocketGetOption(AsyncSocket *asyncSocket,     // IN/OUT
       *outBufLen = sizeof(Bool);
       *((Bool *)valuePtr) = tcpSocket->sendLowLatency;
       TCPSOCKLG0(tcpSocket,
-                 ("%s: sendLowLatencyMode is [%d].\n",
-                  __FUNCTION__, (int)tcpSocket->sendLowLatency));
+                 "%s: sendLowLatencyMode is [%d].\n",
+                  __FUNCTION__, (int)tcpSocket->sendLowLatency);
       return ASOCKERR_SUCCESS;
    }
 
@@ -6098,10 +6091,10 @@ AsyncTCPSocketGetOption(AsyncSocket *asyncSocket,     // IN/OUT
 
    if (!isSupported) {
       TCPSOCKLG0(tcpSocket,
-                 ("%s: Option layer/level [%d], option/name [%d]: "
+                 "%s: Option layer/level [%d], option/name [%d]: "
                      "could not get OS option for TCP socket; "
                      "option not supported.\n",
-                  __FUNCTION__, (int)layer, optID));
+                  __FUNCTION__, (int)layer, optID);
       return ASOCKERR_INVAL;
    }
 
@@ -6109,19 +6102,19 @@ AsyncTCPSocketGetOption(AsyncSocket *asyncSocket,     // IN/OUT
                   valuePtr, outBufLen) != 0) {
       tcpSocket->genericErrno = Err_Errno();
       TCPSOCKLG0(tcpSocket,
-                 ("%s: Option layer/level [%d], option/name [%d]: "
+                 "%s: Option layer/level [%d], option/name [%d]: "
                      "could not get OS option for TCP socket; "
                      "error [%d: %s].\n",
                   __FUNCTION__, (int)layer, optID,
                   tcpSocket->genericErrno,
-                  Err_Errno2String(tcpSocket->genericErrno)));
+                  Err_Errno2String(tcpSocket->genericErrno));
       return ASOCKERR_GENERIC;
    }
 
    TCPSOCKLG0(tcpSocket,
-              ("%s: Option layer/level [%d], option/name [%d]: successfully "
+              "%s: Option layer/level [%d], option/name [%d]: successfully "
                   "got OS option for TCP socket.\n",
-               __FUNCTION__, (int)layer, optID));
+               __FUNCTION__, (int)layer, optID);
 
    return ASOCKERR_SUCCESS;
 }
index df5e1017085a1a186562e10de4c2a129a1f7e435..b93098c1466c15cd35be9a8ce4b06ba90cb81d1a 100644 (file)
@@ -56,6 +56,7 @@
 #endif
 
 #include "includeCheck.h"
+#include "log.h"
 
 #if defined(__cplusplus)
 extern "C" {
@@ -755,28 +756,40 @@ unsigned AsyncSocket_WebSocketGetNumAccepted(AsyncSocket *asock);
  */
 #define ASOCKPREFIX "SOCKET "
 
-#define ASOCKWARN(_asock, _warnargs)                                 \
-   do {                                                              \
-      Warning(ASOCKPREFIX "%d (%d) ",                                \
-              AsyncSocket_GetID(_asock), AsyncSocket_GetFd(_asock)); \
-      Warning _warnargs;                                             \
+#define ASOCKWARN(_asock, ...)                   \
+   do {                                          \
+      void *acc = Log_BufBegin();                \
+                                                 \
+      Log_BufAppend(acc, ASOCKPREFIX "%d (%d) ", \
+                    AsyncSocket_GetID(_asock),   \
+                    AsyncSocket_GetFd(_asock));  \
+      Log_BufAppend(acc, __VA_ARGS__);           \
+      Log_BufEndLevel(acc, VMW_LOG_WARNING);     \
    } while (0)
 
-#define ASOCKLG0(_asock, _logargs)                               \
-   do {                                                          \
-      Log(ASOCKPREFIX "%d (%d) ",                                \
-          AsyncSocket_GetID(_asock), AsyncSocket_GetFd(_asock)); \
-      Log _logargs;                                              \
+#define ASOCKLG0(_asock, ...)                    \
+   do {                                          \
+      void *acc = Log_BufBegin();                \
+                                                 \
+      Log_BufAppend(acc, ASOCKPREFIX "%d (%d) ", \
+                    AsyncSocket_GetID(_asock),   \
+                    AsyncSocket_GetFd(_asock));  \
+      Log_BufAppend(acc, __VA_ARGS__);           \
+      Log_BufEndLevel(acc, VMW_LOG_INFO);        \
    } while (0)
 
-#define ASOCKLOG(_level, _asock, _logargs)                            \
-   do {                                                               \
-      if (((_level) == 0) || DOLOG_BYNAME(asyncsocket, (_level))) {   \
-         Log(ASOCKPREFIX "%d (%d) ",                                  \
-             AsyncSocket_GetID((_asock)), AsyncSocket_GetFd(_asock)); \
-         Log _logargs;                                                \
-      }                                                               \
-   } while(0)
+#define ASOCKLOG(_level, _asock, ...)                               \
+   do {                                                             \
+      if (((_level) == 0) || DOLOG_BYNAME(asyncsocket, (_level))) { \
+         void *acc = Log_BufBegin();                                \
+                                                                    \
+         Log_BufAppend(acc, ASOCKPREFIX "%d (%d) ",                 \
+                       AsyncSocket_GetID(_asock),                   \
+                       AsyncSocket_GetFd(_asock));                  \
+         Log_BufAppend(acc, __VA_ARGS__);                           \
+         Log_BufEndLevel(acc, VMW_LOG_INFO);                        \
+      }                                                             \
+   } while (0)
 
 #if defined(__cplusplus)
 }  // extern "C"
index fd5c107abf23abf5f1704e3a8017361a14cfc945..948c8e842b5b171d1aee898540c74af2797aee39 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2008-2016,2019 VMware, Inc. All rights reserved.
+ * Copyright (C) 2008-2019 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -29,6 +29,9 @@
 #include <ctype.h>
 #include "str.h"
 #include "log.h"
+#include "util.h"
+#include "dynbuf.h"
+#include "strutil.h"
 
 
 /*
@@ -36,8 +39,8 @@
  * bora/lib/install, that provide implementations for only some of
  * the functions of the real library, but not all.
  */
-#if !defined(NO_LOG_STUB)
 
+#if !defined(NO_LOG_STUB)
 void
 LogV(uint32 unused,
      const char *fmt,
@@ -117,6 +120,100 @@ Log_HexDump(const char *prefix,  // IN: prefix for each log line
    Log_HexDumpLevel(VMW_LOG_INFO, prefix, data, size);
 }
 
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * Log_BufBegin --
+ *
+ *      Obtain a line accumulator.
+ *
+ * Results:
+ *      A pointer to the line accumulator, a DynBuf.
+ *
+ * Side effects:
+ *      None.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+void *
+Log_BufBegin(void)
+{
+   DynBuf *b = Util_SafeCalloc(1, sizeof *b);
+
+   DynBuf_Init(b);
+
+   return b;
+}
+
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * Log_BufAppend --
+ *
+ *      Append data to the specified line accumulator.
+ *
+ * Results:
+ *      None.
+ *
+ * Side effects:
+ *      None.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+void
+Log_BufAppend(void *acc,        // IN/OUT:
+              const char *fmt,  // IN:
+              ...)              // IN/OUT:
+{
+   va_list args;
+   Bool success;
+
+   ASSERT(acc != NULL);
+   ASSERT(fmt != NULL);
+
+   va_start(args, fmt);
+   success = StrUtil_VDynBufPrintf((DynBuf *) acc, fmt, args);
+   va_end(args);
+
+   VERIFY(success);
+}
+
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * Log_BufEndLevel --
+ *
+ *      Issue the contents of the specified line accumulator to the Log
+ *      Facility using the specified routing information.
+ *
+ *      The line accumulator is destroyed.
+ *
+ * Results:
+ *      None.
+ *
+ * Side effects:
+ *      None.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+void
+Log_BufEndLevel(void *acc,       // IN/OUT:
+                uint32 routing)  // IN:
+{
+   ASSERT(acc != NULL);
+
+   Log_Level(routing, "%s", (char *) DynBuf_GetString((DynBuf *) acc));
+
+   DynBuf_Destroy((DynBuf *) acc);
+   free(acc);
+}
+
 #endif
 
 
index 82c232286e3bf12a79b4f3d1d05a4ab9fb8cc997..7bc4a0db7138192337fca87e63d936530a917121 100644 (file)
@@ -52,6 +52,9 @@
 #  include "windowsu.h"
 #endif
 #include "str.h"
+#include "util.h"
+#include "dynbuf.h"
+#include "strutil.h"
 #include "system.h"
 #include "vmware/tools/log.h"
 #include "vmware/tools/guestrpc.h"
@@ -2193,6 +2196,129 @@ LogV(uint32 routing,
    WITH_ERRNO(err, VMToolsLogWrapper(glevel, fmt, args));
 }
 
+/*
+ *----------------------------------------------------------------------
+ *
+ * Log_Level --
+ *
+ *   Write a message via a printf style string and arguments using the
+ *   specified routing.
+ *
+ * Results:
+ *   None
+ *
+ * Side effects:
+ *   The log is written
+ *
+ *----------------------------------------------------------------------
+ */
+
+void
+Log_Level(uint32 routing,   // IN:
+          const char *fmt,  // IN:
+          ...)              // IN or OUT: depends on 'fmt'
+{
+   va_list ap;
+
+   va_start(ap, fmt);
+   LogV(routing, fmt, ap);
+   va_end(ap);
+}
+
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * Log_BufBegin --
+ *
+ *      Obtain a line accumulator.
+ *
+ * Results:
+ *      A pointer to the line accumulator, a DynBuf.
+ *
+ * Side effects:
+ *      None.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+void *
+Log_BufBegin(void)
+{
+   DynBuf *b = Util_SafeCalloc(1, sizeof *b);
+
+   DynBuf_Init(b);
+
+   return b;
+}
+
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * Log_BufAppend --
+ *
+ *      Append data to the specified line accumulator.
+ *
+ * Results:
+ *      None.
+ *
+ * Side effects:
+ *      None.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+void
+Log_BufAppend(void *acc,        // IN/OUT:
+              const char *fmt,  // IN:
+              ...)              // IN/OUT:
+{
+   va_list args;
+   Bool success;
+
+   ASSERT(acc != NULL);
+   ASSERT(fmt != NULL);
+
+   va_start(args, fmt);
+   success = StrUtil_VDynBufPrintf((DynBuf *) acc, fmt, args);
+   va_end(args);
+
+   VERIFY(success);
+}
+
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * Log_BufEndLevel --
+ *
+ *      Issue the contents of the specified line accumulator to the Log
+ *      Facility using the specified routing information.
+ *
+ *      The line accumulator is destroyed.
+ *
+ * Results:
+ *      None.
+ *
+ * Side effects:
+ *      None.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+void
+Log_BufEndLevel(void *acc,       // IN/OUT:
+                uint32 routing)  // IN:
+{
+   ASSERT(acc != NULL);
+
+   Log_Level(routing, "%s", (char *) DynBuf_GetString((DynBuf *) acc));
+
+   DynBuf_Destroy((DynBuf *) acc);
+}
+
+
 
 /*
  *******************************************************************************