📄 bkendlog.c
字号:
/* strings corresponding to each tsfs operation opcode */LOCAL ENUM_NAME_MAP tsfsOpcodeMap [] = { {WDB_TSFS_OPEN, "WDB_TSFS_OPEN"}, /* open target server file */ {WDB_TSFS_READ, "WDB_TSFS_READ"}, /* read target server file */ {WDB_TSFS_WRITE, "WDB_TSFS_WRITE"}, /* write target server file */ {WDB_TSFS_CLOSE, "WDB_TSFS_CLOSE"}, /* close target server file */ {WDB_TSFS_IOCTL, "WDB_TSFS_IOCTL"}, /* ioctl target server file */ {WDB_TSFS_DELETE, "WDB_TSFS_DELETE"}, /* delete target server file */ {0, 0}, /* sentinel */ };LOCAL ENUM_NAME_MAP contextStatusMap [] = { { WDB_CTX_RUNNING, "CONTEXT_RUNNING"}, /* context running */ { WDB_CTX_SUSPENDED,"CONTEXT_SUSPENDED"}, /* context suspended */ { 0, 0}, /* sentinel */ };LOCAL ENUM_TYPE_MAP enumTypeMap [] = { {"ACTION_TYPE", 1, actionTypeMap}, {"RETURN_TYPE", 0, returnTypeMap}, {"CONTEXT_TYPE", 0, contextTypeMap}, {"EVENT_TYPE", 0, eventTypeMap}, {"AGENT_MODE", 1, agentModeTypeMap}, {"REG_SET_TYPE", 0, regSetTypeMap}, {"RT_TYPE", 0, rtTypeMap}, {"ERROR_TYPE", 0, errorTypeMap}, {"TSFS_IOCTL_REQ", 0, tsfsIoctlReqMap}, {"TSFS_OPCODE", 0, tsfsOpcodeMap}, {"CONTEXT_STATUS", 0, contextStatusMap}, {"TSFS_OPEN_MODE", 1, tsfsOpenModeMap}, };/* forward declarations */LOCAL void bkendLogWdbMemRegion (WDB_MEM_REGION *);LOCAL void bkendLogWdbMemXfer (WDB_MEM_XFER *);LOCAL void bkendLogWdbMemScanDesc (WDB_MEM_SCAN_DESC *);LOCAL void bkendLogWdbContext (WDB_CTX *);LOCAL void bkendLogWdbCtxStepDesc (WDB_CTX_STEP_DESC *);LOCAL void bkendLogWdbCtxCreateDesc (WDB_CTX_CREATE_DESC *);LOCAL void bkendLogWdbRegReadDesc (WDB_REG_READ_DESC *);LOCAL void bkendLogWdbRegWriteDesc (WDB_REG_WRITE_DESC *);LOCAL void bkendLogWdbRtInfo (WDB_RT_INFO *);LOCAL void bkendLogWdbAgentInfo (WDB_AGENT_INFO *);LOCAL void bkendLogWdbTgtInfo (WDB_TGT_INFO *);LOCAL void bkendLogWdbAction (WDB_ACTION *);LOCAL void bkendLogWdbEvtptAddDesc (WDB_EVTPT_ADD_DESC *);LOCAL void bkendLogWdbEvtptDelDesc (WDB_EVTPT_DEL_DESC *);LOCAL void bkendLogWdbEvtData (WDB_EVT_DATA *);LOCAL void bkendLogWdbCallRetInfo (WDB_CALL_RET_INFO *);LOCAL void bkendLogWdbExcInfo (WDB_EXC_INFO *);LOCAL void bkendLogWdbBpInfo (WDB_BP_INFO *);LOCAL void bkendLogWdbCtxExitInfo (WDB_CTX_EXIT_INFO *);LOCAL void bkendLogWdbCtxStartInfo (WDB_CTX_START_INFO *);LOCAL void bkendLogWdbUINT32 (UINT32 *);LOCAL void bkendLogWdbAgentMode (TGT_INT_T *);LOCAL void bkendLogWdbTGT_ADDR_T (TGT_ADDR_T *);LOCAL void bkendLogWdbString (WDB_STRING_T *);LOCAL void bkendLogWdbTsfsInfo (WDB_TSFS_INFO * pWdbTsfsInfo);LOCAL void bkendLogWdbTsfsOpenInfo (WDB_TSFS_OPEN_INFO * pWdbTsfsOpenInfo);LOCAL void bkendLogWdbTsfsRwInfo (WDB_TSFS_RW_INFO * pWdbTsfsRwInfo);LOCAL void bkendLogWdbTsfsIoctlInfo (WDB_TSFS_IOCTL_INFO * pWdbTsfsIoctlInfo);LOCAL void bkendLogWdbTsfsDeleteInfo (WDB_TSFS_DELETE_INFO * pWdbTsfsDeleteInfo);LOCAL void bkendLogWdbEnumToString (char * enumType, int enumValue);LOCAL void bkendLogWdbCtxStatus (TGT_INT_T * pCtxStatus);/********************************************************************************* bkendLogInit - initialize the back end log feature.** This function is called by the back end during the back end initialization to* initialize the back end request log feature. The <wdbLogFileName> argument* points to the log file name. If this pointer is the NULL pointer then* no file are opened and no requests are logged.** RETURNS: OK or ERROR if something failed.** NOMANUAL*/STATUS bkendLogInit ( char * pWdbLogFileName, /* file name to save info in */ u_int wdbLogMaxSize /* Max size for the log file */ ) { char hostName[MAXHOSTNAMELEN]; /* host name */ time_t currentDate; /* current time & date */ char ** arg; /* cmd line arguments */ /* * check if the back end log capability is already in use. If not * start the initialization otherwise log a message and exit. */ if (bkendLogEnable) { wpwrLogWarn ("Backend log capability already in use\n"); return (WTX_ERR_SVR_BKEND_LOG_IN_USE); } /* * if the wdbLogFileName pointer is NULL then return immediately because no * request need to be logged. */ if (pWdbLogFileName == NULL) { wdbLogFile = NULL; return (OK); } /* Create the backEndLog Mutex if not exists (for the first time) */ if (backEndLogMutex == NULL) { backEndLogMutex = semMCreate (0); if (backEndLogMutex == NULL) { wpwrLogErr ("Unable to create BackEndLog mutex semaphore\n"); return (ERROR); } } /* Wait for the backEndLog Mutex */ if (semTake (backEndLogMutex, WAIT_FOREVER) == ERROR) return ERROR; /* * Re-check if the back end log capability is already in use. If not * start the initialization otherwise log a message and exit. */ if (bkendLogEnable) { wpwrLogWarn ("Backend log capability already in use\n"); semGive (backEndLogMutex); return (WTX_ERR_SVR_BKEND_LOG_IN_USE); } /* Save maxSize */ maxSize = wdbLogMaxSize; /* * open a file with the name pointed to by wdbLogFileName. If the file can't * be opened the back end request log feature is not enabled but the * target server initialization and execution is not stopped. In this case * no requests are logged. */ if (maxSize == 0) wdbLogFile = fopen (pWdbLogFileName, "a"); else wdbLogFile = fopen (pWdbLogFileName, "w"); if (wdbLogFile == NULL) { wpwrLogWarn ("Can't create the log file\n"); wpwrLogWarn ("Continue without logging the requests\n"); semGive (backEndLogMutex); return (WTX_ERR_SVR_FILE_NOT_FOUND); } /* set the flag to signal the back end log capability is turn on */ bkendLogEnable = TRUE; /* log the user name */ fprintf (wdbLogFile, "User Name : %s\n", wpwrGetUserName (WPWR_UID_DEFAULT)); /* log the current time and date */ time (¤tDate); /* get current time & date */ fprintf (wdbLogFile, "Started : %s", ctime(¤tDate)); /* log the target server name */ if (gethostname (hostName, sizeof (hostName)) != OK) sprintf (hostName, "unknown"); fprintf (wdbLogFile, "Target Server Name : %s@%s\n", tgtSvrNameGet(), hostName); /* log the target name */ fprintf (wdbLogFile, "Target Name : %s\n", tgtNameGet()); /* log the arguments on the command line */ arg = wpwrCmdLineGet (); fprintf (wdbLogFile, "Target Server Options : "); while (*arg != NULL) fprintf (wdbLogFile, "%s ", *arg++); fprintf (wdbLogFile, "\n"); /* log the host informations on the command line */#ifndef WIN32 { struct utsname name; if (uname(&name) != ERROR) { fprintf (wdbLogFile, "Host : %s %s %s %s %s\n", name.sysname, name.nodename, name.release, name.version, name.machine); } }#else /* WIN32 */ { OSVERSIONINFO osvi; char szVersion [100] = ""; char osVersion [4] = ""; memset (&osvi, 0, sizeof(OSVERSIONINFO)); osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); GetVersionEx (&osvi); if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) { if (osvi.dwMinorVersion == 0) /* Windows 95 */ strcpy (osVersion, "95 "); else if (osvi.dwMinorVersion == 10) /* Windows 98 */ strcpy (osVersion, "98 "); } else if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) strcpy (osVersion, "NT "); sprintf (szVersion, "Microsoft Windows %sversion %d.%d (Build %d)", osVersion, osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber & 0xFFFF); fprintf (wdbLogFile, "Host : %s\n", szVersion); }#endif /* WIN32 */ /* * flush the file write buffer to have all information physically in the * file in case the target server hang later. */ fflush (wdbLogFile); /* Give the backEndLog Mutex back */ semGive (backEndLogMutex); /* Return OK */ return (OK); }/********************************************************************************* bkendLog - log a request exchanged between the target server back end and the target ** This routine logs request data exchanged between the target server back* end and the target agent. Call this routine twice when issuing a WDB* service request: once prior to sending the request, in order to log the* request name and the input structure; and once on the reply, in order to* log the output structure.** The log is written to the file specified with the `-Bd' option to* `tgtsvr'. For example,* .CS* tgtsvr target -Bd /tmp/target.log* .CE* When the `-Bd' option is not used, bkendLog() does nothing and returns* immediately.** The <procNum> argument contains the WDB request number sent to the target* agent. If <xmit> is equal to TRUE, the structure pointed to by <args> is a* transmission structure (labeled `In' in the log output); otherwise, it is* a receive structure (labeled `Out' in the log output). <timeoutNb>* contains the number of time an identical request was resent.* <sequenceNumber> contains the request's current sequence number. If* <args> is NONE, no input or output structure value is logged.** Now, the banner is finished to be printed by rpcCoreInit. To do that, <procNum>* is equal to 0, and <xmit> is set to the value of the <timeout>, and <status>* to <resemd>.* The <timeoutVal> and <resendMax> arguments handle the time out value used by* the back end and the maximum number of times a request might be resent to the* target agent. These two back end features might be useless for some back end* but are always logged in the file. The <wdbLogMaxSize> argument is the * maximum size for the log file.** The code below gives an example of how to call bkendLog().* .CS* ...* /@ increment the sequence number @/** seqNumber++ ;** /@ log the WDB request @/** bkendLog (procNum, TRUE, in, 0, (int ) seqNumber, 0);** /@ call the agent request @/** do * {* status = myBackendCall (...);* }* while (++resendCnt < maxNumResend);** /@ log the structure returned by the target agent @/** bkendLog (procNum, FALSE, out, resendCnt, 0, status);* ...* .CE* RETURNS: N/A*/void bkendLog ( u_long procNum, /* procedure number to perform */ u_int xmit, /* request xmit: TRUE or FALSE */ char * args, /* Input/Output structure pointer */ int timeoutNb, /* timeout number */ int sequenceNumber, /* sequence number */ u_int status /* request status */ ) { void (*logFuncXmit) (); /* ptr to the transmit log function */ void (*logFuncRcv) (); /* ptr to the receive log function */ char * logRequestName; /* ptr to the WDB request name */ time_t currentDate; /* current time & date */ int fileSize; /* Size of the logging file */ /* return immediately if the flag is false */ if (!bkendLogEnable) return; /* Wait for the backEndLog Mutex */ if (semTake (backEndLogMutex, WAIT_FOREVER) == ERROR) return; /* Re-check if the flag is FALSE */ if (!bkendLogEnable) { semGive (backEndLogMutex); return; } /* Print the timeout and the resend values in the banner */ if (procNum == 0) { /* * Log the time out value used by the back end. The <timeout> value * is put in the <xmit> value. */ fprintf (wdbLogFile,"Timeout value : %d second(s)\n", xmit); /* * log the maximum no. of times a request can be resent by the back end * before to consider the link is broken. If <resendMax> is equal to * NONE this variable is not logged. The value of <resendMax> is put * in the place of <status>. */ fprintf (wdbLogFile,"Request re-send Max : %d\n",status); } /* Set current position at the beginning if fileSize > maxSize */ if (maxSize != 0) { /* Get file size in bytes */ fileSize = (int) ftell (wdbLogFile); /* fileSize > maxSize */ if (fileSize > maxSize) { /* Reposition the file pointer to the beginning */ rewind (wdbLogFile); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -