/* ** Initialize a Read-Only caching space. */ void mdlROcache(MDL mdl,int cid,void *pData,int iDataSize,int nData) { CACHE *c; c = CacheInitialize(mdl,cid,pData,iDataSize,nData); c->iType = MDL_ROCACHE; c->init = NULL; c->combine = NULL; }
/* ** Initialize a Combiner caching space. */ void mdlCOcache(MDL mdl,int cid,void *pData,int iDataSize,int nData, void (*init)(void *),void (*combine)(void *,void *)) { CACHE *c; c = CacheInitialize(mdl,cid,pData,iDataSize,nData); c->iType = MDL_COCACHE; c->init = init; c->combine = combine; }
static HRESULT RunNormal( __in HINSTANCE hInstance, __in BURN_ENGINE_STATE* pEngineState ) { HRESULT hr = S_OK; HANDLE hPipesCreatedEvent = NULL; BOOL fContinueExecution = TRUE; BOOL fReloadApp = FALSE; // Initialize logging. hr = LoggingOpen(&pEngineState->log, &pEngineState->variables, pEngineState->command.display, pEngineState->registration.sczDisplayName); ExitOnFailure(hr, "Failed to open log."); // Ensure the cache functions are initialized since we might use them soon. hr = CacheInitialize(&pEngineState->registration, &pEngineState->variables); ExitOnFailure(hr, "Failed to initialize internal cache functionality."); // When launched explicitly unelevated, create the pipes so the elevated process can connect. if (BURN_ELEVATION_STATE_UNELEVATED_EXPLICITLY == pEngineState->elevationState) { Assert(pEngineState->companionConnection.dwProcessId); Assert(pEngineState->companionConnection.sczName); Assert(pEngineState->companionConnection.sczSecret); Assert(!pEngineState->companionConnection.hProcess); Assert(INVALID_HANDLE_VALUE == pEngineState->companionConnection.hPipe); Assert(INVALID_HANDLE_VALUE == pEngineState->companionConnection.hCachePipe); hr = PipeCreatePipes(&pEngineState->companionConnection, TRUE, &hPipesCreatedEvent); ExitOnFailure(hr, "Failed to create pipes to connect to elevated parent process."); hr = PipeWaitForChildConnect(&pEngineState->companionConnection); ExitOnFailure(hr, "Failed to connect to elevated parent process."); ReleaseHandle(hPipesCreatedEvent); } // Ensure we're on a supported operating system. hr = ConditionGlobalCheck(&pEngineState->variables, &pEngineState->condition, pEngineState->command.display, pEngineState->registration.sczDisplayName, &pEngineState->userExperience.dwExitCode, &fContinueExecution); ExitOnFailure(hr, "Failed to check global conditions"); if (!fContinueExecution) { LogId(REPORT_STANDARD, MSG_FAILED_CONDITION_CHECK); // If the block told us to abort, abort! ExitFunction1(hr = S_OK); } if (pEngineState->userExperience.fSplashScreen && BOOTSTRAPPER_DISPLAY_NONE < pEngineState->command.display) { SplashScreenCreate(hInstance, NULL, &pEngineState->command.hwndSplashScreen); } // Create a top-level window to handle system messages. hr = UiCreateMessageWindow(hInstance, pEngineState); ExitOnFailure(hr, "Failed to create the message window."); // Query registration state. hr = CoreQueryRegistration(pEngineState); ExitOnFailure(hr, "Failed to query registration."); // Set some built-in variables before loading the BA. hr = PlanSetVariables(pEngineState->command.action, &pEngineState->variables); ExitOnFailure(hr, "Failed to set action variables."); hr = RegistrationSetVariables(&pEngineState->registration, &pEngineState->variables); ExitOnFailure(hr, "Failed to set registration variables."); // If a layout directory was specified on the command-line, set it as a well-known variable. if (pEngineState->command.wzLayoutDirectory && *pEngineState->command.wzLayoutDirectory) { hr = VariableSetString(&pEngineState->variables, BURN_BUNDLE_LAYOUT_DIRECTORY, pEngineState->command.wzLayoutDirectory, FALSE); ExitOnFailure(hr, "Failed to set layout directory variable to value provided from command-line."); } do { fReloadApp = FALSE; hr = RunApplication(pEngineState, &fReloadApp); ExitOnFailure(hr, "Failed while running "); } while (fReloadApp); LExit: // If the message window is still around, close it. UiCloseMessageWindow(pEngineState); VariablesDump(&pEngineState->variables); // end per-machine process if running if (INVALID_HANDLE_VALUE != pEngineState->companionConnection.hPipe) { PipeTerminateChildProcess(&pEngineState->companionConnection, pEngineState->userExperience.dwExitCode, (BURN_ELEVATION_STATE_UNELEVATED_EXPLICITLY == pEngineState->elevationState) ? pEngineState->fRestart : FALSE); } // If the splash screen is still around, close it. if (::IsWindow(pEngineState->command.hwndSplashScreen)) { ::PostMessageW(pEngineState->command.hwndSplashScreen, WM_CLOSE, 0, 0); } ReleaseHandle(hPipesCreatedEvent); return hr; }
/* ** Initialize a Read-Only caching space. */ void mdlROcache(MDL mdl,int cid,void *pData,int iDataSize,int nData) { CACHE *c; int id; CAHEAD caIn; char achDiag[256]; /* SHMEM */ int i; long lTemp; c = CacheInitialize(mdl,cid,pData,iDataSize,nData); c->iType = MDL_ROCACHE; /* ** For an ROcache these two functions are not needed. */ c->init = NULL; c->combine = NULL; sprintf(achDiag, "%d: before CI, cache %d\n", mdl->idSelf, cid); mdlDiag(mdl, achDiag); /* ** THIS IS A SYNCHRONIZE!!! */ caIn.cid = cid; caIn.mid = MDL_MID_CACHEIN; caIn.id = mdl->idSelf; if(mdl->idSelf == 0) { c->nCheckIn = 1; while(c->nCheckIn < mdl->nThreads) { mdlCacheReceive(mdl, NULL); } } else { /* ** Must use non-blocking sends here, we will never wait ** for these sends to complete, but will know for sure ** that they have completed. */ MPI_Send(&caIn,sizeof(CAHEAD),MPI_BYTE, 0, MDL_TAG_CACHECOM, MPI_COMM_WORLD); } sprintf(achDiag, "%d: In CI, cache %d\n", mdl->idSelf, cid); mdlDiag(mdl, achDiag); if(mdl->idSelf == 0) { for(id = 1; id < mdl->nThreads; id++) { MPI_Send(&caIn,sizeof(CAHEAD),MPI_BYTE, id, MDL_TAG_CACHECOM, MPI_COMM_WORLD); } } else { c->nCheckIn = 0; while (c->nCheckIn == 0) { mdlCacheReceive(mdl,NULL); } } sprintf(achDiag, "%d: After CI, cache %d\n", mdl->idSelf, cid); mdlDiag(mdl, achDiag); AdjustDataSize(mdl); MPI_Barrier(MPI_COMM_WORLD); /* SHMEM */ lTemp = (long) nData; shmem_fcollect(shmem_array,&lTemp,1,0,0,mdl->nThreads,pSync); c->pDataMax=0; for (i=0;i<mdl->nThreads;++i) { if (c->pDataMax < shmem_array[i]) c->pDataMax=shmem_array[i]; } c->pDataMax *= iDataSize; mdlDiag(mdl, "After RO shmem_collect\n"); /* ** Set up array to track pData on all other PEs. */ lTemp = (long) pData; shmem_fcollect(c->shmem_pData,&lTemp,1,0,0,mdl->nThreads,pSync); /*if (mdl->idSelf==0) { * for (i=0;i<mdl->nThreads;++i) * fprintf(stderr,"i: %d shmem_pData: %ld\n",i,c->shmem_pData[i]); *}*/ mdlDiag(mdl, "After RO shmem_pData exchange\n"); }
/** * CCore * * Creates a new shroudBNC application object. * * @param Config the main config object * @param argc argument counts * @param argv program arguments */ CCore::CCore(CConfig *Config, int argc, char **argv) { int i; m_Log = NULL; m_PidFile = NULL; WritePidFile(); m_Config = Config; m_SSLContext = NULL; m_SSLClientContext = NULL; m_Status = Status_Running; CacheInitialize(m_ConfigCache, Config, "system."); char *SourcePath = strdup(BuildPathLog("sbnc.log")); rename(SourcePath, BuildPathLog("sbnc.log.old")); free(SourcePath); m_PollFds.Preallocate(SFD_SETSIZE); m_Log = new CLog("sbnc.log", true); if (m_Log == NULL) { printf("Log system could not be initialized. Shutting down."); exit(EXIT_FAILURE); } m_Log->Clear(); Log("Log system initialized."); g_Bouncer = this; m_Config = Config; m_Args.SetList(argv, argc); m_Ident = new CIdentSupport(); m_Config = new CConfig("sbnc.conf", NULL); CacheInitialize(m_ConfigCache, m_Config, "system."); const char *Users; CUser *User; if ((Users = m_Config->ReadString("system.users")) == NULL) { if (!MakeConfig()) { Log("Configuration file could not be created."); Fatal(); } printf("Configuration has been successfully saved. Please restart shroudBNC now.\n"); exit(EXIT_SUCCESS); } const char *Args; int Count; Args = ArgTokenize(Users); if (AllocFailed(Args)) { Fatal(); } Count = ArgCount(Args); for (i = 0; i < Count; i++) { const char *Name = ArgGet(Args, i + 1); User = new CUser(Name); if (AllocFailed(User)) { Fatal(); } m_Users.Add(Name, User); } ArgFree(Args); m_Listener = NULL; m_ListenerV6 = NULL; m_SSLListener = NULL; m_SSLListenerV6 = NULL; time(&m_Startup); m_LoadingModules = false; m_LoadingListeners = false; InitializeSocket(); m_Capabilities = new CVector<const char *>(); m_Capabilities->Insert("multi-prefix"); m_Capabilities->Insert("znc.in/server-time-iso"); }
/* ** Initialize a combiner caching space. */ void mdlCOcache(MDL mdl,int cid,void *pData,int iDataSize,int nData, void (*init)(void *),void (*combine)(void *,void *)) { CACHE *c; int i,id; CAHEAD caIn; long lTemp; c = CacheInitialize(mdl,cid,pData,iDataSize,nData); c->iType = MDL_COCACHE; assert(init); c->init = init; assert(combine); c->combine = combine; mdlDiag(mdl, "Before CO sync\n"); /* ** THIS IS A SYNCHRONIZE!!! */ caIn.cid = cid; caIn.mid = MDL_MID_CACHEIN; caIn.id = mdl->idSelf; if(mdl->idSelf == 0) { c->nCheckIn = 1; while(c->nCheckIn < mdl->nThreads) { mdlCacheReceive(mdl, NULL); } } else { /* ** Must use non-blocking sends here, we will never wait ** for these sends to complete, but will know for sure ** that they have completed. */ MPI_Send(&caIn,sizeof(CAHEAD),MPI_CHAR, 0, MDL_TAG_CACHECOM, MPI_COMM_WORLD); } mdlDiag(mdl, "After sends CO sync\n"); if(mdl->idSelf == 0) { for(id = 1; id < mdl->nThreads; id++) { MPI_Send(&caIn,sizeof(CAHEAD),MPI_CHAR, id, MDL_TAG_CACHECOM, MPI_COMM_WORLD); } } else { c->nCheckIn = 0; while (c->nCheckIn == 0) { mdlCacheReceive(mdl,NULL); } } mdlDiag(mdl, "After CO sync\n"); AdjustDataSize(mdl); lTemp = (long) nData; shmem_fcollect(shmem_array,&lTemp,1,0,0,mdl->nThreads,pSync); c->pDataMax=0; for (i=0;i<mdl->nThreads;++i) { if (c->pDataMax < shmem_array[i]) c->pDataMax=shmem_array[i]; } c->pDataMax *= iDataSize; mdlDiag(mdl, "After CO shmem_collect\n"); /* ** Set up array to track pData on all other PEs. */ lTemp = (long) pData; shmem_fcollect(c->shmem_pData,&lTemp,1,0,0,mdl->nThreads,pSync); if (mdl->idSelf==0) { for (i=0;i<mdl->nThreads;++i) fprintf(stderr,"i: %d shmem_pData: %ld\n",i,c->shmem_pData[i]); } mdlDiag(mdl, "After CO shmem_pData exchange\n"); }