// PD_TRACE_DECLARE_FUNCTION ( SDB__DMSSU, "_dmsStorageUnit::_dmsStorageUnit" ) _dmsStorageUnit::_dmsStorageUnit ( const CHAR *pSUName, UINT32 sequence, INT32 pageSize, INT32 lobPageSize ) :_apm(this), _pDataSu( NULL ), _pIndexSu( NULL ), _pLobSu( NULL ) { PD_TRACE_ENTRY ( SDB__DMSSU ) ; SDB_ASSERT ( pSUName, "name can't be null" ) ; if ( 0 == pageSize ) { pageSize = DMS_PAGE_SIZE_DFT ; } if ( 0 == lobPageSize ) { lobPageSize = DMS_DEFAULT_LOB_PAGE_SZ ; } CHAR dataFileName[DMS_SU_FILENAME_SZ + 1] = {0} ; CHAR idxFileName[DMS_SU_FILENAME_SZ + 1] = {0} ; _storageInfo._pageSize = pageSize ; _storageInfo._lobdPageSize = lobPageSize ; ossStrncpy( _storageInfo._suName, pSUName, DMS_SU_NAME_SZ ) ; _storageInfo._suName[DMS_SU_NAME_SZ] = 0 ; _storageInfo._sequence = sequence ; _storageInfo._secretValue = ossPack32To64( (UINT32)time(NULL), (UINT32)(ossRand()*239641) ) ; ossSnprintf( dataFileName, DMS_SU_FILENAME_SZ, "%s.%d.%s", _storageInfo._suName, sequence, DMS_DATA_SU_EXT_NAME ) ; ossSnprintf( idxFileName, DMS_SU_FILENAME_SZ, "%s.%d.%s", _storageInfo._suName, sequence, DMS_INDEX_SU_EXT_NAME ) ; _pDataSu = SDB_OSS_NEW dmsStorageData( dataFileName, &_storageInfo ) ; if ( _pDataSu ) { _pIndexSu = SDB_OSS_NEW dmsStorageIndex( idxFileName, &_storageInfo, _pDataSu ) ; } if ( NULL != _pDataSu && NULL != _pIndexSu ) { ossMemset( dataFileName, 0, sizeof( dataFileName ) ) ; ossMemset( idxFileName, 0 , sizeof( idxFileName ) ) ; ossSnprintf( dataFileName, DMS_SU_FILENAME_SZ, "%s.%d.%s", _storageInfo._suName, _storageInfo._sequence, DMS_LOB_META_SU_EXT_NAME ) ; ossSnprintf( idxFileName, DMS_SU_FILENAME_SZ, "%s.%d.%s", _storageInfo._suName, _storageInfo._sequence, DMS_LOB_DATA_SU_EXT_NAME ) ; _pLobSu = SDB_OSS_NEW dmsStorageLob( dataFileName, idxFileName, &_storageInfo, _pDataSu ) ; } PD_TRACE_EXIT ( SDB__DMSSU ) ; }
void ossSprintVersion( const CHAR *prompt, CHAR *pBuff, UINT32 len, BOOLEAN multiLine ) { if ( 0 == len ) { return ; } ossMemset( pBuff, 0, len ) ; #ifdef SDB_ENGINE_FIXVERSION_CURRENT if ( multiLine ) { ossSnprintf( pBuff, len - 1, "%s: %d.%d.%d%sRelease: %d%s%s%s", prompt, SDB_ENGINE_VERISON_CURRENT, SDB_ENGINE_SUBVERSION_CURRENT, SDB_ENGINE_FIXVERSION_CURRENT, OSS_NEWLINE, SDB_ENGINE_RELEASE_CURRENT, OSS_NEWLINE, SDB_ENGINE_BUILD_TIME, OSS_NEWLINE ) ; } else { ossSnprintf( pBuff, len - 1, "%s: %d.%d.%d, Release: %d, Build: %s", prompt, SDB_ENGINE_VERISON_CURRENT, SDB_ENGINE_SUBVERSION_CURRENT, SDB_ENGINE_FIXVERSION_CURRENT, SDB_ENGINE_RELEASE_CURRENT, SDB_ENGINE_BUILD_TIME ) ; } #else if ( multiLine ) { ossSnprintf( pBuff, len - 1, "%s: %d.%d%sRelease: %d%s%s%s", prompt, SDB_ENGINE_VERISON_CURRENT, SDB_ENGINE_SUBVERSION_CURRENT, OSS_NEWLINE, SDB_ENGINE_RELEASE_CURRENT, OSS_NEWLINE, SDB_ENGINE_BUILD_TIME, OSS_NEWLINE ) ; } else { ossSnprintf( pBuff, len - 1, "%s: %d.%d, Release: %d, Build: %s", prompt, SDB_ENGINE_VERISON_CURRENT, SDB_ENGINE_SUBVERSION_CURRENT, SDB_ENGINE_RELEASE_CURRENT, SDB_ENGINE_BUILD_TIME ) ; } #endif //SDB_ENGINE_FIXVERSION_CURRENT }
void ossMemTrace ( const CHAR *pPath ) { ossPrimitiveFileOp trapFile ; CHAR fileName [ OSS_MAX_PATHSIZE + 1 ] = {0} ; UINT64 totalSize = 0 ; if ( !ossMemTrackCBInit ) { return ; } gMemTrackCB._memTrackMutex.get() ; if ( OSS_MAX_PATHSIZE < ossStrlen ( pPath ) + ossStrlen ( OSS_PRIMITIVE_FILE_SEP ) + ossStrlen ( SDB_OSS_MEMDUMPNAME ) ) { goto error ; } ossMemset ( fileName, 0, sizeof ( fileName ) ) ; ossSnprintf ( fileName, sizeof(fileName), "%s%s%s", pPath, OSS_PRIMITIVE_FILE_SEP, SDB_OSS_MEMDUMPNAME ) ; trapFile.Open ( fileName ) ; if ( trapFile.isValid () ) { trapFile.seekToEnd () ; trapFile.Write ( " -------- Memory Allocation Information --------\n" ) ; std::set<void*>::iterator it ; for ( it = gMemTrackCB._memTrackMap.begin() ; it != gMemTrackCB._memTrackMap.end() ; ++it ) { void *p = *it ; totalSize += ossMemTraceDump ( p, trapFile ) ; } ossMemset ( fileName, 0, sizeof ( fileName ) ) ; ossSnprintf ( fileName, sizeof(fileName), " -------- Totally Allocated %lld Bytes --------\n", totalSize ) ; trapFile.Write ( fileName ) ; } done : trapFile.Close () ; gMemTrackCB._memTrackMutex.release() ; return ; error : goto done ; }
/* _pmdSession implement */ _pmdSession::_pmdSession( SOCKET fd ) :_socket( &fd, SESSION_SOCKET_DFT_TIMEOUT ), _client( &_socket ), _processor( NULL ), _pDPSCB( NULL ) { _pEDUCB = NULL ; _eduID = PMD_INVALID_EDUID ; _pBuff = NULL ; _buffLen = 0 ; _awaitingHandshake = TRUE ; _socket.disableNagle() ; if ( SOCKET_INVALIDSOCKET != fd ) { CHAR tmpName [ 128 ] = {0} ; _socket.getPeerAddress( tmpName, sizeof( tmpName ) -1 ) ; _sessionName = tmpName ; _sessionName += ":" ; ossSnprintf( tmpName, sizeof( tmpName ) -1, "%d", _socket.getPeerPort() ) ; _sessionName += tmpName ; } }
void _pmdEDUCB::setClientInfo ( const CHAR *clientName, UINT16 clientPort ) { ossScopedLock _lock ( &_mutex, EXCLUSIVE ) ; ossSnprintf( _Name, PMD_EDU_NAME_LENGTH, "%s:%u", clientName, clientPort ) ; _Name[PMD_EDU_NAME_LENGTH] = 0 ; }
INT32 restAdaptor::_sendHttpChunk( pmdRestSession *pSession, const CHAR *pBuffer, INT32 length ) { INT32 rc = SDB_OK ; CHAR CRLF[3] = { REST_STRING_CR, REST_STRING_LF, 0 } ; CHAR chunkSize[255] = { 0 } ; ossSnprintf( chunkSize, 255, "%x\r\n", length ) ; rc = pSession->sendData( REST_FUN_STRING( chunkSize ), _timeout ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to send data, rc=%d", rc ) ; goto error ; } rc = pSession->sendData( pBuffer, length, _timeout ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to send data, rc=%d", rc ) ; goto error ; } rc = pSession->sendData( REST_FUN_STRING( CRLF ), _timeout ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to send data, rc=%d", rc ) ; goto error ; } done: return rc ; error: goto done ; }
static INT32 qgmPrint ( _qgmOperatorElement *ele, CHAR *&pBuffer, INT32 &bufferSize ) { INT32 rc = SDB_OK ; INT32 line = 0 ; while ( TRUE ) { INT32 currentOffset = 0 ; rc = qgmPrintln ( ele, pBuffer, bufferSize, line, currentOffset ) ; if ( rc ) { if ( SDB_DMS_EOC == rc ) { rc = SDB_OK ; break ; } PD_RC_CHECK ( rc, PDERROR, "Failed to println, rc = %d", rc ) ; } ++line ; ossSnprintf ( pBuffer, bufferSize, OSS_NEWLINE ) ; bufferSize -= ossStrlen ( OSS_NEWLINE ) ; pBuffer += ossStrlen ( OSS_NEWLINE ) ; ; QGM_DUMP_BUFFER_SIZE_CHECK } done : return rc ; error : goto done ; }
void _pmdExternClient::_makeName() { if ( 0 == _peerIP[ 0 ] ) { ossStrcpy( _clientName, "noip-Extern" ) ; } else if ( _username.empty() ) { ossSnprintf( _clientName, PMD_CLIENTNAME_LEN, "%s:%u-Extern", _peerIP, _peerPort ) ; } else { ossSnprintf( _clientName, PMD_CLIENTNAME_LEN, "%s@%s:%u-Extern", _username.c_str(), _peerIP, _peerPort ) ; } }
void ossGetSimpleVersion( CHAR *pBuff, UINT32 bufLen ) { if ( NULL == pBuff || 0 == bufLen ) { return ; } ossMemset( pBuff, 0, bufLen ) ; #ifdef SDB_ENGINE_FIXVERSION_CURRENT ossSnprintf( pBuff, bufLen - 1, "%d.%d.%d", SDB_ENGINE_VERISON_CURRENT, SDB_ENGINE_SUBVERSION_CURRENT, SDB_ENGINE_FIXVERSION_CURRENT ) ; #else ossSnprintf( pBuff, bufLen - 1, "%d.%d", SDB_ENGINE_VERISON_CURRENT, SDB_ENGINE_SUBVERSION_CURRENT ) ; #endif }
// PD_TRACE_DECLARE_FUNCTION ( SDB_OSSGETSYMBNFA, "ossGetSymbolNameFromAddress" ) void ossGetSymbolNameFromAddress( OSS_INSTRUCTION_PTR pInstruction, CHAR *pName, size_t nameSize, UINT32_64 *pOffset ) { PD_TRACE_ENTRY ( SDB_OSSGETSYMBNFA ); Dl_info dlip ; UINT32_64 offset = 0 ; BOOLEAN bErr = false ; INT32 rc = 0 ; if ( ( ! pInstruction ) || ( ! pName ) ) { bErr = true ; goto exit ; } rc = dladdr( (void *)pInstruction, &dlip ) ; if ( rc && dlip.dli_sname ) { ossStrncpy( pName, dlip.dli_sname, nameSize ) ; if ( dlip.dli_saddr ) { offset = (UINT32_64)pInstruction - (UINT32_64)dlip.dli_saddr ; } } else if ( rc && dlip.dli_fname ) { ossStrncpy( pName, dlip.dli_fname, nameSize ) ; offset = (UINT32_64)pInstruction - (UINT32_64)dlip.dli_fbase ; } else { bErr = true ; } exit : if ( bErr ) { if ( pInstruction ) { ossSnprintf(pName, nameSize, "0x" OSS_PRIXPTR, (UINT32_64)pInstruction) ; } else { ossStrncpy (pName, OSS_UNKNOWN_STACKFRAME_NAME, nameSize); } } if ( pOffset ) { *pOffset = offset ; } PD_TRACE_EXIT ( SDB_OSSGETSYMBNFA ); }
// PD_TRACE_DECLARE_FUNCTION ( SDB_OSSGETSYMBNFADDR, "ossGetSymbolNameFromAddress" ) void ossGetSymbolNameFromAddress( HANDLE hProcess, UINT64 pInstruction, SYMBOL_INFO * pSymbol, CHAR *pName, UINT32 nameSize ) { PD_TRACE_ENTRY ( SDB_OSSGETSYMBNFADDR ); SYMBOL_INFO * symbol = NULL ; UINT64 displacement = 0 ; UINT32 dwDisplacement = 0 ; IMAGEHLP_LINE64 line = { 0 } ; UINT32 strLen = 0 ; if ( ( NULL != pInstruction ) & ( NULL != pSymbol ) ) { line.SizeOfStruct = sizeof(IMAGEHLP_LINE64) ; WaitForSingleObject( ossGetSysMutexHandle( _SymFromAddr ), INFINITE ) ; if ( SymFromAddr( hProcess, pInstruction, &displacement, pSymbol ) ) { strLen += ossSnprintf( pName, nameSize, "0x%0llX %s", pInstruction, pSymbol->Name ) ; if ( SymGetLineFromAddr64( hProcess, pInstruction, (PDWORD)(&dwDisplacement), &line ) ) { strLen += ossSnprintf( pName + strLen, nameSize - strLen, " %s [%d]", line.FileName, line.LineNumber ); } else { strLen += ossSnprintf( pName + strLen, nameSize - strLen, OSS_UNKNOWN_STACKFRAME_NAME ) ; } } ReleaseMutex ( ossGetSysMutexHandle( _SymFromAddr ) ) ; } PD_TRACE_EXIT ( SDB_OSSGETSYMBNFADDR ); }
// PD_TRACE_DECLARE_FUNCTION ( SDB_OSSMCHCODE, "ossMachineCode" ) CHAR *ossMachineCode( UINT32 instruction, CHAR * mCode ) { PD_TRACE_ENTRY ( SDB_OSSMCHCODE ); char mcode[4] = { 0 } ; if ( NULL != mCode ) { memcpy( mcode, &instruction, sizeof(mcode) ) ; ossSnprintf( mCode, OSS_MCODE_LEN, "%02X%02X%02X%02X", 0xff & mcode[0], 0xff & mcode[1], 0xff & mcode[2], 0xff & mcode[3]) ; PD_TRACE1 ( SDB_OSSMCHCODE, PD_PACK_STRING(mCode) ); } PD_TRACE_EXIT ( SDB_OSSMCHCODE ); return mCode ; }
static string _rtnMakeDateDirName() { CHAR tmpBuff[ 20 ] = {0} ; time_t tmpTime = time( NULL ) ; struct tm localTm ; ossLocalTime( tmpTime, localTm ) ; ossSnprintf( tmpBuff, sizeof(tmpBuff) - 1, "%04d%02d%02d", localTm.tm_year+1900, // 1) Year (UINT32) localTm.tm_mon+1, // 2) Month (UINT32) localTm.tm_mday // 3) Day (UINT32) ) ; return (string)tmpBuff ; }
static UINT64 ossMemTraceDump ( void *p, ossPrimitiveFileOp &trapFile ) { CHAR lineBuffer [ OSSMEMTRACEDUMPBUFSZ + 1 ] = {0} ; CHAR *pAddr = (CHAR*)p ; ossMemset ( lineBuffer, 0, sizeof(lineBuffer) ) ; ossSnprintf ( lineBuffer, sizeof(lineBuffer), " Address: %p\n", pAddr ) ; trapFile.Write ( lineBuffer ) ; ossMemset ( lineBuffer, 0, sizeof(lineBuffer) ) ; ossSnprintf ( lineBuffer, sizeof(lineBuffer), " Freed: %s, Size: %lld, DebugSize: %d\n", (*(UINT32*)(pAddr+OSS_MEM_HEAD_FREEDOFFSET))==0?"false":"true", (*(UINT64*)(pAddr+OSS_MEM_HEAD_SIZEOFFSET)), (*(UINT32*)(pAddr+OSS_MEM_HEAD_DEBUGOFFSET)) ) ; trapFile.Write ( lineBuffer ) ; ossMemset ( lineBuffer, 0, sizeof(lineBuffer) ) ; ossSnprintf ( lineBuffer, sizeof(lineBuffer), " File: 0x%x, Line: %d\n", (*(UINT32*)(pAddr+OSS_MEM_HEAD_FILEOFFSET)), (*(UINT32*)(pAddr+OSS_MEM_HEAD_LINEOFFSET)) ) ; trapFile.Write ( lineBuffer ) ; trapFile.Write ( "\n" ) ; return (*(UINT64*)(pAddr+OSS_MEM_HEAD_SIZEOFFSET)) ; }
void _pmdExternClient::logout() { if ( _isAuthed ) { CHAR szTmp[ 16 ] = { 0 } ; ossSnprintf( szTmp, sizeof(szTmp)-1, "%llu", _pEDUCB->getID() ) ; PD_AUDIT( AUDIT_ACCESS, getUsername(), getPeerIPAddr(), getPeerPort(), "LOGOUT", AUDIT_OBJ_SESSION, szTmp, SDB_OK, "User[UserName:%s, RemoteIP:%s, RemotePort:%u, " "LocalIP:%s, LocalPort:%u] logout succeed", getUsername(), getPeerIPAddr(), getPeerPort(), getLocalIPAddr(), getLocalPort() ) ; } _isAuthed = FALSE ; }
string _pmdController::_makeID( restSessionInfo * pSessionInfo ) { UINT32 ip = 0 ; UINT32 seq = 0 ; ossUnpack32From64( pSessionInfo->_attr._sessionID, ip, seq ) ; CHAR tmp[9] = {0} ; ossSnprintf( tmp, sizeof(tmp)-1, "%08x", seq ) ; string strValue = md5::md5simpledigest( (const void*)pSessionInfo, pSessionInfo->getAttrSize() ) ; UINT32 size = strValue.size() ; strValue = strValue.substr( 0, size - ossStrlen( tmp ) ) ; strValue += tmp ; pSessionInfo->_id = strValue ; return strValue ; }
char* ossSSLGetErrorMessage(INT32 error) { #define _MSG_LEN 256 static OSS_THREAD_LOCAL char buf[_MSG_LEN]; char* errorMsg; INT32 err = ERR_get_error(); switch(error) { case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_WRITE: errorMsg = "possibly timed out during connect"; break; case SSL_ERROR_ZERO_RETURN: errorMsg = "SSL network connection closed"; break; case SSL_ERROR_SYSCALL: if (0 != err) { ERR_error_string_n(err, buf, _MSG_LEN); errorMsg = buf; } else { INT32 lastError; #ifdef _WINDOWS lastError = WSAGetLastError(); #else lastError = errno; #endif ossSnprintf(buf, _MSG_LEN, "the SSL BIO reported an I/O error, " "system errno: %d", lastError); errorMsg = buf; } break; case SSL_ERROR_SSL: ERR_error_string_n(err, buf, _MSG_LEN); errorMsg = buf; break; default: errorMsg = "unrecognized SSL error"; } return errorMsg; }
const CHAR* utilAscTime( time_t tTime, CHAR * pBuff, UINT32 size ) { struct tm localTm ; ossLocalTime( tTime, localTm ) ; ossMemset( pBuff, 0, size ) ; ossSnprintf( pBuff, size-1, "%04d-%02d-%02d-%02d:%02d:%02d", localTm.tm_year+1900, // 1) Year (UINT32) localTm.tm_mon+1, // 2) Month (UINT32) localTm.tm_mday, // 3) Day (UINT32) localTm.tm_hour, // 4) Hour (UINT32) localTm.tm_min, // 5) Minute (UINT32) localTm.tm_sec // 6) Second (UINT32) ) ; pBuff[ size - 1 ] = 0 ; return pBuff ; }
INT32 pmdThreadMainEntry( INT32 argc, CHAR** argv ) { INT32 rc = SDB_OK ; pmdKRCB *krcb = pmdGetKRCB() ; CHAR currentPath[ OSS_MAX_PATHSIZE + 1 ] = { 0 } ; CHAR dialogPath[ OSS_MAX_PATHSIZE + 1 ] = { 0 } ; CHAR dialogFile[ OSS_MAX_PATHSIZE + 1 ] = { 0 } ; INT32 delSig[] = { 17, 0 } ; // del SIGCHLD CHAR verText[ OSS_MAX_PATHSIZE + 1 ] = { 0 } ; po::variables_map vm ; rc = initArgs( argc, argv, vm ) ; if ( rc ) { if ( SDB_PMD_HELP_ONLY == rc || SDB_PMD_VERSION_ONLY == rc ) { rc = SDB_OK ; } goto done ; } rc = ossGetEWD( currentPath, OSS_MAX_PATHSIZE ) ; if ( rc ) { std::cout << "Get current path failed: " << rc << std::endl ; goto error ; } ossChDir( currentPath ) ; rc = utilBuildFullPath( currentPath, SDBCM_LOG_PATH, OSS_MAX_PATHSIZE, dialogPath ) ; if ( rc ) { std::cout << "Build dialog path failed: " << rc << std::endl ; goto error ; } rc = ossMkdir( dialogPath ) ; if ( rc && SDB_FE != rc ) { std::cout << "Create dialog dir: " << dialogPath << " failed: " << rc << std::endl ; goto error ; } rc = utilBuildFullPath( dialogPath, SDBCM_DIALOG_FILE_NAME, OSS_MAX_PATHSIZE, dialogFile ) ; if ( rc ) { std::cout << "Build dialog path failed: " << rc << std::endl ; goto error ; } sdbEnablePD( dialogFile ) ; ossSprintVersion( "Version", verText, OSS_MAX_PATHSIZE, FALSE ) ; PD_LOG( PDEVENT, "Start cm[%s]...", verText) ; rc = sdbGetOMAgentOptions()->init( currentPath ) ; if ( rc ) { PD_LOG( PDERROR, "Failed to init config, rc: %d", rc ) ; goto error ; } if ( vm.count( PMD_OPTION_CURUSER ) ) { sdbGetOMAgentOptions()->setCurUser() ; } if ( vm.count( PMD_OPTION_STANDALONE ) ) { sdbGetOMAgentOptions()->setStandAlone() ; if ( vm.count( PMD_OPTION_ALIVE_TIME ) ) { UINT32 timeout = vm[ PMD_OPTION_ALIVE_TIME ].as<INT32>() ; sdbGetOMAgentOptions()->setAliveTimeout( timeout ) ; } } if ( vm.count( PMD_OPTION_PORT ) ) { string svcname = vm[ PMD_OPTION_PORT ].as<string>() ; sdbGetOMAgentOptions()->setCMServiceName( svcname.c_str() ) ; pmdSetLocalPort( (UINT16)ossAtoi( svcname.c_str() ) ) ; } setPDLevel( sdbGetOMAgentOptions()->getDiagLevel() ) ; { string configs ; sdbGetOMAgentOptions()->toString( configs ) ; PD_LOG( PDEVENT, "All configs:\n%s", configs.c_str() ) ; } pmdSetDBRole( SDB_ROLE_OMA ) ; rc = pmdEnableSignalEvent( dialogPath, (PMD_ON_QUIT_FUNC)pmdOnQuit, delSig ) ; PD_RC_CHECK ( rc, PDERROR, "Failed to enable trap, rc: %d", rc ) ; #if defined( _LINUX ) signal( SIGCHLD, SIG_IGN ) ; #endif // _LINUX PMD_REGISTER_CB( sdbGetOMAgentMgr() ) ; rc = krcb->init() ; PD_RC_CHECK( rc, PDERROR, "Failed to init krcb, rc: %d", rc ) ; { EDUID agentEDU = PMD_INVALID_EDUID ; pmdEDUMgr *eduMgr = krcb->getEDUMgr() ; rc = eduMgr->startEDU ( EDU_TYPE_PIPESLISTENER, (void*)sdbGetOMAgentOptions()->getCMServiceName(), &agentEDU ) ; PD_RC_CHECK( rc, PDERROR, "Start PIPELISTENER failed, rc: %d", rc ) ; rc = eduMgr->waitUntil( agentEDU, PMD_EDU_RUNNING ) ; PD_RC_CHECK( rc, PDERROR, "Wait pipe listener to running " "failed, rc: %d", rc ) ; } #if defined (_LINUX) { CHAR pmdProcessName [ OSS_RENAME_PROCESS_BUFFER_LEN + 1 ] = {0} ; ossSnprintf ( pmdProcessName, OSS_RENAME_PROCESS_BUFFER_LEN, "%s(%s)", utilDBTypeStr( pmdGetDBType() ), sdbGetOMAgentOptions()->getCMServiceName() ) ; ossEnableNameChanges ( argc, argv ) ; ossRenameProcess ( pmdProcessName ) ; } #endif // _LINUX while ( PMD_IS_DB_UP() ) { ossSleepsecs ( 1 ) ; } rc = krcb->getShutdownCode() ; done: PMD_SHUTDOWN_DB( rc ) ; pmdSetQuit() ; krcb->destroy () ; PD_LOG ( PDEVENT, "Stop programme, exit code: %d", krcb->getShutdownCode() ) ; return rc == SDB_OK ? 0 : 1 ; error: goto done ; }
static INT32 qgmPrintln ( _qgmOperatorElement *ele, CHAR *&pBuffer, INT32 &bufferSize, INT32 line, INT32 ¤tOffset ) { INT32 rc = SDB_DMS_EOC ; INT32 tempRC = SDB_DMS_EOC ; INT32 slen = 0 ; INT32 temp = 0 ; if ( line >= 5 ) { std::vector<_qgmOperatorElement*>::iterator it ; for ( it = ele->_children.begin(); it != ele->_children.end() ; ++it ) { tempRC = qgmPrintln ( *it, pBuffer, bufferSize, line-5, currentOffset ) ; if ( tempRC ) { PD_CHECK ( SDB_DMS_EOC == tempRC, tempRC, error, PDERROR, "Failed to println, rc = %d", tempRC ) ; } else { rc = SDB_OK ; } } goto done ; } switch ( line % 5 ) { case 0 : slen = ossStrlen ( ele->_opID ) ; temp = ele->_pos - currentOffset - slen/2 ; for ( INT32 i = 0; i < temp; ++i ) { ossSnprintf ( pBuffer, bufferSize, "%c", ' ' ) ; bufferSize-- ; pBuffer++ ; currentOffset ++ ; QGM_DUMP_BUFFER_SIZE_CHECK } ossSnprintf ( pBuffer, bufferSize, "%s", ele->_opID ) ; bufferSize -= slen ; QGM_DUMP_BUFFER_SIZE_CHECK pBuffer += slen ; currentOffset += slen ; break ; case 1 : slen = ossStrlen ( ele->_opName ) ; temp = ele->_pos - currentOffset - slen/2 ; for ( INT32 i = 0; i < temp; ++i ) { ossSnprintf ( pBuffer, bufferSize, "%c", ' ' ) ; bufferSize-- ; pBuffer++ ; currentOffset ++ ; QGM_DUMP_BUFFER_SIZE_CHECK } ossSnprintf ( pBuffer, bufferSize, "%s", ele->_opName ) ; bufferSize -= slen ; QGM_DUMP_BUFFER_SIZE_CHECK pBuffer += slen ; currentOffset += slen ; break ; case 2 : temp = ele->_pos - currentOffset ; for ( INT32 i = 0; i < temp; ++i ) { ossSnprintf ( pBuffer, bufferSize, "%c", ' ' ) ; bufferSize-- ; pBuffer++ ; currentOffset ++ ; QGM_DUMP_BUFFER_SIZE_CHECK } ossSnprintf ( pBuffer, bufferSize, "%c", '|' ) ; bufferSize-- ; pBuffer++ ; currentOffset++ ; QGM_DUMP_BUFFER_SIZE_CHECK break ; case 3 : for ( UINT32 i = 0; i < ele->_children.size(); i++ ) { _qgmOperatorElement *child = ele->_children[i] ; SDB_ASSERT ( child, "child can't be NULL" ) ; temp = child->_pos - currentOffset ; for ( INT32 j = 0; j < temp; ++j ) { ossSnprintf ( pBuffer, bufferSize, "%c", i == 0 ? ' ':'-' ) ; bufferSize-- ; pBuffer++ ; currentOffset ++ ; QGM_DUMP_BUFFER_SIZE_CHECK } ossSnprintf ( pBuffer, bufferSize, "%c", ele->_children.size() == 1 ? '|' : '+' ) ; bufferSize-- ; pBuffer++ ; currentOffset ++ ; QGM_DUMP_BUFFER_SIZE_CHECK } if ( ele->_children.size() == 0 && ele->_pCLName ) { slen = ossStrlen ( ele->_pCLName ) ; temp = ele->_pos - currentOffset - slen/2 ; for ( INT32 i = 0; i < temp; ++i ) { ossSnprintf ( pBuffer, bufferSize, "%c", ' ' ) ; bufferSize-- ; pBuffer++ ; currentOffset ++ ; QGM_DUMP_BUFFER_SIZE_CHECK } ossSnprintf ( pBuffer, bufferSize, "%s", ele->_pCLName ) ; bufferSize -= slen ; QGM_DUMP_BUFFER_SIZE_CHECK pBuffer += slen ; currentOffset += slen ; } break ; case 4 : for ( UINT32 i = 0; i < ele->_children.size(); i++ ) { _qgmOperatorElement *child = ele->_children[i] ; SDB_ASSERT ( child, "child can't be NULL" ) ; temp = child->_pos - currentOffset ; for ( INT32 i = 0; i < temp; ++i ) { ossSnprintf ( pBuffer, bufferSize, "%c", ' ' ) ; bufferSize-- ; pBuffer++ ; currentOffset ++ ; QGM_DUMP_BUFFER_SIZE_CHECK } ossSnprintf ( pBuffer, bufferSize, "%c", '|' ) ; bufferSize-- ; pBuffer++ ; currentOffset ++ ; QGM_DUMP_BUFFER_SIZE_CHECK } break ; default : break ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB_OSSST, "ossStackTrace" ) void ossStackTrace( OSS_HANDPARMS, const CHAR *dumpDir ) { PD_TRACE_ENTRY ( SDB_OSSST ); ossPrimitiveFileOp trapFile ; CHAR fileName [ OSS_MAX_PATHSIZE ] = {0} ; UINT32 strLen = 0 ; oss_edu_data * pEduData = ossGetThreadEDUData() ; sigset_t savemask, tmpmask ; SINT32 prevNestedHandlerLevel = 0 ; OSS_SIGFUNCPTR pPrevNestedHandler = NULL ; pthread_sigmask( SIG_SETMASK, NULL, &savemask ) ; sigemptyset( &tmpmask ) ; sigaddset( &tmpmask, SIGSEGV ) ; sigaddset( &tmpmask, SIGILL ) ; sigaddset( &tmpmask, SIGTRAP ) ; sigaddset( &tmpmask, SIGBUS ) ; if ( NULL != pEduData ) { OSS_GET_NESTED_HANDLER_LEVEL( pEduData, prevNestedHandlerLevel ) ; pPrevNestedHandler = pEduData->ossEDUNestedSignalHandler ; pEduData->ossEDUNestedSignalHandler = (OSS_SIGFUNCPTR)ossNestedTrapHandler ; OSS_CLEAR_NESTED_HANDLER_LEVEL( pEduData ) ; if ( 0 == ossSetJump( pEduData->ossNestedSignalHanderJmpBuf, 1 ) ) { pthread_sigmask( SIG_UNBLOCK, &tmpmask, NULL ) ; } else { trapFile.Close() ; goto error ; } ossSnprintf ( fileName, OSS_MAX_PATHSIZE, "%d.%d.trap", ossGetCurrentProcessID(), ossGetCurrentThreadID() ) ; if ( ossStrlen ( dumpDir ) + ossStrlen ( OSS_PRIMITIVE_FILE_SEP ) + ossStrlen ( fileName ) > OSS_MAX_PATHSIZE ) { PD_LOG ( PDERROR, "path + file name is too long" ) ; goto error ; } ossMemset( fileName, 0, sizeof( fileName ) ) ; strLen += ossSnprintf( fileName, sizeof( fileName ), "%s%s", dumpDir, OSS_PRIMITIVE_FILE_SEP ) ; ossSnprintf( fileName + strLen, sizeof(fileName) - strLen, "%d.%d.trap", ossGetCurrentProcessID(), ossGetCurrentThreadID() ) ; ossOneTimeOnly() ; trapFile.Open( fileName ) ; if ( trapFile.isValid() ) { trapFile.seekToEnd () ; ossDumpStackTrace( OSS_HANDARGS, &trapFile ) ; } trapFile.Close() ; } done : if ( NULL != pEduData ) { pEduData->ossEDUNestedSignalHandler = pPrevNestedHandler ; OSS_SET_NESTED_HANDLER_LEVEL( pEduData, prevNestedHandlerLevel ) ; } pthread_sigmask( SIG_SETMASK, &savemask, NULL ) ; PD_TRACE_EXIT ( SDB_OSSST ); return ; error : goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB_OSSSTKTRA, "ossStackTrace" ) void ossStackTrace( LPEXCEPTION_POINTERS lpEP, const CHAR * dumpDir ) { PD_TRACE_ENTRY ( SDB_OSSSTKTRA ); SYMBOL_INFO * pSymbol = NULL ; HANDLE hProcess ; void * stack[ OSS_MAX_BACKTRACE_FRAMES_SUPPORTED + 1 ] = { 0 } ; CHAR pName[ OSS_FUNC_NAME_LEN_MAX + 1 ] ; UINT32 frames = 0 ; SYSTEM_INFO sysInfo = { 0 } ; OSVERSIONINFOEX OSVerInfo={ 0 } ; ossPrimitiveFileOp trapFile ; CHAR fileName[ OSS_MAX_PATHSIZE + 1 ] = { 0 } ; UINT32 StrLen = 0 ; ossSnprintf ( fileName, OSS_MAX_PATHSIZE, "%d.%d.trap", ossGetCurrentProcessID(), ossGetCurrentThreadID() ) ; if ( OSS_MAX_PATHSIZE < ossStrlen ( dumpDir ) + ossStrlen ( OSS_PRIMITIVE_FILE_SEP ) + ossStrlen ( fileName ) ) { pdLog ( PDERROR, __FUNC__, __FILE__, __LINE__, "path + file name is too long" ) ; goto error ; } ossMemset( fileName, 0, sizeof( fileName ) ) ; StrLen += ossSnprintf( fileName, sizeof( fileName ), "%s%s", dumpDir, OSS_PRIMITIVE_FILE_SEP ) ; ossSnprintf( fileName + StrLen, sizeof(fileName) - StrLen, "%d.%d.trap", ossGetCurrentProcessID(), ossGetCurrentThreadID() ) ; trapFile.Open( fileName ) ; if ( trapFile.isValid() ) { trapFile.seekToEnd () ; trapFile.Write(" -------- System Information --------\n" ) ; ossDumpSystemTime ( &trapFile ) ; ossDumpDatabaseInfo ( &trapFile ) ; GetSystemInfo( &sysInfo ) ; switch( sysInfo.wProcessorArchitecture ) { case PROCESSOR_ARCHITECTURE_INTEL: trapFile.Write( "Processor : Intel x86\n" ) ; break ; case PROCESSOR_ARCHITECTURE_IA64: trapFile.Write( "Processor : Intel IA64\n" ) ; break ; case PROCESSOR_ARCHITECTURE_AMD64: trapFile.Write( "Processor : AMD 64\n") ; break ; default: trapFile.Write( "Unknown processor architecture ") ; } trapFile.fWrite( " Number of processors: %u Page size: %u\n" " Min application address: %lx" " Max application address: %lx\n" " Active processor mask: %u\n", sysInfo.dwNumberOfProcessors, sysInfo.dwPageSize, sysInfo.lpMinimumApplicationAddress, sysInfo.lpMaximumApplicationAddress, sysInfo.dwActiveProcessorMask ) ; OSVerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); GetVersionEx ( (OSVERSIONINFO*) &OSVerInfo ) ; if ( OSVerInfo.dwMajorVersion == 6 ) { if ( OSVerInfo.dwMinorVersion == 0 ) { if ( OSVerInfo.wProductType == VER_NT_WORKSTATION ) { trapFile.Write( "Windows Vista " ) ; } else { trapFile.Write( "Windows Server 2008 " ) ; } } if ( OSVerInfo.dwMinorVersion == 1 ) { if ( OSVerInfo.wProductType == VER_NT_WORKSTATION ) { trapFile.Write( "Windows 7 " ) ; } else { trapFile.Write( "Windows Server 2008 " ) ; } } } if ( OSVerInfo.dwMajorVersion == 5 && OSVerInfo.dwMinorVersion == 2 ) { if ( OSVerInfo.wProductType == VER_NT_WORKSTATION ) { trapFile.Write( "Windows XP " ) ; } else { trapFile.Write( "Windows Server 2003 " ) ; } } if ( OSVerInfo.dwMajorVersion == 5 && OSVerInfo.dwMinorVersion == 1 ) { trapFile.Write("Windows XP ") ; } if ( OSVerInfo.dwMajorVersion == 5 && OSVerInfo.dwMinorVersion == 0 ) { trapFile.Write("Windows 2000 ") ; } trapFile.fWrite( "%s ( %d.%d) Build:%d\n", OSVerInfo.szCSDVersion, OSVerInfo.dwMajorVersion, OSVerInfo.dwMinorVersion, OSVerInfo.dwBuildNumber ) ; hProcess = GetCurrentProcess() ; pSymbol = ( SYMBOL_INFO * )SDB_OSS_MALLOC( sizeof( SYMBOL_INFO ) + OSS_FUNC_NAME_LEN_MAX * sizeof( char ) ) ; if ( NULL != pSymbol ) { ossMemset( pSymbol, 0, sizeof( SYMBOL_INFO ) + OSS_FUNC_NAME_LEN_MAX * sizeof(char) ) ; pSymbol->MaxNameLen = OSS_FUNC_NAME_LEN_MAX ; pSymbol->SizeOfStruct = sizeof( SYMBOL_INFO ) ; ossSymInitialize( hProcess, NULL, TRUE ) ; if ( NULL != lpEP ) { trapFile.Write( "-------- Registers --------\n" ) ; #ifndef _WIN64 trapFile.fWrite( SEGREG, lpEP->ContextRecord->SegGs, lpEP->ContextRecord->SegFs, lpEP->ContextRecord->SegEs, lpEP->ContextRecord->SegDs ) ; trapFile.fWrite( INTREG, (void*)lpEP->ContextRecord->Edi, (void*)lpEP->ContextRecord->Esi, (void*)lpEP->ContextRecord->Eax, (void*)lpEP->ContextRecord->Ebx, (void*)lpEP->ContextRecord->Ecx, (void*)lpEP->ContextRecord->Edx ) ; trapFile.fWrite( CTXREG, (void*)lpEP->ContextRecord->Ebp, (void*)lpEP->ContextRecord->Eip, (void*)lpEP->ContextRecord->Esp, (void*)lpEP->ContextRecord->EFlags, lpEP->ContextRecord->SegCs, lpEP->ContextRecord->SegSs ) ; #elif defined(_M_AMD64) trapFile.fWrite( SEGREG, lpEP->ContextRecord->SegGs, lpEP->ContextRecord->SegFs, lpEP->ContextRecord->SegEs, lpEP->ContextRecord->SegDs ) ; trapFile.fWrite( INTREG, (void*)lpEP->ContextRecord->Rdi, (void*)lpEP->ContextRecord->Rsi, (void*)lpEP->ContextRecord->Rax, (void*)lpEP->ContextRecord->Rbx, (void*)lpEP->ContextRecord->Rcx, (void*)lpEP->ContextRecord->Rdx, (void*)lpEP->ContextRecord->R8, (void*)lpEP->ContextRecord->R9, (void*)lpEP->ContextRecord->R10, (void*)lpEP->ContextRecord->R11, (void*)lpEP->ContextRecord->R12, (void*)lpEP->ContextRecord->R13, (void*)lpEP->ContextRecord->R14, (void*)lpEP->ContextRecord->R15 ) ; trapFile.fWrite( CTXREG, (void*)lpEP->ContextRecord->Rbp, (void*)lpEP->ContextRecord->Rip, (void*)lpEP->ContextRecord->Rsp, (void*)lpEP->ContextRecord->EFlags, lpEP->ContextRecord->SegCs, lpEP->ContextRecord->SegSs ) ; #endif trapFile.fWrite( "-------- Point of failure --------\n" ) ; ossMemset( pName, 0, sizeof( pName ) ) ; ossGetSymbolNameFromAddress( hProcess, (UINT64)lpEP->ExceptionRecord->ExceptionAddress, pSymbol, pName, sizeof( pName ) ) ; trapFile.fWrite( "%s\n", pName ) ; } // if NULL != lpEP trapFile.fWrite( "\n-------- Stack frames --------\n" ) ; #ifndef _WIN64 if ( NULL != lpEP ) { frames = ossWalkStackEx( lpEP, 0, OSS_MAX_BACKTRACE_FRAMES_SUPPORTED, stack ) ; } else { #endif frames = ossWalkStack( 0, OSS_MAX_BACKTRACE_FRAMES_SUPPORTED, stack ) ; #ifndef _WIN64 } #endif for ( UINT32 i = 0; i < frames; i++ ) { ossMemset( pName, 0, sizeof( pName ) ) ; ossGetSymbolNameFromAddress( hProcess, (UINT64)stack[i], pSymbol, pName, sizeof( pName ) ) ; trapFile.fWrite( "%3i: %s\n", i, pName ) ; } SDB_OSS_FREE( pSymbol ) ; } // if NULL != pSymbol } error : trapFile.Close() ; PD_TRACE_EXIT ( SDB_OSSSTKTRA ); return ; }
INT32 restAdaptor::sendResponse( pmdRestSession *pSession, HTTP_RESPONSE_CODE rspCode ) { INT32 rc = SDB_OK ; PD_TRACE_ENTRY( SDB__RESTADP_SENDRE ) ; SDB_ASSERT ( pSession, "pSession is NULL" ) ; CHAR httpBodySize[256] = { 0 } ; httpConnection *pHttpCon = pSession->getRestConn() ; std::vector<httpResponse>::iterator it ; httpResponse httpRe ; if( TRUE == pHttpCon->_isChunk ) { rc = pSession->sendData( REST_STRING_CHUNKED_END, REST_STRING_CHUNKED_END_SIZE, _timeout ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to send data, rc=%d", rc ) ; goto error ; } } else { if( HTTP_OK == rspCode ) { ossSnprintf( httpBodySize, 255, "%d", pHttpCon->_firstRecordSize + pHttpCon->_responseSize ); rc = appendHttpHeader( pSession, REST_STRING_CONLEN, httpBodySize ); if ( rc ) { PD_LOG ( PDERROR, "Failed to call append http header, rc=%d", rc ) ; goto error ; } rc = _setResponseType( pSession ) ; if( rc ) { PD_LOG ( PDERROR, "Failed to set respone type, rc=%d", rc ) ; goto error ; } } else { ossSnprintf( httpBodySize, 255, "0" ) ; rc = appendHttpHeader( pSession, REST_STRING_CONLEN, httpBodySize ); if ( rc ) { PD_LOG ( PDERROR, "Failed to call append http header, rc=%d", rc ) ; goto error ; } } rc = _sendHttpHeader( pSession, rspCode ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to send http header, rc=%d", rc ) ; goto error ; } if( HTTP_OK == rspCode ) { for( it = pHttpCon->_responseBody.begin(); it != pHttpCon->_responseBody.end(); ++it ) { httpRe = (*(it)) ; rc = pSession->sendData( httpRe.pBuffer, httpRe.len, _timeout ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to send data, rc=%d", rc ) ; goto error ; } } } } done: PD_TRACE_EXITRC( SDB__RESTADP_SENDRE, rc ) ; return rc ; error: goto done ; }
static INT32 qgmDumpDetails ( _qgmPlan *op, CHAR *&pBuffer, INT32 &bufferSize, INT32 &id ) { INT32 rc = SDB_OK ; INT32 slen = 0 ; CHAR idBuffer[128] = {0} ; const CHAR *pField = "" ; std::string ps = "" ; ossSnprintf ( idBuffer, sizeof(idBuffer), "(%d) ", id ) ; ++id ; switch ( op->type() ) { case QGM_PLAN_TYPE_INSERT : pField = FIELD_NAME_INSERT ; break ; case QGM_PLAN_TYPE_UPDATE : pField = FIELD_NAME_UPDATE ; break ; case QGM_PLAN_TYPE_DELETE : pField = FIELD_NAME_DELETE ; break ; case QGM_PLAN_TYPE_RETURN : pField = FIELD_NAME_RETURN ; break ; case QGM_PLAN_TYPE_NLJOIN : pField = FIELD_NAME_NLJOIN ; break ; case QGM_PLAN_TYPE_SORT : pField = FIELD_NAME_SORT ; break ; case QGM_PLAN_TYPE_SCAN : pField = FIELD_NAME_SCAN ; break ; case QGM_PLAN_TYPE_FILTER : pField = FIELD_NAME_FILTER ; break ; case QGM_PLAN_TYPE_AGGR : pField = FIELD_NAME_AGGR ; break ; case QGM_PLAN_TYPE_COMMAND : pField = FIELD_NAME_CMD ; break ; case QGM_PLAN_TYPE_SPLIT : pField = FIELD_NAME_SPLITBY ; break ; case QGM_PLAN_TYPE_HASHJOIN : pField = FIELD_NAME_HASHJOIN ; break ; default : rc = SDB_INVALIDARG ; PD_LOG ( PDERROR, "Unsupported operator" ) ; goto error ; } ossStrncat ( idBuffer, pField, ossStrlen ( pField ) ) ; ossStrncat ( idBuffer, OSS_NEWLINE, ossStrlen ( OSS_NEWLINE ) ) ; slen = ossStrlen ( idBuffer ) ; ossSnprintf ( pBuffer, bufferSize, "%s", idBuffer ) ; bufferSize -= slen ; QGM_DUMP_BUFFER_SIZE_CHECK pBuffer += slen ; ps = op->toString() ; pField = ps.c_str() ; slen = ps.size() ; ossSnprintf ( pBuffer, bufferSize, "%s", pField ) ; bufferSize -= slen ; QGM_DUMP_BUFFER_SIZE_CHECK pBuffer += slen ; ossSnprintf ( pBuffer, bufferSize, OSS_NEWLINE ) ; bufferSize -= ossStrlen ( OSS_NEWLINE ) ; pBuffer += ossStrlen ( OSS_NEWLINE ) ; ; QGM_DUMP_BUFFER_SIZE_CHECK for ( UINT32 i = 0; i < op->inputSize(); ++i ) { rc = qgmDumpDetails ( op->input ( i ), pBuffer, bufferSize, id ) ; PD_RC_CHECK ( rc, PDERROR, "Failed to dump details, rc = %d", rc ) ; } done : return rc ; error : goto done ; }
INT32 _pmdExternClient::authenticate( MsgHeader *pMsg ) { #if defined ( SDB_ENGINE ) INT32 rc = SDB_OK ; BSONObj authObj ; BSONElement user, pass ; rc = extractAuthMsg( pMsg, authObj ) ; if ( rc ) { PD_LOG( PDERROR, "Client[%s] extract auth msg failed, rc: %d", clientName(), rc ) ; goto error ; } user = authObj.getField( SDB_AUTH_USER ) ; pass = authObj.getField( SDB_AUTH_PASSWD ) ; _isAuthed = FALSE ; if ( SDB_ROLE_STANDALONE == pmdGetDBRole() ) // not auth { _isAuthed = TRUE ; goto done ; } else if ( SDB_ROLE_OM == pmdGetDBRole() ) { rc = sdbGetOMManager()->authenticate( authObj, _pEDUCB ) ; if ( rc ) { PD_LOG( PDERROR, "Client[%s] authenticate failed[user: %s, " "passwd: %s], rc: %d", clientName(), user.valuestrsafe(), pass.valuestrsafe(), rc ) ; goto error ; } _isAuthed = TRUE ; } else if ( SDB_ROLE_COORD == pmdGetDBRole() ) { INT64 contextID = -1 ; rtnContextBuf buf ; CoordCB *pCoordcb = pmdGetKRCB()->getCoordCB(); rtnCoordProcesserFactory *pProcesserFactory = pCoordcb->getProcesserFactory(); rtnCoordOperator *pOperator = NULL ; pOperator = pProcesserFactory->getOperator( pMsg->opCode ); rc = pOperator->execute( pMsg, _pEDUCB, contextID, &buf ) ; // special handling for password verification when there is no // addrlist specified. Usually this happen when there is only // one coord node before creating the first catalog if ( MSG_AUTH_VERIFY_REQ == pMsg->opCode && SDB_CAT_NO_ADDR_LIST == rc ) { rc = SDB_OK ; _isAuthed = TRUE ; } else if ( rc ) { PD_LOG( PDERROR, "Client[%s] authenticate failed[user: %s, " "passwd: %s], rc: %d", clientName(), user.valuestrsafe(), pass.valuestrsafe(), rc ) ; goto error ; } else { _isAuthed = TRUE ; } } else { MsgHeader *pAuthRes = NULL ; shardCB *pShard = sdbGetShardCB() ; UINT32 retryTimes = 0 ; MsgOpReply replyHeader ; replyHeader.contextID = -1 ; replyHeader.numReturned = 0 ; while ( TRUE ) { ++retryTimes ; rc = pShard->syncSend( pMsg, CATALOG_GROUPID, TRUE, &pAuthRes ) ; if ( SDB_OK != rc ) { rc = pShard->syncSend( pMsg, CATALOG_GROUPID, FALSE, &pAuthRes ) ; PD_RC_CHECK( rc, PDERROR, "Client[%s] failed to send auth " "req to catalog, rc: %d", clientName(), rc ) ; } if ( NULL == pAuthRes ) { rc = SDB_SYS ; PD_LOG( PDERROR, "syncsend return ok but res is NULL" ) ; goto error ; } rc = MSG_GET_INNER_REPLY_RC(pAuthRes) ; replyHeader.flags = rc ; replyHeader.startFrom = MSG_GET_INNER_REPLY_STARTFROM(pAuthRes) ; ossMemcpy( &(replyHeader.header), pAuthRes, sizeof( MsgHeader ) ) ; /// release recv msg SDB_OSS_FREE( (BYTE*)pAuthRes ) ; pAuthRes = NULL ; if ( SDB_CLS_NOT_PRIMARY == rc && retryTimes < PMD_AUTH_RETRY_TIMES ) { INT32 rcTmp = SDB_OK ; rcTmp = pShard->updatePrimaryByReply( &(replyHeader.header) ) ; if ( SDB_NET_CANNOT_CONNECT == rcTmp ) { /// the node is crashed, sleep some seconds PD_LOG( PDWARNING, "Catalog group primary node is crashed " "but other nodes not aware, sleep %d seconds", NET_NODE_FAULTUP_MIN_TIME ) ; ossSleep( NET_NODE_FAULTUP_MIN_TIME * OSS_ONE_SEC ) ; } if ( rcTmp ) { pShard->updateCatGroup( CLS_SHARD_TIMEOUT ) ; } continue ; } else if ( rc ) { PD_LOG( PDERROR, "Client[%s] authenticate failed[user: %s, " "passwd: %s], rc: %d", clientName(), user.valuestrsafe(), pass.valuestrsafe(), rc ) ; goto error ; } else { _isAuthed = TRUE ; } break ; } } done: if ( SDB_OK == rc && _isAuthed ) { _username = user.valuestrsafe() ; if ( !_username.empty() ) { _password = pass.valuestrsafe() ; } _pEDUCB->setUserInfo( _username, _password ) ; _makeName() ; CHAR szTmp[ 16 ] = { 0 } ; ossSnprintf( szTmp, sizeof(szTmp)-1, "%llu", _pEDUCB->getID() ) ; PD_AUDIT_OP( AUDIT_ACCESS, MSG_AUTH_VERIFY_REQ, AUDIT_OBJ_SESSION, szTmp, SDB_OK, "User[UserName:%s, RemoteIP:%s, RemotePort:%u, " "LocalIP:%s, LocalPort:%u] login succeed", getUsername(), getPeerIPAddr(), getPeerPort(), getLocalIPAddr(), getLocalPort() ) ; } return rc ; error: if ( SDB_AUTH_AUTHORITY_FORBIDDEN == rc ) { _pEDUCB->printInfo( EDU_INFO_ERROR, "username or passwd is wrong" ) ; } goto done ; #else _isAuthed = TRUE ; return SDB_OK ; #endif // SDB_ENGINE }
// PD_TRACE_DECLARE_FUNCTION ( SDB_OSSDUMPSIGINFO, "ossDumpSigInfo" ) void ossDumpSigInfo ( oss_siginfo_t pSigInfo, ossPrimitiveFileOp * trapFile ) { PD_TRACE_ENTRY ( SDB_OSSDUMPSIGINFO ); CHAR buf[64] = { 0 } ; CHAR hexNum[10] = { 0 } ; CHAR *bytePtr, ch ; UINT32 i = 0 ; if ( ( NULL != pSigInfo ) && ( NULL != trapFile ) && ( trapFile->isValid() ) ) { trapFile->Write( OSS_NEWLINE"Siginfo_t:"OSS_NEWLINE ) ; buf[0] = '\0' ; bytePtr = ( CHAR * ) pSigInfo ; while ( i < sizeof( siginfo_t ) ) { ch = *bytePtr ; ossSnprintf( hexNum, sizeof( hexNum ), "%02X", (unsigned char)ch ) ; strcat( buf, hexNum ) ; bytePtr++ ; i++ ; if ( i % 16 == 0 ) { trapFile->fWrite( "%s"OSS_NEWLINE, buf ) ; buf[0] = '\0' ; } else if ( i % 4 == 0 ) { strcat( buf, " " ) ; } } if ( 0 != (i % 16) ) { strcat( buf, OSS_NEWLINE ) ; } trapFile->Write( buf ) ; switch (pSigInfo->si_signo) { case SIGBUS: case SIGFPE: case SIGILL: case SIGSEGV: trapFile->fWrite ( "Signal #:%d, si_addr: 0x"OSS_PRIXPTR ", si_code: 0x%08X"OSS_NEWLINE, pSigInfo->si_signo, pSigInfo->si_addr, pSigInfo->si_code) ; break ; case SIGABRT: case SIGINT: case SIGPROF: #if defined SIGSYS case SIGSYS: #endif case SIGTRAP: #if defined SIGURG case SIGURG: #endif #if defined SIGPRE case SIGPRE: #endif trapFile->fWrite ( "Signal #: %d, si_pid: %d, si_uid: %d, " "si_value: %08X"OSS_NEWLINE, pSigInfo->si_signo, pSigInfo->si_pid, pSigInfo->si_uid, pSigInfo->si_value.sival_int ) ; break ; case SIGCHLD: trapFile->fWrite ( "Signal #: %d(SIGCHLD), si_code: %d, " "child_pid: %d, status: 0x%08X"OSS_NEWLINE, pSigInfo->si_signo, pSigInfo->si_code, pSigInfo->si_pid, pSigInfo->si_status ) ; break ; default : trapFile->fWrite ( "Signal #:%d, si_code: %d"OSS_NEWLINE, pSigInfo->si_signo, pSigInfo->si_code ) ; break ; } } PD_TRACE_EXIT ( SDB_OSSDUMPSIGINFO ); }
INT32 _dpsLogFilter::doParse() { INT32 rc = SDB_OK ; BOOLEAN Open = FALSE ; CHAR dstFile[ OSS_MAX_PATHSIZE + 1 ] = { 0 } ; OSSFILE fileFrom, fileTo ; if( isDir( _cmdData->dstPath ) ) { INT32 len = ossStrlen( _cmdData->dstPath ) ; if ( OSS_FILE_SEP_CHAR == _cmdData->dstPath[ len - 1 ] ) { ossSnprintf( dstFile, OSS_MAX_PATHSIZE, "%s%s", _cmdData->dstPath, "tmpLog.log" ) ; } else { ossSnprintf( dstFile, OSS_MAX_PATHSIZE, "%s"OSS_FILE_SEP"%s", _cmdData->dstPath, "tmpLog.log" ) ; } } else { ossSnprintf( dstFile, OSS_MAX_PATHSIZE, "%s", _cmdData->dstPath ) ; } if( !_cmdData->output ) { rc = ossOpen( dstFile, OSS_REPLACE | OSS_READWRITE, OSS_RU | OSS_WU | OSS_RG, fileTo ) ; if( rc ) { printf( "Unable to open file: %s\n", dstFile ) ; goto error ; } Open = TRUE ; } if ( SDB_LOG_FILTER_META == _filter->getType() ) { rc = _filter->doFilte( _cmdData, fileTo, NULL ) ; if( rc ) { goto error ; } goto done ; } if( isDir( _cmdData->srcPath ) ) { if( SDB_LOG_FILTER_LAST == _filter->getType() ) { printf( "Error: Cannot specify a dir path when using --last/-e\n" ); rc = SDB_INVALIDARG ; goto error ; } INT32 const MAX_FILE_COUNT = getFileCount( _cmdData->srcPath ) ; if( 0 >= MAX_FILE_COUNT ) { printf( "Cannot find any Log files\nPlease check" " and input the correct log file path\n" ) ; rc = SDB_INVALIDPATH ; goto error ; } for( INT32 idx = 0 ; idx < MAX_FILE_COUNT ; ++idx ) { fs::path fileDir( _cmdData->srcPath ) ; const CHAR *filepath = fileDir.string().c_str() ; CHAR filename[ OSS_MAX_PATHSIZE * 2 ] = { 0 } ; ossSnprintf( filename, OSS_MAX_PATHSIZE, "%s/sequoiadbLog.%d", filepath, idx ) ; if( !isFileExisted( filename ) ) { rc = SDB_INVALIDPATH ; goto error ; } rc = _filter->doFilte( _cmdData, fileTo, filename ) ; if( rc && idx != MAX_FILE_COUNT - 1 ) { rc = SDB_OK ; continue ; } } } else { if( !isFileExisted( _cmdData->srcPath ) ) { rc = SDB_INVALIDPATH ; goto error ; } rc = _filter->doFilte( _cmdData, fileTo, _cmdData->srcPath ) ; if( rc ) { goto error ; } } done: if( Open ) { ossClose( fileTo ) ; } return rc ; error: goto done ; }
INT32 _omaAddHostSubTask::doit() { INT32 rc = SDB_OK ; INT32 tmpRc = SDB_OK ; _pTask->setSubTaskStatus( _taskName, OMA_TASK_STATUS_RUNNING ) ; while( TRUE ) { AddHostInfo *pInfo = NULL ; AddHostResultInfo resultInfo = { "", "", OMA_TASK_STATUS_INIT, OMA_TASK_STATUS_DESC_INIT, SDB_OK, "" } ; CHAR flow[OMA_BUFF_SIZE + 1] = { 0 } ; const CHAR *pDetail = NULL ; const CHAR *pIP = NULL ; const CHAR *pHostName = NULL ; INT32 errNum = 0 ; BSONObj retObj ; pInfo = _pTask->getAddHostItem() ; if ( NULL == pInfo ) { PD_LOG( PDEVENT, "No hosts need to add now, sub task[%s] exits", _taskName.c_str() ) ; goto done ; } pIP = pInfo->_item._ip.c_str() ; pHostName = pInfo->_item._hostName.c_str() ; resultInfo._ip = pIP ; resultInfo._hostName = pHostName ; ossSnprintf( flow, OMA_BUFF_SIZE, "Adding host[%s]", pIP ) ; resultInfo._status = OMA_TASK_STATUS_RUNNING ; resultInfo._statusDesc = getTaskStatusDesc( OMA_TASK_STATUS_RUNNING ) ; resultInfo._errno = SDB_OK ; resultInfo._detail = "" ; resultInfo._flow.push_back( flow ) ; tmpRc = _pTask->updateProgressToTask( pInfo->_serialNum, resultInfo ) ; if ( tmpRc ) { PD_LOG( PDWARNING, "Failed to update add host[%s]'s progress, " "rc = %d", pIP, tmpRc ) ; } _omaAddHost runCmd( *pInfo ) ; rc = runCmd.init( NULL ) ; if ( rc ) { PD_LOG( PDERROR, "Failed to init for adding " "host[%s], rc = %d", pIP, rc ) ; pDetail = pmdGetThreadEDUCB()->getInfo( EDU_INFO_ERROR ) ; if ( NULL == pDetail || 0 == *pDetail ) pDetail = "Failed to init for adding host " ; ossSnprintf( flow, OMA_BUFF_SIZE, "Failed to add host[%s]", pIP ) ; resultInfo._status = OMA_TASK_STATUS_FINISH ; resultInfo._statusDesc = getTaskStatusDesc( OMA_TASK_STATUS_FINISH ) ; resultInfo._errno = rc ; resultInfo._detail = pDetail ; resultInfo._flow.push_back( flow ) ; rc = _pTask->updateProgressToTask( pInfo->_serialNum, resultInfo ) ; if ( rc ) { PD_LOG( PDWARNING, "Failed to update add host[%s]'s progress, " "rc = %d", pIP, rc ) ; } continue ; } rc = runCmd.doit( retObj ) ; if ( rc ) { PD_LOG( PDERROR, "Failed to do adding host[%s], rc = %d", pIP, rc ) ; tmpRc = omaGetStringElement ( retObj, OMA_FIELD_DETAIL, &pDetail ) ; if ( SDB_OK != tmpRc ) { pDetail = pmdGetThreadEDUCB()->getInfo( EDU_INFO_ERROR ) ; if ( NULL == pDetail || 0 == *pDetail ) pDetail = "Not exeute js file yet" ; } ossSnprintf( flow, OMA_BUFF_SIZE, "Failed to add host[%s]", pIP ) ; resultInfo._status = OMA_TASK_STATUS_FINISH ; resultInfo._statusDesc = getTaskStatusDesc( OMA_TASK_STATUS_FINISH ) ; resultInfo._errno = rc ; resultInfo._detail = pDetail ; resultInfo._flow.push_back( flow ) ; tmpRc = _pTask->updateProgressToTask( pInfo->_serialNum, resultInfo ) ; if ( tmpRc ) { PD_LOG( PDWARNING, "Failed to update add host[%s]'s progress, " "rc = %d", pIP, tmpRc ) ; } continue ; } rc = omaGetIntElement ( retObj, OMA_FIELD_ERRNO, errNum ) ; if ( rc ) { PD_LOG( PDERROR, "Failed to get errno from js after " "adding host[%s], rc = %d", pIP, rc ) ; pDetail = pmdGetThreadEDUCB()->getInfo( EDU_INFO_ERROR ) ; if ( NULL == pDetail || 0 == *pDetail ) pDetail = "Failed to get errno from js after adding host" ; ossSnprintf( flow, OMA_BUFF_SIZE, "Failed to add host[%s]", pIP ) ; resultInfo._status = OMA_TASK_STATUS_FINISH ; resultInfo._statusDesc = getTaskStatusDesc( OMA_TASK_STATUS_FINISH ) ; resultInfo._errno = rc ; resultInfo._detail = pDetail ; resultInfo._flow.push_back( flow ) ; tmpRc =_pTask->updateProgressToTask( pInfo->_serialNum, resultInfo ) ; if ( tmpRc ) { PD_LOG( PDWARNING, "Failed to update add host[%s]'s progress, " "rc = %d", pIP, tmpRc ) ; } continue ; } if ( SDB_OK != errNum ) { rc = omaGetStringElement ( retObj, OMA_FIELD_DETAIL, &pDetail ) ; if ( SDB_OK != rc ) { PD_LOG( PDERROR, "Failed to get error detail from js after " "adding host[%s], rc = %d", pIP, rc ) ; pDetail = pmdGetThreadEDUCB()->getInfo( EDU_INFO_ERROR ) ; if ( NULL == pDetail || 0 == *pDetail ) pDetail = "Failed to get error detail from js after adding host" ; } ossSnprintf( flow, OMA_BUFF_SIZE, "Failed to add host[%s]", pIP ) ; resultInfo._status = OMA_TASK_STATUS_FINISH ; resultInfo._statusDesc = getTaskStatusDesc( OMA_TASK_STATUS_FINISH ) ; resultInfo._errno = errNum ; resultInfo._detail = pDetail ; resultInfo._flow.push_back( flow ) ; tmpRc = _pTask->updateProgressToTask( pInfo->_serialNum, resultInfo ) ; if ( tmpRc ) { PD_LOG( PDWARNING, "Failed to update add host[%s]'s progress, " "rc = %d", pIP, tmpRc ) ; } continue ; } else { ossSnprintf( flow, OMA_BUFF_SIZE, "Finish adding host[%s]", pIP ) ; PD_LOG ( PDEVENT, "Success to add host[%s]", pIP ) ; resultInfo._status = OMA_TASK_STATUS_FINISH ; resultInfo._statusDesc = getTaskStatusDesc( OMA_TASK_STATUS_FINISH ) ; resultInfo._flow.push_back( flow ) ; tmpRc = _pTask->updateProgressToTask( pInfo->_serialNum, resultInfo ) ; if ( tmpRc ) { PD_LOG( PDWARNING, "Failed to update add host[%s]'s progress, " "rc = %d", pIP, tmpRc ) ; } } } done: _pTask->setSubTaskStatus( _taskName, OMA_TASK_STATUS_FINISH ) ; _pTask->notifyUpdateProgress() ; return SDB_OK ; }
INT32 _omaInstDBBusSubTask::doit() { INT32 rc = SDB_OK ; INT32 tmpRc = SDB_OK ; OMA_TASK_STATUS taskStatus ; _pTask->setSubTaskStatus( _taskName, OMA_TASK_STATUS_RUNNING ) ; while( TRUE ) { string instRGName ; instRGName = _pTask->getDataRGToInst() ; if ( instRGName.empty() ) { PD_LOG( PDEVENT, "No data group need to install now, " "sub task[%s] exits", _taskName.c_str() ) ; goto done ; } while( TRUE ) { InstDBBusInfo *pInfo = NULL ; InstDBResult instResult ; CHAR flow[OMA_BUFF_SIZE + 1] = { 0 } ; const CHAR *pDetail = NULL ; const CHAR *pHostName = NULL ; const CHAR *pSvcName = NULL ; INT32 errNum = 0 ; BSONObj retObj ; pInfo = _pTask->getDataNodeInfo( instRGName ) ; if ( NULL == pInfo ) { PD_LOG( PDEVENT, "Finish installing group[%s] in task[%s]", instRGName.c_str(), _taskName.c_str() ) ; break ; } taskStatus = _pTask->getTaskStatus() ; if ( OMA_TASK_STATUS_RUNNING != taskStatus ) { PD_LOG ( PDERROR, "Task's status is: [%d], stop running sub " "task[%s]", taskStatus, _taskName.c_str() ) ; goto done ; } pHostName = pInfo->_instInfo._hostName.c_str() ; pSvcName = pInfo->_instInfo._svcName.c_str() ; instResult._errno = SDB_OK ; instResult._detail = "" ; instResult._hostName = pHostName ; instResult._svcName = pSvcName ; instResult._role = ROLE_DATA ; instResult._groupName = pInfo->_instInfo._dataGroupName ; instResult._status = OMA_TASK_STATUS_RUNNING ; instResult._statusDesc = getTaskStatusDesc( OMA_TASK_STATUS_RUNNING ) ; ossSnprintf( flow, OMA_BUFF_SIZE, "Installing data node[%s:%s]", pHostName, pSvcName ) ; instResult._status = OMA_TASK_STATUS_RUNNING ; instResult._statusDesc = getTaskStatusDesc( OMA_TASK_STATUS_RUNNING ) ; instResult._flow.push_back( flow ) ; rc = _pTask->updateProgressToTask( pInfo->_nodeSerialNum, instResult, TRUE ) ; if ( rc ) { PD_LOG( PDWARNING, "Failed to update install data node[%s:%s]'s " "progress, rc = %d", pHostName, pSvcName, rc ) ; } _omaInstallDataNode runCmd( _taskID, _pTask->getTmpCoordSvcName(), pInfo->_instInfo ) ; rc = runCmd.init( NULL ) ; if ( rc ) { PD_LOG( PDERROR, "Failed to init to install data node[%s:%s], " "rc = %d", pHostName, pSvcName, rc ) ; pDetail = pmdGetThreadEDUCB()->getInfo( EDU_INFO_ERROR ) ; if ( NULL == pDetail || 0 == *pDetail ) pDetail = "Failed to init to install data node" ; goto build_error_result ; } rc = runCmd.doit( retObj ) ; if ( rc ) { PD_LOG( PDERROR, "Failed to install data node[%s:%s], rc = %d", pHostName, pSvcName, rc ) ; tmpRc = omaGetStringElement ( retObj, OMA_FIELD_DETAIL, &pDetail ) ; if ( SDB_OK != tmpRc ) { pDetail = pmdGetThreadEDUCB()->getInfo( EDU_INFO_ERROR ) ; if ( NULL == pDetail || 0 == *pDetail ) pDetail = "Not exeute js file yet" ; } goto build_error_result ; } rc = omaGetIntElement ( retObj, OMA_FIELD_ERRNO, errNum ) ; if ( rc ) { PD_LOG( PDERROR, "Failed to get errno from js after " "installing data node[%s:%s], rc = %d", pHostName, pSvcName, rc ) ; pDetail = pmdGetThreadEDUCB()->getInfo( EDU_INFO_ERROR ) ; if ( NULL == pDetail || 0 == *pDetail ) pDetail = "Failed to get errno from js after " "installing data node" ; goto build_error_result ; } if ( SDB_OK != errNum ) { rc = errNum ; tmpRc = omaGetStringElement ( retObj, OMA_FIELD_DETAIL, &pDetail ) ; if ( SDB_OK != tmpRc ) { PD_LOG( PDERROR, "Failed to get error detail from js after " "installing data node[%s:%s], rc = %d", pHostName, pSvcName, tmpRc ) ; pDetail = pmdGetThreadEDUCB()->getInfo( EDU_INFO_ERROR ) ; if ( NULL == pDetail || 0 == *pDetail ) pDetail = "Failed to get error detail from js " "after installing data node" ; } goto build_error_result ; } else { ossSnprintf( flow, OMA_BUFF_SIZE, "Finish installing data " "node[%s:%s]", pHostName, pSvcName ) ; PD_LOG ( PDEVENT, "Success to install data node[%s:%s]", pHostName, pSvcName ) ; instResult._status = OMA_TASK_STATUS_FINISH ; instResult._statusDesc = getTaskStatusDesc( OMA_TASK_STATUS_FINISH ) ; instResult._flow.push_back( flow ) ; rc = _pTask->updateProgressToTask( pInfo->_nodeSerialNum, instResult, TRUE ) ; if ( rc ) { PD_LOG( PDWARNING, "Failed to update install data " "node[%s:%s]'s progress, rc = %d", pHostName, pSvcName, rc ) ; } } continue ; // if we success, nerver go to "build_error_result" build_error_result: ossSnprintf( flow, OMA_BUFF_SIZE, "Failed to install data " "node[%s:%s], going to rollback", pHostName, pSvcName ) ; instResult._status = OMA_TASK_STATUS_ROLLBACK ; instResult._statusDesc = getTaskStatusDesc( OMA_TASK_STATUS_ROLLBACK ) ; instResult._errno = rc ; instResult._detail = pDetail ; instResult._flow.push_back( flow ) ; tmpRc = _pTask->updateProgressToTask( pInfo->_nodeSerialNum, instResult, TRUE ) ; if ( SDB_OK != tmpRc ) { PD_LOG( PDWARNING, "Failed to update install coord[%s:%s]'s " "progress, rc = %d", pHostName, pSvcName, tmpRc ) ; } goto error ; } // while } // while done: _pTask->setSubTaskStatus( _taskName, OMA_TASK_STATUS_FINISH ) ; _pTask->notifyUpdateProgress() ; return rc ; error: goto done ; }
INT32 _qgmPtrTable::getUniqueTableAlias( qgmField & field ) { CHAR uniqueName[20] = {0} ; ossSnprintf( uniqueName, 19, "$SYS_T%d", ++_uniqueTableID ) ; return getOwnField( uniqueName, field ) ; }