ID:355 - Replace DEBUG() macro with lprintf(LOG_DEBUG, ...)

Commit replaces parametric macro DEBUG() in insrc/plugins/imb/imbapi.c.
This commit is contained in:
Zdenek Styblik 2016-06-05 14:00:56 +02:00
parent 2153bd7aa3
commit 0fdfbce8b6

View File

@ -60,6 +60,7 @@
#include "imbapi.h" #include "imbapi.h"
#include <sys/socket.h> #include <sys/socket.h>
#include <ipmitool/log.h>
#ifdef SCO_UW #ifdef SCO_UW
# define NO_MACRO_ARGS 1 # define NO_MACRO_ARGS 1
@ -77,15 +78,6 @@
# define _SC_PAGESIZE _SC_PAGE_SIZE # define _SC_PAGESIZE _SC_PAGE_SIZE
#endif #endif
/* Just to make the DEBUG code cleaner. */
#ifndef NO_MACRO_ARGS
# ifdef LINUX_DEBUG
# define DEBUG(format, args...) printf(format, ##args)
# else
# define DEBUG(format, args...)
# endif
#endif
HANDLE AsyncEventHandle = 0; HANDLE AsyncEventHandle = 0;
static int IpmiVersion; static int IpmiVersion;
@ -178,9 +170,7 @@ open_imb(void)
if (hDevice1 != 0) { if (hDevice1 != 0) {
return 1; return 1;
} }
# ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "%s: opening the driver", __FUNCTION__);
DEBUG("%s: opening the driver\n", __FUNCTION__);
# endif
/* printf("open_imb: " /* printf("open_imb: "
"IOCTL_IMB_SEND_MESSAGE =%x \n" "IOCTL_IMB_GET_ASYNC_MSG=%x \n" "IOCTL_IMB_SEND_MESSAGE =%x \n" "IOCTL_IMB_GET_ASYNC_MSG=%x \n"
"IOCTL_IMB_MAP_MEMORY = %x \n" "IOCTL_IMB_UNMAP_MEMORY= %x \n" "IOCTL_IMB_MAP_MEMORY = %x \n" "IOCTL_IMB_UNMAP_MEMORY= %x \n"
@ -222,9 +212,7 @@ open_imb(void)
requestData.data = NULL; requestData.data = NULL;
requestData.dataLength = 0; requestData.dataLength = 0;
respLength = 16; respLength = 16;
# ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "%s: opened driver, getting IPMI version", __FUNCTION__);
DEBUG("%s: opened driver, getting IPMI version\n", __FUNCTION__);
# endif
if (((my_ret_code = SendTimedImbpRequest(&requestData, (DWORD)400, if (((my_ret_code = SendTimedImbpRequest(&requestData, (DWORD)400,
respBuffer, respBuffer,
(int *)&respLength, (int *)&respLength,
@ -245,9 +233,8 @@ open_imb(void)
IpmiVersion = IPMI_10_VERSION; IpmiVersion = IPMI_10_VERSION;
} }
} }
# ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "%s: IPMI version 0x%x", __FUNCTION__,
DEBUG("%s: IPMI version 0x%x\n", __FUNCTION__, IpmiVersion); IpmiVersion);
# endif
return 1; return 1;
} /* end open_imb() */ } /* end open_imb() */
#endif #endif
@ -311,10 +298,10 @@ DeviceIoControl(HANDLE dummey_hDevice, DWORD dwIoControlCode, LPVOID
if (rc == 0) { if (rc == 0) {
return FALSE; return FALSE;
} }
#ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "%s: ioctl cmd = 0x%lx", __FUNCTION__,
DEBUG("%s: ioctl cmd = 0x%lx ", __FUNCTION__, dwIoControlCode); dwIoControlCode);
DEBUG("cbInBuffer %d cbOutBuffer %d\n", cbInBuffer, cbOutBuffer); lprintf(LOG_DEBUG, "cbInBuffer %d cbOutBuffer %d", cbInBuffer,
#endif cbOutBuffer);
if (cbInBuffer > 41) { if (cbInBuffer > 41) {
cbInBuffer = 41; /* Intel driver max buf */ cbInBuffer = 41; /* Intel driver max buf */
} }
@ -331,26 +318,17 @@ DeviceIoControl(HANDLE dummey_hDevice, DWORD dwIoControlCode, LPVOID
s.ntstatus = (LPVOID)&NTstatus; s.ntstatus = (LPVOID)&NTstatus;
if ((ioctl_status = ioctl(hDevice1, dwIoControlCode,&s)) < 0) { if ((ioctl_status = ioctl(hDevice1, dwIoControlCode,&s)) < 0) {
#ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "%s %s: ioctl cmd = 0x%x failed",
DEBUG("%s %s: ioctl cmd = 0x%x failed",
__FILE__, __FUNCTION__, dwIoControlCode); __FILE__, __FUNCTION__, dwIoControlCode);
#endif
return FALSE; return FALSE;
} }
#ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "%s: ioctl_status %d bytes returned = %d",
DEBUG("%s: ioctl_status %d bytes returned = %d \n",
__FUNCTION__, ioctl_status, *lpcbBytesReturned); __FUNCTION__, ioctl_status, *lpcbBytesReturned);
#endif
if (ioctl_status == STATUS_SUCCESS) { if (ioctl_status == STATUS_SUCCESS) {
#ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "%s returning true", __FUNCTION__);
DEBUG("%s returning true\n", __FUNCTION__);
#endif
return (TRUE); return (TRUE);
} else { } else {
#ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "%s returning false", __FUNCTION__);
DEBUG("%s returning false\n", __FUNCTION__);
#endif
return (FALSE); return (FALSE);
} }
} }
@ -362,16 +340,14 @@ StartAsyncMesgPoll()
{ {
DWORD retLength; DWORD retLength;
BOOL status; BOOL status;
#ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "%s: DeviceIoControl cmd = %x",
DEBUG("%s: DeviceIoControl cmd = %x\n",
__FUNCTION__, IOCTL_IMB_POLL_ASYNC); __FUNCTION__, IOCTL_IMB_POLL_ASYNC);
#endif
status = DeviceIoControl(hDevice, IOCTL_IMB_POLL_ASYNC, NULL, 0, NULL, status = DeviceIoControl(hDevice, IOCTL_IMB_POLL_ASYNC, NULL, 0, NULL,
0, &retLength, 0); 0, &retLength, 0);
#ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __FUNCTION__,
DEBUG("%s: DeviceIoControl status = %d\n", __FUNCTION__, status); status);
#endif
if (status == TRUE) { if (status == TRUE) {
return ACCESN_OK; return ACCESN_OK;
} else { } else {
@ -431,9 +407,8 @@ SendTimedI2cRequest(I2CREQUESTDATA *reqPtr, int timeOut, BYTE *respDataPtr,
status = DeviceIoControl(hDevice, IOCTL_IMB_SEND_MESSAGE, requestData, status = DeviceIoControl(hDevice, IOCTL_IMB_SEND_MESSAGE, requestData,
sizeof(requestData), &responseData, sizeof(requestData), &responseData,
sizeof(responseData), &respLength, NULL); sizeof(responseData), &respLength, NULL);
#ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __FUNCTION__,
DEBUG("%s: DeviceIoControl status = %d\n", __FUNCTION__, status); status);
#endif
if (status != TRUE) { if (status != TRUE) {
DWORD error; DWORD error;
error = GetLastError(); error = GetLastError();
@ -523,9 +498,8 @@ SendTimedEmpMessageResponse (ImbPacket *ptr, char *responseDataBuf,
status = DeviceIoControl(hDevice, IOCTL_IMB_SEND_MESSAGE, requestData, status = DeviceIoControl(hDevice, IOCTL_IMB_SEND_MESSAGE, requestData,
sizeof(requestData), responseData, sizeof(responseData), sizeof(requestData), responseData, sizeof(responseData),
&respLength, NULL); &respLength, NULL);
#ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __FUNCTION__,
DEBUG("%s: DeviceIoControl status = %d\n", __FUNCTION__, status); status);
#endif
if ((status != TRUE) || (respLength != 1) || (responseData[0] != 0)) { if ((status != TRUE) || (respLength != 1) || (responseData[0] != 0)) {
return ACCESN_ERROR; return ACCESN_ERROR;
} }
@ -652,9 +626,8 @@ SendTimedEmpMessageResponse_Ex (ImbPacket *ptr, char *responseDataBuf, int
sizeof(requestData), responseData, sizeof(responseData), sizeof(requestData), responseData, sizeof(responseData),
&respLength, NULL); &respLength, NULL);
#ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __FUNCTION__,
DEBUG("%s: DeviceIoControl status = %d\n", __FUNCTION__, status); status);
#endif
if ((status != TRUE) || (respLength != 1) || (responseData[0] != 0)) { if ((status != TRUE) || (respLength != 1) || (responseData[0] != 0)) {
return ACCESN_ERROR; return ACCESN_ERROR;
} }
@ -738,9 +711,8 @@ SendTimedLanMessageResponse(ImbPacket *ptr, char *responseDataBuf,
sizeof(requestData), responseData, sizeof(responseData), sizeof(requestData), responseData, sizeof(responseData),
&respLength, NULL); &respLength, NULL);
#ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __FUNCTION__,
DEBUG("%s: DeviceIoControl status = %d\n", __FUNCTION__, status); status);
#endif
if ((status != TRUE) || (respLength != 1) || (responseData[0] != 0)) { if ((status != TRUE) || (respLength != 1) || (responseData[0] != 0)) {
return ACCESN_ERROR; return ACCESN_ERROR;
} }
@ -867,9 +839,8 @@ SendTimedLanMessageResponse_Ex(ImbPacket *ptr, char *responseDataBuf, int
status = DeviceIoControl(hDevice, IOCTL_IMB_SEND_MESSAGE, requestData, status = DeviceIoControl(hDevice, IOCTL_IMB_SEND_MESSAGE, requestData,
sizeof(requestData), responseData, sizeof(responseData), sizeof(requestData), responseData, sizeof(responseData),
&respLength, NULL); &respLength, NULL);
#ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __FUNCTION__,
DEBUG("%s: DeviceIoControl status = %d\n", __FUNCTION__, status); status);
#endif
if ((status != TRUE) || (respLength != 1) || (responseData[0] != 0)) { if ((status != TRUE) || (respLength != 1) || (responseData[0] != 0)) {
return ACCESN_ERROR; return ACCESN_ERROR;
} }
@ -903,30 +874,25 @@ SendTimedImbpRequest(IMBPREQUESTDATA *reqPtr, int timeOut, BYTE *respDataPtr,
req->req.rsLun = reqPtr->rsLun; req->req.rsLun = reqPtr->rsLun;
req->req.dataLength = reqPtr->dataLength; req->req.dataLength = reqPtr->dataLength;
#ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "cmd=%02x, pdata=%p, datalen=%x", req->req.cmd,
DEBUG("cmd=%02x, pdata=%p, datalen=%x\n", req->req.cmd, reqPtr->data, reqPtr->data, reqPtr->dataLength);
reqPtr->dataLength);
#endif
memcpy(req->req.data, reqPtr->data, reqPtr->dataLength); memcpy(req->req.data, reqPtr->data, reqPtr->dataLength);
req->flags = 0; req->flags = 0;
/* convert to uSec units */ /* convert to uSec units */
req->timeOut = timeOut * 1000; req->timeOut = timeOut * 1000;
#ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "%s: rsSa 0x%x cmd 0x%x netFn 0x%x rsLun 0x%x",
DEBUG("%s: rsSa 0x%x cmd 0x%x netFn 0x%x rsLun 0x%x\n", __FUNCTION__, __FUNCTION__, req->req.rsSa, req->req.cmd,
req->req.rsSa, req->req.cmd, req->req.netFn, req->req.netFn, req->req.rsLun);
req->req.rsLun);
#endif
status = DeviceIoControl(hDevice, IOCTL_IMB_SEND_MESSAGE, requestData, status = DeviceIoControl(hDevice, IOCTL_IMB_SEND_MESSAGE, requestData,
sizeof(requestData), &responseData, sizeof(requestData), &responseData,
sizeof(responseData), &respLength, NULL); sizeof(responseData), &respLength, NULL);
#ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "%s: DeviceIoControl returned status = %d",
DEBUG("%s: DeviceIoControl returned status = %d\n",__FUNCTION__, __FUNCTION__, status);
status);
#endif
#ifdef DBG_IPMI #ifdef DBG_IPMI
/* TODO */
printf("%s: rsSa %x cmd %x netFn %x lun %x, status=%d, cc=%x, rlen=%d\n", printf("%s: rsSa %x cmd %x netFn %x lun %x, status=%d, cc=%x, rlen=%d\n",
__FUNCTION__, req->req.rsSa, req->req.cmd, __FUNCTION__, req->req.rsSa, req->req.cmd,
req->req.netFn, req->req.rsLun, status, resp->cCode, req->req.netFn, req->req.rsLun, status, resp->cCode,
@ -982,10 +948,9 @@ SendAsyncImbpRequest(IMBPREQUESTDATA *reqPtr, BYTE *seqNo)
status = DeviceIoControl(hDevice, IOCTL_IMB_SEND_MESSAGE, requestData, status = DeviceIoControl(hDevice, IOCTL_IMB_SEND_MESSAGE, requestData,
sizeof(requestData), &responseData, sizeof(requestData), &responseData,
sizeof(responseData), &respLength, NULL); sizeof(responseData), &respLength, NULL);
#ifndef NO_MACRO_ARGS
DEBUG("%s: DeviceIoControl status = %d\n", __FUNCTION__, status);
#endif
lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __FUNCTION__,
status);
if (status != TRUE) { if (status != TRUE) {
DWORD error; DWORD error;
error = GetLastError(); error = GetLastError();
@ -1033,11 +998,8 @@ GetAsyncImbpMessage (ImbPacket *msgPtr, DWORD *msgLen, DWORD timeOut,
sizeof(req), &responseData, sizeof(req), &responseData,
sizeof(responseData), &respLength, NULL); sizeof(responseData), &respLength, NULL);
#ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d",
DEBUG("%s: DeviceIoControl status = %d\n", __FUNCTION__, __FUNCTION__, status);
status);
#endif
if (status != TRUE) { if (status != TRUE) {
DWORD error = GetLastError(); DWORD error = GetLastError();
/* handle "msg not available" specially. it is different /* handle "msg not available" specially. it is different
@ -1133,11 +1095,8 @@ GetAsyncImbpMessage_Ex(ImbPacket *msgPtr, DWORD *msgLen, DWORD timeOut,
sizeof(req), &responseData, sizeof(req), &responseData,
sizeof(responseData), &respLength, NULL); sizeof(responseData), &respLength, NULL);
#ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d",
DEBUG("%s: DeviceIoControl status = %d\n", __FUNCTION__, __FUNCTION__, status);
status);
#endif
if (status != TRUE) { if (status != TRUE) {
DWORD error = GetLastError(); DWORD error = GetLastError();
/* handle "msg not available" specially. it is /* handle "msg not available" specially. it is
@ -1235,9 +1194,8 @@ IsAsyncMessageAvailable(unsigned int eventId)
status = DeviceIoControl(hDevice, IOCTL_IMB_CHECK_EVENT, status = DeviceIoControl(hDevice, IOCTL_IMB_CHECK_EVENT,
&AsyncEventHandle, sizeof(HANDLE), &dummy, sizeof(int), &AsyncEventHandle, sizeof(HANDLE), &dummy, sizeof(int),
(LPDWORD)&respLength, NULL); (LPDWORD)&respLength, NULL);
#ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __FUNCTION__,
DEBUG("%s: DeviceIoControl status = %d\n",__FUNCTION__, status); status);
#endif
if (status != TRUE) { if (status != TRUE) {
return ACCESN_ERROR; return ACCESN_ERROR;
} }
@ -1268,19 +1226,15 @@ RegisterForImbAsyncMessageNotification(unsigned int *handleId)
status = DeviceIoControl(hDevice, IOCTL_IMB_REGISTER_ASYNC_OBJ, &dummy, status = DeviceIoControl(hDevice, IOCTL_IMB_REGISTER_ASYNC_OBJ, &dummy,
sizeof(int), &AsyncEventHandle, (DWORD)sizeof(HANDLE), sizeof(int), &AsyncEventHandle, (DWORD)sizeof(HANDLE),
(LPDWORD)&respLength, NULL); (LPDWORD)&respLength, NULL);
#ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __FUNCTION__,
DEBUG("%s: DeviceIoControl status = %d\n", __FUNCTION__, status); status);
#endif
if ((respLength != sizeof(int)) || (status != TRUE)) { if ((respLength != sizeof(int)) || (status != TRUE)) {
return ACCESN_ERROR; return ACCESN_ERROR;
} }
/* printf("imbapi: Register handle = %x\n",AsyncEventHandle); *//*++++*/ /* printf("imbapi: Register handle = %x\n",AsyncEventHandle); *//*++++*/
*handleId = (unsigned int)AsyncEventHandle; *handleId = (unsigned int)AsyncEventHandle;
lprintf(LOG_DEBUG, "handleId = %x AsyncEventHandle %x", *handleId,
#ifndef NO_MACRO_ARGS AsyncEventHandle);
DEBUG("handleId = %x AsyncEventHandle %x\n", *handleId, AsyncEventHandle);
#endif
return ACCESN_OK; return ACCESN_OK;
} }
@ -1311,9 +1265,8 @@ UnRegisterForImbAsyncMessageNotification(unsigned int handleId, int iFlag)
status = DeviceIoControl(hDevice, IOCTL_IMB_DEREGISTER_ASYNC_OBJ, status = DeviceIoControl(hDevice, IOCTL_IMB_DEREGISTER_ASYNC_OBJ,
&AsyncEventHandle, (DWORD)sizeof(HANDLE ), &dummy, &AsyncEventHandle, (DWORD)sizeof(HANDLE ), &dummy,
(DWORD)sizeof(int), (LPDWORD)&respLength, NULL ); (DWORD)sizeof(int), (LPDWORD)&respLength, NULL );
#ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __FUNCTION__,
DEBUG("%s: DeviceIoControl status = %d\n",__FUNCTION__, status); status);
#endif
if (status != TRUE) { if (status != TRUE) {
return ACCESN_ERROR; return ACCESN_ERROR;
} }
@ -1342,9 +1295,8 @@ SetShutDownCode(int delayTime, int code)
cmd.delayTime = delayTime; cmd.delayTime = delayTime;
status = DeviceIoControl(hDevice, IOCTL_IMB_SHUTDOWN_CODE, &cmd, status = DeviceIoControl(hDevice, IOCTL_IMB_SHUTDOWN_CODE, &cmd,
sizeof(cmd), NULL, 0, &retLength, NULL); sizeof(cmd), NULL, 0, &retLength, NULL);
#ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __FUNCTION__,
DEBUG("%s: DeviceIoControl status = %d\n", __FUNCTION__, status); status);
#endif
if (status == TRUE) { if (status == TRUE) {
return ACCESN_OK; return ACCESN_OK;
} else { } else {
@ -1466,9 +1418,8 @@ MapPhysicalMemory(int startAddress, int addressLength, int *virtualAddress)
close(fd); close(fd);
return ACCESN_ERROR; return ACCESN_ERROR;
} }
#ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "%s: mmap of 0x%x success", __FUNCTION__,
DEBUG("%s: mmap of 0x%x success\n", __FUNCTION__, startpAddress); startpAddress);
#endif
#ifdef LINUX_DEBUG_MAX #ifdef LINUX_DEBUG_MAX
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
printf("0x%x ", (startvAddress[i])); printf("0x%x ", (startvAddress[i]));
@ -1500,20 +1451,16 @@ UnmapPhysicalMemory(int virtualAddress, int Length)
diff = ((unsigned int)virtualAddress) % pagesize; diff = ((unsigned int)virtualAddress) % pagesize;
virtualAddress -= diff; virtualAddress -= diff;
Length += diff; Length += diff;
#ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "%s: calling munmap(0x%x,%d)", __FUNCTION__,
DEBUG("%s: calling munmap(0x%x,%d)\n", __FUNCTION__,
virtualAddress,Length); virtualAddress,Length);
#endif
if (munmap(&virtualAddress, Length) != 0) { if (munmap(&virtualAddress, Length) != 0) {
char buf[128]; char buf[128];
sprintf(buf, "%s %s: munmap failed", __FILE__, __FUNCTION__); sprintf(buf, "%s %s: munmap failed", __FILE__, __FUNCTION__);
perror(buf); perror(buf);
return ACCESN_ERROR; return ACCESN_ERROR;
} }
#ifndef NO_MACRO_ARGS lprintf(LOG_DEBUG, "%s: munmap(0x%x,%d) success", __FUNCTION__,
DEBUG("%s: munmap(0x%x,%d) success\n", __FUNCTION__,
virtualAddress, Length); virtualAddress, Length);
#endif
return ACCESN_OK; return ACCESN_OK;
} }
#endif /* unix */ #endif /* unix */