From: VMware, Inc <> Date: Wed, 18 Sep 2013 03:38:24 +0000 (-0700) Subject: Change glib logging in RpcChannel to use Debug/Warning/Panic. X-Git-Tag: 2013.09.16-1328054~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac4e72c01eec5565d3ac8d0c84cb4072d9e3e08e;p=thirdparty%2Fopen-vm-tools.git Change glib logging in RpcChannel to use Debug/Warning/Panic. Change glib logging in RpcChannel to use Debug/Warning/Panic so RpcChannel logging can be controlled by different logging stubs in different applications(rpctool/vgauth/toolsd etc). Signed-off-by: Dmitry Torokhov --- diff --git a/open-vm-tools/lib/rpcChannel/bdoorChannel.c b/open-vm-tools/lib/rpcChannel/bdoorChannel.c index c709c53d0..edc2866d2 100644 --- a/open-vm-tools/lib/rpcChannel/bdoorChannel.c +++ b/open-vm-tools/lib/rpcChannel/bdoorChannel.c @@ -28,6 +28,7 @@ #include "rpcin.h" #include "rpcout.h" #include "util.h" +#include "debug.h" typedef struct BackdoorChannel { RpcOut *out; @@ -162,13 +163,13 @@ BkdoorChannelSend(RpcChannel *chan, */ if (!ret && reply != NULL && replyLen > sizeof "RpcOut: " && g_str_has_prefix(reply, "RpcOut: ")) { - g_debug("RpcOut failure, restarting channel.\n"); + Debug("RpcOut failure, restarting channel.\n"); RpcOut_stop(bdoor->out); if (RpcOut_start(bdoor->out)) { ret = RpcOut_send(bdoor->out, data, dataLen, &reply, &replyLen); } else { - g_warning("Couldn't restart RpcOut channel; bad things may happen " - "until the RPC channel is reset.\n"); + Warning("Couldn't restart RpcOut channel; bad things may happen " + "until the RPC channel is reset.\n"); chan->outStarted = FALSE; } } diff --git a/open-vm-tools/lib/rpcChannel/rpcChannel.c b/open-vm-tools/lib/rpcChannel/rpcChannel.c index fc39540fb..b775813c6 100644 --- a/open-vm-tools/lib/rpcChannel/rpcChannel.c +++ b/open-vm-tools/lib/rpcChannel/rpcChannel.c @@ -31,6 +31,7 @@ #include "vmxrpc.h" #include "xdrutil.h" #include "rpcin.h" +#include "debug.h" /** Internal state of a channel. */ typedef struct RpcChannelInt { @@ -90,7 +91,7 @@ RpcChannelRestart(gpointer _chan) RpcChannel_Stop(&chan->impl); if (!RpcChannel_Start(&chan->impl)) { - g_warning("Channel restart failed [%d]\n", chan->rpcErrorCount); + Warning("Channel restart failed [%d]\n", chan->rpcErrorCount); if (chan->resetCb != NULL) { chan->resetCb(&chan->impl, FALSE, chan->resetData); } @@ -122,8 +123,8 @@ RpcChannelCheckReset(gpointer _chan) GSource *src; if (++(chan->rpcErrorCount) > channelTimeoutAttempts) { - g_warning("Failed to reset channel after %u attempts\n", - chan->rpcErrorCount - 1); + Warning("Failed to reset channel after %u attempts\n", + chan->rpcErrorCount - 1); if (chan->resetCb != NULL) { chan->resetCb(&chan->impl, FALSE, chan->resetData); } @@ -131,7 +132,7 @@ RpcChannelCheckReset(gpointer _chan) } /* Schedule the channel restart for 1 sec in the future. */ - g_debug("Resetting channel [%u]\n", chan->rpcErrorCount); + Debug("Resetting channel [%u]\n", chan->rpcErrorCount); src = g_timeout_source_new(1000); g_source_set_callback(src, RpcChannelRestart, chan, NULL); g_source_attach(src, chan->mainCtx); @@ -140,7 +141,7 @@ RpcChannelCheckReset(gpointer _chan) } /* Reset was successful. */ - g_debug("Channel was reset successfully.\n"); + Debug("Channel was reset successfully.\n"); chan->rpcErrorCount = 0; if (chan->resetCb != NULL) { @@ -463,9 +464,9 @@ RpcChannel_Error(void *_chan, chan->rpcError = TRUE; /* * XXX: Workaround for PR 935520. - * Revert the log call to g_warning() after fixing PR 955746. + * Revert the log call to Warning() after fixing PR 955746. */ - g_debug("Error in the RPC receive loop: %s.\n", status); + Debug("Error in the RPC receive loop: %s.\n", status); if (chan->resetCheck == NULL) { chan->resetCheck = g_idle_source_new(); @@ -601,7 +602,7 @@ RpcChannel_RegisterCallback(RpcChannel *chan, cdata->rpcs = g_hash_table_new(g_str_hash, g_str_equal); } if (g_hash_table_lookup(cdata->rpcs, rpc->name) != NULL) { - g_error("Trying to overwrite existing RPC registration for %s!\n", rpc->name); + Panic("Trying to overwrite existing RPC registration for %s!\n", rpc->name); } g_hash_table_insert(cdata->rpcs, (gpointer) rpc->name, rpc); } @@ -716,7 +717,7 @@ RpcChannel_Start(RpcChannel *chan) ok = funcs->start(chan); if (!ok && funcs->onStartErr != NULL) { - g_warning(LGPFX "Fallback to backdoor ...\n"); + Warning(LGPFX "Fallback to backdoor ...\n"); funcs->onStartErr(chan); ok = BackdoorChannel_Fallback(chan); } @@ -795,7 +796,7 @@ RpcChannel_Send(RpcChannel *chan, size_t resLen = 0; const RpcChannelFuncs *funcs; - g_debug(LGPFX "Sending: %"FMTSZ"u bytes\n", dataLen); + Debug(LGPFX "Sending: %"FMTSZ"u bytes\n", dataLen); ASSERT(chan && chan->funcs); @@ -821,7 +822,7 @@ RpcChannel_Send(RpcChannel *chan, resLen = 0; /* retry once */ - g_debug(LGPFX "Stop RpcOut channel and try to send again ...\n"); + Debug(LGPFX "Stop RpcOut channel and try to send again ...\n"); funcs->stopRpcOut(chan); if (RpcChannel_Start(chan)) { /* The channel may get switched from vsocket to backdoor */ @@ -837,7 +838,7 @@ RpcChannel_Send(RpcChannel *chan, done: if (ok) { - g_debug(LGPFX "Recved %"FMTSZ"u bytes\n", resLen); + Debug(LGPFX "Recved %"FMTSZ"u bytes\n", resLen); } if (result != NULL) { @@ -903,8 +904,8 @@ RpcChannel_SendOneRaw(const char *data, status = TRUE; sent: - g_debug(LGPFX "Request %s: reqlen=%"FMTSZ"u, replyLen=%"FMTSZ"u\n", - status ? "OK" : "FAILED", dataLen, resultLen ? *resultLen : 0); + Debug(LGPFX "Request %s: reqlen=%"FMTSZ"u, replyLen=%"FMTSZ"u\n", + status ? "OK" : "FAILED", dataLen, resultLen ? *resultLen : 0); if (chan) { RpcChannel_Stop(chan); RpcChannel_Destroy(chan); diff --git a/open-vm-tools/lib/rpcChannel/simpleSocket.c b/open-vm-tools/lib/rpcChannel/simpleSocket.c index a99d2726a..c47b7e269 100644 --- a/open-vm-tools/lib/rpcChannel/simpleSocket.c +++ b/open-vm-tools/lib/rpcChannel/simpleSocket.c @@ -33,6 +33,7 @@ #include "vmci_sockets.h" #include "dataMap.h" #include "err.h" +#include "debug.h" #define LGPFX "SimpleSock: " @@ -65,14 +66,14 @@ SocketStartup(void) err = WSAStartup(MAKEWORD(2, 0), &wsaData); if (err) { - g_warning(LGPFX "Error in WSAStartup: %d[%s]\n", err, - Err_Errno2String(err)); + Warning(LGPFX "Error in WSAStartup: %d[%s]\n", err, + Err_Errno2String(err)); return FALSE; } if (2 != LOBYTE(wsaData.wVersion) || 0 != HIBYTE(wsaData.wVersion)) { - g_warning(LGPFX "Unsupported Winsock version %d.%d\n", - LOBYTE(wsaData.wVersion), HIBYTE(wsaData.wVersion)); + Warning(LGPFX "Unsupported Winsock version %d.%d\n", + LOBYTE(wsaData.wVersion), HIBYTE(wsaData.wVersion)); return FALSE; } #endif @@ -103,8 +104,8 @@ SocketCleanup(void) #if defined(_WIN32) int err = WSACleanup(); if (err) { - g_warning(LGPFX "Error in WSACleanup: %d[%s]\n", err, - Err_Errno2String(err)); + Warning(LGPFX "Error in WSACleanup: %d[%s]\n", err, + Err_Errno2String(err)); return FALSE; } #endif @@ -141,8 +142,8 @@ Socket_Close(SOCKET sock) if (res == SOCKET_ERROR) { int err = SocketGetLastError(); - g_warning(LGPFX "Error in closing socket %d: %d[%s]\n", - sock, err, Err_Errno2String(err)); + Warning(LGPFX "Error in closing socket %d: %d[%s]\n", + sock, err, Err_Errno2String(err)); } SocketCleanup(); @@ -204,7 +205,7 @@ Socket_Recv(SOCKET fd, // IN while (remaining > 0) { rv = recv(fd, buf , remaining, 0); if (rv == 0) { - g_warning(LGPFX "Socket %d closed by peer.", fd); + Warning(LGPFX "Socket %d closed by peer.", fd); return FALSE; } if (rv == SOCKET_ERROR) { @@ -212,15 +213,15 @@ Socket_Recv(SOCKET fd, // IN if (sysErr == SYSERR_EINTR) { continue; } - g_warning(LGPFX "Recv error for socket %d: %d[%s]", fd, sysErr, - Err_Errno2String(sysErr)); + Warning(LGPFX "Recv error for socket %d: %d[%s]", fd, sysErr, + Err_Errno2String(sysErr)); return FALSE; } remaining -= rv; buf += rv; } - g_debug(LGPFX "Recved %d bytes from socket %d\n", len, fd); + Debug(LGPFX "Recved %d bytes from socket %d\n", len, fd); return TRUE; } @@ -258,15 +259,15 @@ Socket_Send(SOCKET fd, // IN if (sysErr == SYSERR_EINTR) { continue; } - g_warning(LGPFX "Send error for socket %d: %d[%s]", fd, sysErr, - Err_Errno2String(sysErr)); + Warning(LGPFX "Send error for socket %d: %d[%s]", fd, sysErr, + Err_Errno2String(sysErr)); return FALSE; } left -= rv; sent += rv; } - g_debug(LGPFX "Sent %d bytes from socket %d\n", len, fd); + Debug(LGPFX "Sent %d bytes from socket %d\n", len, fd); return TRUE; } @@ -312,7 +313,7 @@ Socket_ConnectVMCI(unsigned int cid, // IN } if (family == -1) { - g_warning(LGPFX "Couldn't get VMCI socket family info."); + Warning(LGPFX "Couldn't get VMCI socket family info."); goto error; } @@ -321,13 +322,13 @@ Socket_ConnectVMCI(unsigned int cid, // IN addr.svm_cid = cid; addr.svm_port = port; - g_debug(LGPFX "creating new socket, connecting to %u:%u\n", cid, port); + Debug(LGPFX "creating new socket, connecting to %u:%u\n", cid, port); fd = socket(addr.svm_family, SOCK_STREAM, 0); if (fd == INVALID_SOCKET) { sysErr = SocketGetLastError(); - g_warning(LGPFX "failed to create socket, error %d: %s\n", - sysErr, Err_Errno2String(sysErr)); + Warning(LGPFX "failed to create socket, error %d: %s\n", + sysErr, Err_Errno2String(sysErr)); goto error; } @@ -349,8 +350,8 @@ Socket_ConnectVMCI(unsigned int cid, // IN if (bind(fd, (struct sockaddr *)&localAddr, sizeof localAddr) != 0) { sysErr = SocketGetLastError(); if (sysErr == SYSERR_EACCESS) { - g_warning(LGPFX "Couldn't bind to privileged port for " - "socket %d\n", fd); + Warning(LGPFX "Couldn't bind to privileged port for " + "socket %d\n", fd); error = SOCKERR_EACCESS; Socket_Close(fd); goto error; @@ -358,8 +359,8 @@ Socket_ConnectVMCI(unsigned int cid, // IN if (sysErr == SYSERR_EADDRINUSE) { continue; } - g_warning(LGPFX "could not bind socket, error %d: %s\n", sysErr, - Err_Errno2String(sysErr)); + Warning(LGPFX "could not bind socket, error %d: %s\n", sysErr, + Err_Errno2String(sysErr)); Socket_Close(fd); error = SOCKERR_BIND; goto error; @@ -370,28 +371,28 @@ Socket_ConnectVMCI(unsigned int cid, // IN } if (!bindOk) { - g_warning(LGPFX "Failed to bind to privileged port for socket %d, " - "no port available\n", fd); + Warning(LGPFX "Failed to bind to privileged port for socket %d, " + "no port available\n", fd); error = SOCKERR_BIND; Socket_Close(fd); goto error; } else { - g_debug(LGPFX "Successfully bound to port %d for socket %d\n", - localAddr.svm_port, fd); + Debug(LGPFX "Successfully bound to port %d for socket %d\n", + localAddr.svm_port, fd); } } if (connect(fd, (struct sockaddr *)&addr, addrLen) != 0) { sysErr = SocketGetLastError(); - g_warning(LGPFX "socket connect failed, error %d: %s\n", - sysErr, Err_Errno2String(sysErr)); + Warning(LGPFX "socket connect failed, error %d: %s\n", + sysErr, Err_Errno2String(sysErr)); Socket_Close(fd); error = SOCKERR_CONNECT; goto error; } VMCISock_ReleaseAFValueFd(vsockDev); - g_debug(LGPFX "socket %d connected\n", fd); + Debug(LGPFX "socket %d connected\n", fd); return fd; error: @@ -437,7 +438,7 @@ Socket_DecodePacket(const char *recvBuf, // IN /* decoding the packet */ res = DataMap_Deserialize(recvBuf, fullPktLen, &map); if (res != DMERR_SUCCESS) { - g_debug(LGPFX "Error in dataMap decoding, error=%d\n", res); + Debug(LGPFX "Error in dataMap decoding, error=%d\n", res); return FALSE; } @@ -445,7 +446,7 @@ Socket_DecodePacket(const char *recvBuf, // IN if (res == DMERR_SUCCESS) { char *tmpPtr = malloc(len + 1); if (tmpPtr == NULL) { - g_debug(LGPFX "Error in allocating memory\n"); + Debug(LGPFX "Error in allocating memory\n"); goto error; } memcpy(tmpPtr, buf, len); @@ -455,7 +456,7 @@ Socket_DecodePacket(const char *recvBuf, // IN *payload = tmpPtr; *payloadLen = len; } else { - g_debug(LGPFX "Error in decoding payload, error=%d\n", res); + Debug(LGPFX "Error in decoding payload, error=%d\n", res); goto error; } @@ -510,7 +511,7 @@ Socket_PackSendData(const char *buf, // IN newBuf = malloc(len); if (newBuf == NULL) { - g_debug(LGPFX "Error in allocating memory.\n"); + Debug(LGPFX "Error in allocating memory.\n"); goto error; } memcpy(newBuf, buf, len); @@ -533,7 +534,7 @@ error: if (mapCreated) { DataMap_Destroy(&map); } - g_debug(LGPFX "Error in dataMap encoding\n"); + Debug(LGPFX "Error in dataMap encoding\n"); return FALSE; } @@ -569,8 +570,8 @@ Socket_RecvPacket(SOCKET sock, // IN ok = Socket_Recv(sock, (char *)&packetLen, packetLenSize); if (!ok) { - g_debug(LGPFX "error in recving packet header, err=%d\n", - SocketGetLastError()); + Debug(LGPFX "error in recving packet header, err=%d\n", + SocketGetLastError()); return FALSE; } @@ -578,7 +579,7 @@ Socket_RecvPacket(SOCKET sock, // IN recvBufLen = fullPktLen; recvBuf = malloc(recvBufLen); if (recvBuf == NULL) { - g_debug(LGPFX "Could not allocate recv buffer.\n"); + Debug(LGPFX "Could not allocate recv buffer.\n"); return FALSE; } @@ -586,8 +587,8 @@ Socket_RecvPacket(SOCKET sock, // IN ok = Socket_Recv(sock, recvBuf + packetLenSize, fullPktLen - packetLenSize); if (!ok) { - g_debug(LGPFX "error in recving packet, err=%d\n", - SocketGetLastError()); + Debug(LGPFX "error in recving packet, err=%d\n", + SocketGetLastError()); free(recvBuf); return FALSE; } diff --git a/open-vm-tools/lib/rpcChannel/vsockChannel.c b/open-vm-tools/lib/rpcChannel/vsockChannel.c index 0c5cf37d2..2a0bcacf4 100644 --- a/open-vm-tools/lib/rpcChannel/vsockChannel.c +++ b/open-vm-tools/lib/rpcChannel/vsockChannel.c @@ -30,6 +30,7 @@ #include "rpcChannelInt.h" #include "rpcin.h" #include "util.h" +#include "debug.h" #define LGPFX "VSockChan: " @@ -70,30 +71,30 @@ VSockCreateConn(gboolean *isPriv) // OUT SockConnError err; SOCKET fd; - g_debug(LGPFX "Creating privileged vsocket ...\n"); + Debug(LGPFX "Creating privileged vsocket ...\n"); fd = Socket_ConnectVMCI(VMCI_HYPERVISOR_CONTEXT_ID, GUESTRPC_RPCI_VSOCK_LISTEN_PORT, TRUE, &err); if (fd != INVALID_SOCKET) { - g_debug(LGPFX "Successfully created priv vsocket %d\n", fd); + Debug(LGPFX "Successfully created priv vsocket %d\n", fd); *isPriv = TRUE; return fd; } if (err == SOCKERR_EACCESS) { - g_debug(LGPFX "Creating unprivileged vsocket ...\n"); + Debug(LGPFX "Creating unprivileged vsocket ...\n"); fd = Socket_ConnectVMCI(VMCI_HYPERVISOR_CONTEXT_ID, GUESTRPC_RPCI_VSOCK_LISTEN_PORT, FALSE, &err); if (fd != INVALID_SOCKET) { - g_debug(LGPFX "Successfully created unpriv vsocket %d\n", fd); + Debug(LGPFX "Successfully created unpriv vsocket %d\n", fd); *isPriv = FALSE; return fd; } } - g_warning(LGPFX "Failed to create vsocket channel, err=%d\n", err); + Warning(LGPFX "Failed to create vsocket channel, err=%d\n", err); return INVALID_SOCKET; } @@ -252,8 +253,8 @@ VSockOutSend(VSockOut *out, // IN *reply = NULL; *repLen = 0; - g_debug(LGPFX "Sending request for conn %d, reqLen=%d\n", - out->fd, (int)reqLen); + Debug(LGPFX "Sending request for conn %d, reqLen=%d\n", + out->fd, (int)reqLen); if (!Socket_SendPacket(out->fd, request, reqLen)) { *reply = "VSockOut: Unable to send data for the RPCI command"; @@ -278,7 +279,7 @@ VSockOutSend(VSockOut *out, // IN *reply = out->payload + 2; *repLen = out->payloadLen - 2; - g_debug("VSockOut: recved %d bytes for conn %d\n", out->payloadLen, out->fd); + Debug("VSockOut: recved %d bytes for conn %d\n", out->payloadLen, out->fd); return out->payload[0] == '1';