RU32 RPAL_EXPORT RPAL_THREAD_FUNC rpHcpI_entry ( rpHCPModuleContext* moduleContext ) { RU32 ret = (RU32)(-1); rThread hMain = 0; if( NULL != moduleContext ) { g_Module_Context = moduleContext; if( rpal_initialize( moduleContext->rpalContext, g_current_Module_id ) ) { ret = (RU32)(-2); if( 0 != ( hMain = rpal_thread_new( RpHcpI_mainThread, g_Module_Context->isTimeToStop ) ) ) { rpal_debug_info( "main module worker started" ); ret = 0; while( TRUE ) { if( rpal_thread_wait( hMain, ( 1 * 1000 ) ) ) { break; } } rpal_debug_info( "main module worker finished" ); rpal_thread_free( hMain ); } else { rpal_debug_error( "failed spawning module main worker" ); } rpal_Context_cleanup(); rpal_Context_deinitialize(); } else { rpal_debug_error( "failed IFace init" ); } } return ret; }
int main ( int argc, char* argv[] ) { int ret = 1; RU32 i = 0; CU_pSuite suite = NULL; UNREFERENCED_PARAMETER( argc ); UNREFERENCED_PARAMETER( argv ); rpal_initialize( NULL, 1 ); for( i = 0; i < 1000000; i++ ) { CU_initialize_registry(); if( NULL != ( suite = CU_add_suite( "obsLib", NULL, NULL ) ) ) { if( NULL != CU_add_test( suite, "createAndDestroy", test_CreateAndDestroy ) && NULL != CU_add_test( suite, "addPattern", test_addPattern ) && NULL != CU_add_test( suite, "singlePattern", test_singlePattern ) && NULL != CU_add_test( suite, "multiPattern", test_multiPattern ) ) { ret = 0; } } CU_basic_run_tests(); CU_cleanup_registry(); } rpal_Context_cleanup(); if( 0 != rpal_memory_totalUsed() ) { ret = -1; } rpal_Context_deinitialize(); return ret; }
int main ( int argc, char* argv[] ) { int ret = 1; CU_pSuite suite = NULL; #ifdef RPAL_PLATFORM_WINDOWS RCHAR strSeDebug[] = "SeDebugPrivilege"; Get_Privilege( strSeDebug ); #endif UNREFERENCED_PARAMETER( argc ); UNREFERENCED_PARAMETER( argv ); rpal_initialize( NULL, 1 ); CU_initialize_registry(); if( NULL != ( suite = CU_add_suite( "raptd", NULL, NULL ) ) ) { if( NULL == CU_add_test( suite, "procEntries", test_procEntries ) || NULL == CU_add_test( suite, "processInfo", test_processInfo ) || NULL == CU_add_test( suite, "modules", test_modules ) || NULL == CU_add_test( suite, "memmap", test_memmap ) || NULL == CU_add_test( suite, "handles", test_handles ) || NULL == CU_add_test( suite, "services", test_servicesList ) || NULL == CU_add_test( suite, "memoryLeaks", test_memoryLeaks ) ) { ret = 0; } } CU_basic_run_tests(); CU_cleanup_registry(); rpal_Context_deinitialize(); return ret; }
RBOOL rpHostCommonPlatformLib_launch ( RU8 configHint, RPNCHAR primaryHomeUrl, RPNCHAR secondaryHomeUrl ) { RBOOL isInitSuccessful = FALSE; rSequence staticConfig = NULL; RPCHAR tmpStr = NULL; rSequence tmpSeq = NULL; RPU8 tmpBuffer = NULL; RU32 tmpSize = 0; RU16 tmpPort = 0; rpal_debug_info( "launching hcp" ); #ifdef RPAL_PLATFORM_WINDOWS if( setGlobalCrashHandler() && SetConsoleCtrlHandler( (PHANDLER_ROUTINE)ctrlHandler, TRUE ) ) { rpal_debug_info( "global crash handler set" ); } else { rpal_debug_warning( "error setting global crash handler" ); } #endif if( 1 == rInterlocked_increment32( &g_hcpContext.isRunning ) ) { if( rpal_initialize( NULL, RPAL_COMPONENT_HCP ) ) { CryptoLib_init(); if( NULL == ( g_hcpContext.cloudConnectionMutex = rMutex_create() ) || NULL == ( g_hcpContext.isCloudOnline = rEvent_create( TRUE ) ) ) { rMutex_free( g_hcpContext.cloudConnectionMutex ); rpal_debug_error( "could not create cloud connection mutex or event" ); return FALSE; } g_hcpContext.currentId.raw = g_idTemplate.raw; // We attempt to load some initial config from the serialized // rSequence that can be patched in this binary. if( NULL != ( staticConfig = getStaticConfig() ) ) { if( rSequence_getSTRINGA( staticConfig, RP_TAGS_HCP_PRIMARY_URL, &tmpStr ) && rSequence_getRU16( staticConfig, RP_TAGS_HCP_PRIMARY_PORT, &tmpPort ) ) { g_hcpContext.primaryUrl = rpal_string_strdupA( tmpStr ); g_hcpContext.primaryPort = tmpPort; rpal_debug_info( "loading primary url from static config" ); } if( rSequence_getSTRINGA( staticConfig, RP_TAGS_HCP_SECONDARY_URL, &tmpStr ) && rSequence_getRU16( staticConfig, RP_TAGS_HCP_SECONDARY_PORT, &tmpPort ) ) { g_hcpContext.secondaryUrl = rpal_string_strdupA( tmpStr ); g_hcpContext.secondaryPort = tmpPort; rpal_debug_info( "loading secondary url from static config" ); } if( rSequence_getSEQUENCE( staticConfig, RP_TAGS_HCP_ID, &tmpSeq ) ) { g_hcpContext.currentId = seqToHcpId( tmpSeq ); rpal_debug_info( "loading default id from static config" ); } if( rSequence_getBUFFER( staticConfig, RP_TAGS_HCP_C2_PUBLIC_KEY, &tmpBuffer, &tmpSize ) ) { setC2PublicKey( rpal_memory_duplicate( tmpBuffer, tmpSize ) ); rpal_debug_info( "loading c2 public key from static config" ); } if( rSequence_getBUFFER( staticConfig, RP_TAGS_HCP_ROOT_PUBLIC_KEY, &tmpBuffer, &tmpSize ) ) { setRootPublicKey( rpal_memory_duplicate( tmpBuffer, tmpSize ) ); rpal_debug_info( "loading root public key from static config" ); } if( rSequence_getSTRINGA( staticConfig, RP_TAGS_HCP_DEPLOYMENT_KEY, &tmpStr ) ) { g_hcpContext.deploymentKey = rpal_string_strdupA( tmpStr ); rpal_debug_info( "loading deployment key from static config" ); } rSequence_free( staticConfig ); } // Now we will override the defaults (if present) with command // line parameters. if( NULL != primaryHomeUrl && 0 != rpal_string_strlen( primaryHomeUrl ) ) { if( NULL != g_hcpContext.primaryUrl ) { rpal_memory_free( g_hcpContext.primaryUrl ); g_hcpContext.primaryUrl = NULL; } g_hcpContext.primaryUrl = rpal_string_ntoa( primaryHomeUrl ); } if( NULL != secondaryHomeUrl && 0 != rpal_string_strlen( secondaryHomeUrl ) ) { if( NULL != g_hcpContext.secondaryUrl ) { rpal_memory_free( g_hcpContext.secondaryUrl ); g_hcpContext.secondaryUrl = NULL; } g_hcpContext.secondaryUrl = rpal_string_ntoa( secondaryHomeUrl ); } g_hcpContext.enrollmentToken = NULL; g_hcpContext.enrollmentTokenSize = 0; getStoreConf(); /* Sets the agent ID platform. */ // Set the current configId g_hcpContext.currentId.id.configId = configHint; if( startBeacons() ) { isInitSuccessful = TRUE; } else { rpal_debug_warning( "error starting beacons" ); } CryptoLib_deinit(); } else { rpal_debug_warning( "hcp platform could not init rpal" ); } } else { rInterlocked_decrement32( &g_hcpContext.isRunning ); rpal_debug_info( "hcp already launched" ); } return isInitSuccessful; }