bool ScopeSync::saveConfigurationAs() { File configurationFileDirectory = getConfigurationDirectory(); FileChooser fileChooser("Save Configuration File As...", configurationFileDirectory, "*.configuration"); if (fileChooser.browseForFileToSave(true)) { String fileName = fileChooser.getResult().getFullPathName(); if (File::isAbsolutePath(fileName)) { configuration->setLastFailedFile(configuration->getFile()); configuration->setFile(File(fileName)); getConfigurationRoot().setProperty(Ids::ID, createAlphaNumericUID(), nullptr); saveConfiguration(); } applyConfiguration(); UserSettings::getInstance()->addActionListener(this); UserSettings::getInstance()->rebuildFileLibrary(true, false, false); return true; } else return false; }
void cloneFileInfoToDali(StringArray ¬Found, IPropertyTree *packageMap, const char *lookupDaliIp, IConstWUClusterInfo *dstInfo, const char *srcCluster, const char *remotePrefix, bool overWrite, IUserDescriptor* userdesc, bool allowForeignFiles) { StringBuffer user; StringBuffer password; if (userdesc) { userdesc->getUserName(user); userdesc->getPassword(password); } Owned<IReferencedFileList> wufiles = createReferencedFileList(user, password, allowForeignFiles, false); wufiles->addFilesFromPackageMap(packageMap); SCMStringBuffer processName; dstInfo->getRoxieProcess(processName); wufiles->resolveFiles(processName.str(), lookupDaliIp, remotePrefix, srcCluster, !overWrite, false); StringBuffer defReplicateFolder; getConfigurationDirectory(NULL, "data2", "roxie", processName.str(), defReplicateFolder); Owned<IDFUhelper> helper = createIDFUhelper(); wufiles->cloneAllInfo(helper, overWrite, true, false, dstInfo->getRoxieRedundancy(), dstInfo->getChannelsPerNode(), dstInfo->getRoxieReplicateOffset(), defReplicateFolder); Owned<IReferencedFileIterator> iter = wufiles->getFiles(); ForEach(*iter) { IReferencedFile &item = iter->query(); if (item.getFlags() & (RefFileNotFound | RefFileNotOnSource)) notFound.append(item.getLogicalName()); } }
void openEspLogFile(IPropertyTree* envpt, IPropertyTree* procpt) { StringBuffer logdir; if(procpt->hasProp("@name")) { StringBuffer espNameStr; procpt->getProp("@name", espNameStr); if (!getConfigurationDirectory(envpt->queryPropTree("Software/Directories"), "log", "esp", espNameStr.str(), logdir)) { logdir.clear(); } } if(logdir.length() == 0) { if(procpt->hasProp("@logDir")) procpt->getProp("@logDir", logdir); } Owned<IComponentLogFileCreator> lf = createComponentLogFileCreator(logdir.str(), "esp"); lf->setName("esp_main");//override default filename lf->setAliasName("esp"); lf->beginLogging(); if (procpt->getPropBool("@enableSysLog", false)) UseSysLogForOperatorMessages(); }
int main( int argc, char *argv[] ) { int res=0; if (argc < 3) { printf ("frunssh <nodelistfile> \"command\" [options] \n" " options: -i:<identity-file> \n" " -u:<user> \n" " -n:<number_of_threads>\n" " -t:<connect-timeout-secs>\n" " -a:<connect-attempts>\n" " -d:<working_directory>\n" " -s -- strict, must match known_hosts\n" " -b -- background\n" " -pw:<password> -- INSECURE: requires pssh (NB identity file preferred)\n" " -pe:<password> -- INSECURE: as -pw except encrypted password\n" " -pl -- use plink (on windows)\n" " -v -- verbose, lists commands run\n" " -d -- dry run (for testing, enables verbose)\n" ); return 255; } InitModuleObjects(); try { StringBuffer logname; splitFilename(argv[0], NULL, NULL, &logname, NULL); StringBuffer logdir; if (getConfigurationDirectory(NULL,"log","frunssh",logname.str(),logdir)) { recursiveCreateDirectory(logdir.str()); StringBuffer tmp(logname); addPathSepChar(logname.clear().append(logdir)).append(tmp); } addFileTimestamp(logname, true); logname.append(".log"); appendLogFile(logname.str(),0,false); queryStderrLogMsgHandler()->setMessageFields(MSGFIELD_prefix); Owned<IFRunSSH> runssh = createFRunSSH(); runssh->init(argc,argv); runssh->exec(); } catch(IException *e) { EXCLOG(e,"frunssh"); e->Release(); res=255; } releaseAtoms(); return res; }
NamedMutex::NamedMutex(const char *name) { { CriticalBlock b(lockPrefixCS); if (0 == lockPrefix.length()) { if (!getConfigurationDirectory(NULL, "lock", NULL, NULL, lockPrefix)) throw MakeStringException(0, "Failed to get lock directory from environment"); } addPathSepChar(lockPrefix); lockPrefix.append("JLIBMUTEX_"); } StringBuffer tmp(lockPrefix); tmp.append("JLIBMUTEX_").append(name); mutexfname = tmp.detach(); }
int main(int argc, const char *argv[]) { InitModuleObjects(); EnableSEHtoExceptionMapping(); NoQuickEditSection xxx; Owned<IFile> file = createIFile("dfuserver.xml"); if (file->exists()) globals.setown(createPTreeFromXMLFile("dfuserver.xml", ipt_caseInsensitive)); else globals.setown(readOldIni()); for (unsigned i=1;i<(unsigned)argc;i++) { const char *arg = argv[i]; StringBuffer prop("@"); StringBuffer val; while (*arg && *arg != '=') prop.append(*arg++); if (*arg) { arg++; while (isspace(*arg)) arg++; val.append(arg); prop.clip(); val.clip(); if (prop.length()>1) globals->setProp(prop.str(), val.str()); } } StringBuffer daliServer; StringBuffer queue; if (!globals->getProp("@DALISERVERS", daliServer)||!globals->getProp("@QUEUE", queue)) { usage(); globals.clear(); releaseAtoms(); return 1; } Owned<IFile> sentinelFile; bool stop = globals->getPropInt("@STOP",0)!=0; if (!stop) { sentinelFile.setown(createSentinelTarget()); removeSentinelFile(sentinelFile); StringBuffer logname; StringBuffer logdir; if (!getConfigurationDirectory(globals->queryPropTree("Directories"),"log","dfuserver",globals->queryProp("@name"),logdir)) globals->getProp("@LOG_DIR", logdir); if (logdir.length() && recursiveCreateDirectory(logdir.str())) logname.append(logdir); else appendCurrentDirectory(logname, true); if (logname.length() && logname.charAt(logname.length()-1) != PATHSEPCHAR) logname.append(PATHSEPCHAR); logname.append("dfuserver"); StringBuffer aliasLogName(logname); aliasLogName.append(".log"); fileMsgHandler = getRollingFileLogMsgHandler(logname.str(), ".log", MSGFIELD_STANDARD, false, true, NULL, aliasLogName.str()); queryLogMsgManager()->addMonitorOwn(fileMsgHandler, getCategoryLogMsgFilter(MSGAUD_all, MSGCLS_all, 1000)); } StringBuffer ftslogdir; if (getConfigurationDirectory(globals->queryPropTree("Directories"),"log","ftslave",globals->queryProp("@name"),ftslogdir)) // NB instance deliberately dfuserver's setFtSlaveLogDir(ftslogdir.str()); setRemoteSpawnSSH( globals->queryProp("SSH/@SSHidentityfile"), globals->queryProp("SSH/@SSHusername"), globals->queryProp("SSH/@SSHpassword"), globals->getPropInt("SSH/@SSHtimeout",0), globals->getPropInt("SSH/@SSHretries",3), "run_"); bool enableSNMP = globals->getPropInt("@enableSNMP")!=0; CSDSServerStatus *serverstatus=NULL; Owned<IReplicateServer> replserver; try { Owned<IGroup> serverGroup = createIGroup(daliServer.str(),DALI_SERVER_PORT); initClientProcess(serverGroup, DCR_DfuServer, 0, NULL, NULL, stop?(1000*30):MP_WAIT_FOREVER); setPasswordsFromSDS(); if(!stop) { if (globals->getPropBool("@enableSysLog",true)) UseSysLogForOperatorMessages(); serverstatus = new CSDSServerStatus("DFUserver"); setDaliServixSocketCaching(true); // speeds up lixux operations startLogMsgParentReceiver(); // for auditing connectLogMsgManagerToDali(); engine.setown(createDFUengine()); addAbortHandler(exitDFUserver); } const char *q = queue.str(); loop { StringBuffer subq; const char *comma = strchr(q,','); if (comma) subq.append(comma-q,q); else subq.append(q); if (stop) { stopDFUserver(subq.str()); } else { StringBuffer mask; mask.appendf("Queue[@name=\"%s\"][1]",subq.str()); IPropertyTree *t=serverstatus->queryProperties()->queryPropTree(mask.str()); if (t) t->setPropInt("@num",t->getPropInt("@num",0)+1); else { t = createPTree(); t->setProp("@name",subq.str()); t->setPropInt("@num",1); serverstatus->queryProperties()->addPropTree("Queue",t); } serverstatus->commitProperties(); engine->setDefaultTransferBufferSize((size32_t)globals->getPropInt("@transferBufferSize")); engine->startListener(subq.str(),serverstatus); } if (!comma) break; q = comma+1; if (!*q) break; } q = globals->queryProp("@MONITORQUEUE"); if (q&&*q) { if (stop) { stopDFUserver(q); } else { IPropertyTree *t=serverstatus->queryProperties()->addPropTree("MonitorQueue",createPTree()); t->setProp("@name",q); engine->startMonitor(q,serverstatus,globals->getPropInt("@MONITORINTERVAL",60)*1000); } } q = globals->queryProp("@REPLICATEQUEUE"); if (q&&*q) { if (stop) { // TBD? } else { replserver.setown(createReplicateServer(q)); replserver->runServer(); } } if (!stop) { serverstatus->commitProperties(); writeSentinelFile(sentinelFile); engine->joinListeners(); if (replserver.get()) replserver->stopServer(); LOG(MCprogress, unknownJob, "Exiting"); } } catch(IException *e){ EXCLOG(e, "DFU Server Exception: "); e->Release(); } catch (const char *s) { WARNLOG("DFU: %s",s); } delete serverstatus; if (stop) Sleep(2000); // give time to stop engine.clear(); globals.clear(); closeEnvironment(); closedownClientProcess(); UseSysLogForOperatorMessages(false); setDaliServixSocketCaching(false); releaseAtoms(); return 0; }
int main( int argc, char *argv[] ) { #if defined(WIN32) && defined(_DEBUG) int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG ); tmpFlag |= _CRTDBG_LEAK_CHECK_DF; _CrtSetDbgFlag( tmpFlag ); #endif InitModuleObjects(); addAbortHandler(ControlHandler); EnableSEHtoExceptionMapping(); dummyProc(); #ifndef __64BIT__ // Restrict stack sizes on 32-bit systems Thread::setDefaultStackSize(0x10000); // NB under windows requires linker setting (/stack:) #endif #ifdef _WIN32 Owned<CReleaseMutex> globalNamedMutex; #endif if (globals) globals->Release(); { Owned<IFile> iFile = createIFile("thor.xml"); globals = iFile->exists() ? createPTree(*iFile, ipt_caseInsensitive) : createPTree("Thor", ipt_caseInsensitive); } unsigned multiThorMemoryThreshold = 0; Owned<IException> unregisterException; try { if (argc==1) { usage(); return 1; } cmdArgs = argv+1; mergeCmdParams(globals); cmdArgs = argv+1; const char *master = globals->queryProp("@MASTER"); if (!master) usage(); const char *slave = globals->queryProp("@SLAVE"); if (slave) { slfEp.set(slave); localHostToNIC(slfEp); } else slfEp.setLocalHost(0); mySlaveNum = globals->getPropInt("@SLAVENUM"); setMachinePortBase(slfEp.port); slfEp.port = getMachinePortBase(); startSlaveLog(); setSlaveAffinity(globals->getPropInt("@SLAVEPROCESSNUM")); startMPServer(getFixedPort(TPORT_mp)); #ifdef USE_MP_LOG startLogMsgParentReceiver(); LOG(MCdebugProgress, thorJob, "MPServer started on port %d", getFixedPort(TPORT_mp)); #endif SocketEndpoint masterEp(master); localHostToNIC(masterEp); setMasterPortBase(masterEp.port); markNodeCentral(masterEp); if (RegisterSelf(masterEp)) { if (globals->getPropBool("Debug/@slaveDaliClient")) enableThorSlaveAsDaliClient(); IDaFileSrvHook *daFileSrvHook = queryDaFileSrvHook(); if (daFileSrvHook) // probably always installed daFileSrvHook->addFilters(globals->queryPropTree("NAS"), &slfEp); StringBuffer thorPath; globals->getProp("@thorPath", thorPath); recursiveCreateDirectory(thorPath.str()); int err = _chdir(thorPath.str()); if (err) { IException *e = makeErrnoExceptionV(-1, "Failed to change dir to '%s'", thorPath.str()); FLLOG(MCexception(e), thorJob, e); throw e; } // Initialization from globals setIORetryCount(globals->getPropInt("Debug/@ioRetries")); // default == 0 == off StringBuffer str; if (globals->getProp("@externalProgDir", str.clear())) _mkdir(str.str()); else globals->setProp("@externalProgDir", thorPath); const char * overrideBaseDirectory = globals->queryProp("@thorDataDirectory"); const char * overrideReplicateDirectory = globals->queryProp("@thorReplicateDirectory"); StringBuffer datadir; StringBuffer repdir; if (getConfigurationDirectory(globals->queryPropTree("Directories"),"data","thor",globals->queryProp("@name"),datadir)) overrideBaseDirectory = datadir.str(); if (getConfigurationDirectory(globals->queryPropTree("Directories"),"mirror","thor",globals->queryProp("@name"),repdir)) overrideReplicateDirectory = repdir.str(); if (overrideBaseDirectory&&*overrideBaseDirectory) setBaseDirectory(overrideBaseDirectory, false); if (overrideReplicateDirectory&&*overrideBaseDirectory) setBaseDirectory(overrideReplicateDirectory, true); StringBuffer tempDirStr; if (getConfigurationDirectory(globals->queryPropTree("Directories"),"temp","thor",globals->queryProp("@name"), tempDirStr)) globals->setProp("@thorTempDirectory", tempDirStr.str()); else tempDirStr.append(globals->queryProp("@thorTempDirectory")); addPathSepChar(tempDirStr).append(getMachinePortBase()); logDiskSpace(); // Log before temp space is cleared SetTempDir(tempDirStr.str(), "thtmp", true); useMemoryMappedRead(globals->getPropBool("@useMemoryMappedRead")); LOG(MCdebugProgress, thorJob, "ThorSlave Version LCR - %d.%d started",THOR_VERSION_MAJOR,THOR_VERSION_MINOR); StringBuffer url; LOG(MCdebugProgress, thorJob, "Slave %s - temporary dir set to : %s", slfEp.getUrlStr(url).str(), queryTempDir()); #ifdef _WIN32 ULARGE_INTEGER userfree; ULARGE_INTEGER total; ULARGE_INTEGER free; if (GetDiskFreeSpaceEx("c:\\",&userfree,&total,&free)&&total.QuadPart) { unsigned pc = (unsigned)(free.QuadPart*100/total.QuadPart); LOG(MCdebugProgress, thorJob, "Total disk space = %" I64F "d k", total.QuadPart/1000); LOG(MCdebugProgress, thorJob, "Free disk space = %" I64F "d k", free.QuadPart/1000); LOG(MCdebugProgress, thorJob, "%d%% disk free\n",pc); } #endif if (getConfigurationDirectory(globals->queryPropTree("Directories"),"query","thor",globals->queryProp("@name"),str.clear())) globals->setProp("@query_so_dir", str.str()); else globals->getProp("@query_so_dir", str.clear()); if (str.length()) { if (globals->getPropBool("Debug/@dllsToSlaves", true)) { StringBuffer uniqSoPath; if (PATHSEPCHAR == str.charAt(str.length()-1)) uniqSoPath.append(str.length()-1, str.str()); else uniqSoPath.append(str); uniqSoPath.append("_").append(getMachinePortBase()); str.swapWith(uniqSoPath); globals->setProp("@query_so_dir", str.str()); } PROGLOG("Using querySo directory: %s", str.str()); recursiveCreateDirectory(str.str()); } multiThorMemoryThreshold = globals->getPropInt("@multiThorMemoryThreshold")*0x100000; if (multiThorMemoryThreshold) { StringBuffer lgname; if (!globals->getProp("@multiThorResourceGroup",lgname)) globals->getProp("@nodeGroup",lgname); if (lgname.length()) { Owned<ILargeMemLimitNotify> notify = createMultiThorResourceMutex(lgname.str()); setMultiThorMemoryNotify(multiThorMemoryThreshold,notify); PROGLOG("Multi-Thor resource limit for %s set to %" I64F "d",lgname.str(),(__int64)multiThorMemoryThreshold); } else multiThorMemoryThreshold = 0; } slaveMain(jobListenerStopped); } LOG(MCdebugProgress, thorJob, "ThorSlave terminated OK"); } catch (IException *e) { if (!jobListenerStopped) FLLOG(MCexception(e), thorJob, e,"ThorSlave"); unregisterException.setown(e); } ClearTempDirs(); if (multiThorMemoryThreshold) setMultiThorMemoryNotify(0,NULL); roxiemem::releaseRoxieHeap(); if (unregisterException.get()) UnregisterSelf(unregisterException); if (globals->getPropBool("Debug/@slaveDaliClient")) disableThorSlaveAsDaliClient(); #ifdef USE_MP_LOG stopLogMsgReceivers(); #endif stopMPServer(); ::Release(globals); releaseAtoms(); // don't know why we can't use a module_exit to destruct these... ExitModuleObjects(); // not necessary, atexit will call, but good for leak checking return 0; }
int main(int argc,char **argv) { InitModuleObjects(); EnableSEHtoExceptionMapping(); #ifndef __64BIT__ // Restrict stack sizes on 32-bit systems Thread::setDefaultStackSize(0x10000); // 64K stack (also set in windows DSP) #endif Owned<IFile> sentinelFile = createSentinelTarget(); removeSentinelFile(sentinelFile); SocketEndpoint listenep; unsigned sendbufsize = 0; unsigned recvbufsize = 0; int i = 1; bool isdaemon = (memicmp(argv[0]+strlen(argv[0])-4,".exe",4)==0); // bit of a kludge for windows - if .exe not specified then not daemon bool locallisten = false; const char *logdir=NULL; bool requireauthenticate = false; StringBuffer logDir; StringBuffer instanceName; //Get SSL Settings const char * sslCertFile; bool useSSL; unsigned short dafsPort;//DAFILESRV_PORT or SECURE_DAFILESRV_PORT querySecuritySettings(&useSSL, &dafsPort, &sslCertFile, NULL); unsigned parallelRequestLimit = DEFAULT_PARALLELREQUESTLIMIT; unsigned throttleDelayMs = DEFAULT_THROTTLEDELAYMS; unsigned throttleCPULimit = DEFAULT_THROTTLECPULIMIT; Owned<IPropertyTree> env = getHPCCEnvironment(); if (env) { StringBuffer dafilesrvPath("Software/DafilesrvProcess"); if (instanceName.length()) dafilesrvPath.appendf("[@name=\"%s\"]", instanceName.str()); IPropertyTree *daFileSrv = env->queryPropTree(dafilesrvPath); if (daFileSrv) { // global DaFileSrv settings: parallelRequestLimit = daFileSrv->getPropInt("@parallelRequestLimit", DEFAULT_PARALLELREQUESTLIMIT); throttleDelayMs = daFileSrv->getPropInt("@throttleDelayMs", DEFAULT_THROTTLEDELAYMS); throttleCPULimit = daFileSrv->getPropInt("@throttleCPULimit", DEFAULT_THROTTLECPULIMIT); // any overrides by Instance definitions? // NB: This won't work if netAddress is "." or if we start supporting hostnames there StringBuffer ipStr; queryHostIP().getIpText(ipStr); VStringBuffer daFileSrvPath("Instance[@netAddress=\"%s\"]", ipStr.str()); IPropertyTree *dafileSrvInstance = daFileSrv->queryPropTree(daFileSrvPath); if (dafileSrvInstance) { parallelRequestLimit = dafileSrvInstance->getPropInt("@parallelRequestLimit", parallelRequestLimit); throttleDelayMs = dafileSrvInstance->getPropInt("@throttleDelayMs", throttleDelayMs); throttleCPULimit = dafileSrvInstance->getPropInt("@throttleCPULimit", throttleCPULimit); } } } while (argc>i) { if (stricmp(argv[i],"-D")==0) { i++; isdaemon = true; } else if (stricmp(argv[i],"-R")==0) { // for remote run i++; #ifdef _WIN32 isdaemon = false; #else isdaemon = true; #endif } else if (stricmp(argv[i],"-A")==0) { i++; requireauthenticate = true; } else if ((argv[i][0]=='-')&&(toupper(argv[i][1])=='T')&&(!argv[i][2]||isdigit(argv[i][2]))) { if (argv[i][2]) setDafsTrace(NULL,(byte)atoi(argv[i]+2)); i++; isdaemon = false; } else if ((argc>i+1)&&(stricmp(argv[i],"-L")==0)) { i++; logDir.clear().append(argv[i++]); } else if ((argc>i+1)&&(stricmp(argv[i],"-I")==0)) { i++; instanceName.clear().append(argv[i++]); } else if (stricmp(argv[i],"-LOCAL")==0) { i++; locallisten = true; } else if (stricmp(argv[i],"-NOSSL")==0) {//overrides config setting i++; if (useSSL) { PROGLOG("DaFileSrv SSL specified in config but overridden by -NOSSL in command line"); useSSL = false; dafsPort = DAFILESRV_PORT; } } else break; } if (useSSL && !sslCertFile) { ERRLOG("DaFileSrv SSL specified but certificate file information missing from environment.conf"); exit(-1); } if (0 == logDir.length()) { getConfigurationDirectory(NULL,"log","dafilesrv",instanceName.str(),logDir); if (0 == logDir.length()) logDir.append("."); } if (instanceName.length()) { addPathSepChar(logDir); logDir.append(instanceName.str()); } #ifdef _WIN32 if ((argc>i)&&(stricmp(argv[i],"-install")==0)) { if (installService(DAFS_SERVICE_NAME,DAFS_SERVICE_DISPLAY_NAME,NULL)) { PROGLOG(DAFS_SERVICE_DISPLAY_NAME " Installed"); return 0; } return 1; } if ((argc>i)&&(stricmp(argv[i],"-remove")==0)) { if (uninstallService(DAFS_SERVICE_NAME,DAFS_SERVICE_DISPLAY_NAME)) { PROGLOG(DAFS_SERVICE_DISPLAY_NAME " Uninstalled"); return 0; } return 1; } #endif if (argc == i) listenep.port = dafsPort; else { if (strchr(argv[i],'.')||!isdigit(argv[i][0])) listenep.set(argv[i], dafsPort); else listenep.port = atoi(argv[i]); if (listenep.port==0) { usage(); exit(-1); } sendbufsize = (argc>i+1)?(atoi(argv[i+1])*1024):0; recvbufsize = (argc>i+2)?(atoi(argv[i+2])*1024):0; } if (isdaemon) { #ifdef _WIN32 class cserv: public CService { bool stopped; bool started; SocketEndpoint listenep; bool useSSL; bool requireauthenticate; class cpollthread: public Thread { cserv *parent; public: cpollthread( cserv *_parent ) : Thread("CService::cpollthread"), parent(_parent) { } int run() { while (parent->poll()) Sleep(1000); return 1; } } pollthread; Owned<IRemoteFileServer> server; public: cserv(SocketEndpoint _listenep, bool _useSSL) : listenep(_listenep),useSSL(_useSSL),pollthread(this) { stopped = false; started = false; } virtual ~cserv() { stopped = true; if (started) pollthread.join(); } bool init() { PROGLOG(DAFS_SERVICE_DISPLAY_NAME " Initialized"); started = true; pollthread.start(); return true; } bool poll() { if (stopped||!running()) { PROGLOG(DAFS_SERVICE_DISPLAY_NAME " Stopping"); if (server) { server->stop(); server.clear(); } return false; } return true; } void run() { // Get params from HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\DaFileSrv\Parameters int requireauthenticate=0; HKEY hkey; if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\DaFileSrv\\Parameters", 0, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS) { DWORD dwType = 0; DWORD dwSize = sizeof(requireauthenticate); RegQueryValueEx(hkey, "RequireAuthentication", NULL, &dwType, (BYTE*)&requireauthenticate, &dwSize); RegCloseKey(hkey); } StringBuffer eps; if (listenep.isNull()) eps.append(listenep.port); else listenep.getUrlStr(eps); enableDafsAuthentication(requireauthenticate!=0); PROGLOG("Opening " DAFS_SERVICE_DISPLAY_NAME " on %s%s", useSSL?"SECURE ":"",eps.str()); const char * verstring = remoteServerVersionString(); PROGLOG("Version: %s", verstring); PROGLOG("Authentication:%s required",requireauthenticate?"":" not"); PROGLOG(DAFS_SERVICE_DISPLAY_NAME " Running"); server.setown(createRemoteFileServer(parallelRequestLimit, throttleDelayMs, throttleCPULimit)); try { server->run(listenep, useSSL); } catch (IException *e) { EXCLOG(e,DAFS_SERVICE_NAME); e->Release(); } PROGLOG(DAFS_SERVICE_DISPLAY_NAME " Stopped"); stopped = true; } } service(listenep, useSSL); service.start(); return 0; #else int ret = initDaemon(); if (ret) return ret; #endif } { Owned<IComponentLogFileCreator> lf = createComponentLogFileCreator(logDir.str(), "DAFILESRV"); lf->setCreateAliasFile(false); lf->setMaxDetail(TopDetail); lf->beginLogging(); } PROGLOG("Parallel request limit = %d, throttleDelayMs = %d, throttleCPULimit = %d", parallelRequestLimit, throttleDelayMs, throttleCPULimit); const char * verstring = remoteServerVersionString(); StringBuffer eps; if (listenep.isNull()) eps.append(listenep.port); else listenep.getUrlStr(eps); enableDafsAuthentication(requireauthenticate); PROGLOG("Opening Dali File Server on %s%s", useSSL?"SECURE ":"",eps.str()); PROGLOG("Version: %s", verstring); PROGLOG("Authentication:%s required",requireauthenticate?"":" not"); startPerformanceMonitor(10*60*1000, PerfMonStandard); server.setown(createRemoteFileServer(parallelRequestLimit, throttleDelayMs, throttleCPULimit)); writeSentinelFile(sentinelFile); try { server->run(listenep, useSSL); } catch (IException *e) { EXCLOG(e,"DAFILESRV"); e->Release(); } if (server) server->stop(); server.clear(); PROGLOG("Stopped Dali File Server"); return 0; }
int main( int argc, char *argv[] ) { #if defined(WIN32) && defined(_DEBUG) int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG ); tmpFlag |= _CRTDBG_LEAK_CHECK_DF; _CrtSetDbgFlag( tmpFlag ); #endif InitModuleObjects(); addAbortHandler(ControlHandler); EnableSEHtoExceptionMapping(); dummyProc(); #ifndef __64BIT__ Thread::setDefaultStackSize(0x10000); // NB under windows requires linker setting (/stack:) #endif #ifdef _WIN32 Owned<CReleaseMutex> globalNamedMutex; #endif if (globals) globals->Release(); { Owned<IFile> iFile = createIFile("thor.xml"); globals = iFile->exists() ? createPTree(*iFile, ipt_caseInsensitive) : createPTree("Thor", ipt_caseInsensitive); } unsigned multiThorMemoryThreshold = 0; try { if (argc==1) { usage(); return 1; } cmdArgs = argv+1; mergeCmdParams(globals); cmdArgs = argv+1; const char *master = globals->queryProp("@MASTER"); if (!master) usage(); const char *slave = globals->queryProp("@SLAVE"); if (slave) { slfEp.set(slave); localHostToNIC(slfEp); } else slfEp.setLocalHost(0); if (globals->hasProp("@SLAVENUM")) mySlaveNum = atoi(globals->queryProp("@SLAVENUM")); else mySlaveNum = slfEp.port; // shouldn't happen, provided by script setMachinePortBase(slfEp.port); slfEp.port = getMachinePortBase(); startSlaveLog(); startMPServer(getFixedPort(TPORT_mp)); #ifdef USE_MP_LOG startLogMsgParentReceiver(); LOG(MCdebugProgress, thorJob, "MPServer started on port %d", getFixedPort(TPORT_mp)); #endif SocketEndpoint masterEp(master); localHostToNIC(masterEp); setMasterPortBase(masterEp.port); markNodeCentral(masterEp); if (RegisterSelf(masterEp)) { #define ISDALICLIENT // JCSMORE plugins *can* access dali - though I think we should probably prohibit somehow. #ifdef ISDALICLIENT const char *daliServers = globals->queryProp("@DALISERVERS"); if (!daliServers) { LOG(MCerror, thorJob, "No Dali server list specified\n"); return 1; } Owned<IGroup> serverGroup = createIGroup(daliServers, DALI_SERVER_PORT); unsigned retry = 0; loop { try { LOG(MCdebugProgress, thorJob, "calling initClientProcess"); initClientProcess(serverGroup,DCR_ThorSlave, getFixedPort(TPORT_mp)); break; } catch (IJSOCK_Exception *e) { if ((e->errorCode()!=JSOCKERR_port_in_use)) throw; FLLOG(MCexception(e), thorJob, e,"InitClientProcess"); if (retry++>10) throw; e->Release(); LOG(MCdebugProgress, thorJob, "Retrying"); Sleep(retry*2000); } } setPasswordsFromSDS(); #endif IDaFileSrvHook *daFileSrvHook = queryDaFileSrvHook(); if (daFileSrvHook) // probably always installed daFileSrvHook->addSubnetFilters(globals->queryPropTree("NAS"), NULL); StringBuffer thorPath; globals->getProp("@thorPath", thorPath); recursiveCreateDirectory(thorPath.str()); int err = _chdir(thorPath.str()); if (err) { IException *e = MakeErrnoException(-1, "Failed to change dir to '%s'",thorPath.str()); FLLOG(MCexception(e), thorJob, e); throw e; } // Initialization from globals setIORetryCount(globals->getPropInt("Debug/@ioRetries")); // default == 0 == off StringBuffer str; if (globals->getProp("@externalProgDir", str.clear())) _mkdir(str.str()); else globals->setProp("@externalProgDir", thorPath); const char * overrideBaseDirectory = globals->queryProp("@thorDataDirectory"); const char * overrideReplicateDirectory = globals->queryProp("@thorReplicateDirectory"); StringBuffer datadir; StringBuffer repdir; if (getConfigurationDirectory(globals->queryPropTree("Directories"),"data","thor",globals->queryProp("@name"),datadir)) overrideBaseDirectory = datadir.str(); if (getConfigurationDirectory(globals->queryPropTree("Directories"),"mirror","thor",globals->queryProp("@name"),repdir)) overrideReplicateDirectory = repdir.str(); if (overrideBaseDirectory&&*overrideBaseDirectory) setBaseDirectory(overrideBaseDirectory, false); if (overrideReplicateDirectory&&*overrideBaseDirectory) setBaseDirectory(overrideReplicateDirectory, true); StringBuffer tempdirstr; const char *tempdir = globals->queryProp("@thorTempDirectory"); if (getConfigurationDirectory(globals->queryPropTree("Directories"),"temp","thor",globals->queryProp("@name"),tempdirstr)) tempdir = tempdirstr.str(); SetTempDir(tempdir,true); useMemoryMappedRead(globals->getPropBool("@useMemoryMappedRead")); LOG(MCdebugProgress, thorJob, "ThorSlave Version LCR - %d.%d started",THOR_VERSION_MAJOR,THOR_VERSION_MINOR); StringBuffer url; LOG(MCdebugProgress, thorJob, "Slave %s - temporary dir set to : %s", slfEp.getUrlStr(url).toCharArray(), queryTempDir()); #ifdef _WIN32 ULARGE_INTEGER userfree; ULARGE_INTEGER total; ULARGE_INTEGER free; if (GetDiskFreeSpaceEx("c:\\",&userfree,&total,&free)&&total.QuadPart) { unsigned pc = (unsigned)(free.QuadPart*100/total.QuadPart); LOG(MCdebugProgress, thorJob, "Total disk space = %"I64F"d k", total.QuadPart/1000); LOG(MCdebugProgress, thorJob, "Free disk space = %"I64F"d k", free.QuadPart/1000); LOG(MCdebugProgress, thorJob, "%d%% disk free\n",pc); } #endif if (getConfigurationDirectory(globals->queryPropTree("Directories"),"query","thor",globals->queryProp("@name"),str.clear())) globals->setProp("@query_so_dir", str.str()); else globals->getProp("@query_so_dir", str.clear()); if (str.length()) { if (globals->getPropBool("Debug/@dllsToSlaves", true)) { StringBuffer uniqSoPath; if (PATHSEPCHAR == str.charAt(str.length()-1)) uniqSoPath.append(str.length()-1, str.str()); else uniqSoPath.append(str); uniqSoPath.append("_").append(getMachinePortBase()); str.swapWith(uniqSoPath); globals->setProp("@query_so_dir", str.str()); } PROGLOG("Using querySo directory: %s", str.str()); recursiveCreateDirectory(str.str()); } multiThorMemoryThreshold = globals->getPropInt("@multiThorMemoryThreshold")*0x100000; if (multiThorMemoryThreshold) { StringBuffer lgname; if (!globals->getProp("@multiThorResourceGroup",lgname)) globals->getProp("@nodeGroup",lgname); if (lgname.length()) { Owned<ILargeMemLimitNotify> notify = createMultiThorResourceMutex(lgname.str()); setMultiThorMemoryNotify(multiThorMemoryThreshold,notify); PROGLOG("Multi-Thor resource limit for %s set to %"I64F"d",lgname.str(),(__int64)multiThorMemoryThreshold); } else multiThorMemoryThreshold = 0; } slaveMain(); } LOG(MCdebugProgress, thorJob, "ThorSlave terminated OK"); } catch (IException *e) { FLLOG(MCexception(e), thorJob, e,"ThorSlave"); e->Release(); } catch (CATCHALL) { FLLOG(MCerror, thorJob, "ThorSlave exiting because of uncaught exception"); } ClearTempDirs(); if (multiThorMemoryThreshold) setMultiThorMemoryNotify(0,NULL); roxiemem::releaseRoxieHeap(); #ifdef ISDALICLIENT closeEnvironment(); closedownClientProcess(); // dali client closedown #endif #ifdef USE_MP_LOG stopLogMsgReceivers(); #endif stopMPServer(); ::Release(globals); releaseAtoms(); // don't know why we can't use a module_exit to destruct these... return 0; }
int main(int argc, char* argv[]) { InitModuleObjects(); EnableSEHtoExceptionMapping(); if (argc<2) { usage(argv[0]); return -1; } bool forceGroupUpdate = false; StringBuffer filename; StringBuffer inst; StringBuffer dcat; StringBuffer dcomp; StringBuffer dinst; StringBuffer dip; for (int i=1;i<argc;i++) { if (argv[i][0]=='-') { if ((stricmp(argv[i],"-i")==0)&&(i+1<argc)) { inst.append(argv[++i]); } else if (0==stricmp(argv[i],"-f")) { forceGroupUpdate = true; } else if ((stricmp(argv[i],"-d")==0)&&(i+3<argc)) { dcat.append(argv[++i]); dcomp.append(argv[++i]); dinst.append(argv[++i]); } else if ((stricmp(argv[i],"-ip")==0)&&(i+1<argc)) { dip.append(argv[++i]); } else { usage(argv[0]); return -1; } } else { if (filename.length()) { usage(argv[0]); return -1; } filename.append(argv[i]); } } Owned<IPropertyTree> env; try { env.setown(createPTreeFromXMLFile(argv[1])); if (!env.get()) { fprintf(stderr,"Could not load Environment from %s\n",argv[1]); return 1; } const char *s = env->queryName(); if (!s||(strcmp(s,"Environment")!=0)) { fprintf(stderr,"File %s is invalid\n",argv[1]); return 1; } } catch (IException *e) { StringBuffer err; e->errorMessage(err); fprintf(stderr,"Could not load Environment from %s, %s\n",argv[1],err.str()); return 1; } int ret = 0; try { if (dcat.length()) { IPropertyTree* dirs = env->queryPropTree("Software/Directories"); StringBuffer dirout; if (getConfigurationDirectory(dirs,dcat.str(),dcomp.str(),dinst.str(),dirout)&&dirout.length()) { if (dip.length()) { SocketEndpoint ep(dip.str()); RemoteFilename rfn; rfn.setPath(ep,dirout.str()); rfn.getRemotePath(dirout.clear()); } printf("%s",dirout.str()); } else { ret = 1; } } else { if (!updateDaliEnv(env, forceGroupUpdate, inst.str())) ret = 1; } } catch (IException *e) { pexception("updtdalienv",e); e->Release(); ret = 1; } releaseAtoms(); return ret; }
int init_main(int argc, char* argv[]) { InitModuleObjects(); Owned<IProperties> inputs = createProperties(true); bool interactive = false; for (int i = 1; i < argc; i++) { if (stricmp(argv[i], "-?")==0 || stricmp(argv[i], "-h")==0 || stricmp(argv[i], "-help")==0 || stricmp(argv[i], "/?")==0 || stricmp(argv[i], "/h")==0) usage(); else if(stricmp(argv[i], "interactive") == 0) interactive = true; else if (strchr(argv[i],'=')) { inputs->loadProp(argv[i]); } else { fprintf(stderr, "Unknown option: %s", argv[i]); return 0; } } int result = -1; #ifdef _WIN32 if (!interactive) ::SetErrorMode(SEM_NOGPFAULTERRORBOX|SEM_FAILCRITICALERRORS); #endif SET_ESP_SIGNAL_HANDLER(SIGPIPE, brokenpipe_handler); bool SEHMappingEnabled = false; CEspAbortHandler abortHandler; Owned<IFile> sentinelFile = createSentinelTarget(); removeSentinelFile(sentinelFile); Owned<CEspConfig> config; Owned<CEspServer> server; try { const char* cfgfile = NULL; const char* procname = NULL; if(inputs.get()) { if(inputs->hasProp("config")) cfgfile = inputs->queryProp("config"); if(inputs->hasProp("process")) procname = inputs->queryProp("process"); } if(!cfgfile || !*cfgfile) cfgfile = "esp.xml"; Owned<IPropertyTree> envpt= createPTreeFromXMLFile(cfgfile, ipt_caseInsensitive); Owned<IPropertyTree> procpt = NULL; if (envpt) { envpt->addProp("@config", cfgfile); StringBuffer xpath; if (procname==NULL || strcmp(procname, ".")==0) xpath.appendf("Software/EspProcess[1]"); else xpath.appendf("Software/EspProcess[@name=\"%s\"]", procname); DBGLOG("Using ESP configuration section [%s]", xpath.str()); procpt.set(envpt->queryPropTree(xpath.str())); if (!procpt) throw MakeStringException(-1, "Config section [%s] not found", xpath.str()); } else throw MakeStringException(-1, "Failed to load config file %s", cfgfile); StringBuffer logdir; if(procpt->hasProp("@name")) { StringBuffer espNameStr; procpt->getProp("@name", espNameStr); if (!getConfigurationDirectory(envpt->queryPropTree("Software/Directories"), "log", "esp", espNameStr.str(), logdir)) { logdir.clear(); } } const char* build_ver = BUILD_TAG; setBuildVersion(build_ver); const char* build_level = BUILD_LEVEL; setBuildLevel(build_level); if(logdir.length() == 0) { if(procpt->hasProp("@logDir")) procpt->getProp("@logDir", logdir); } if(logdir.length() == 0) logdir.append("."); if(stricmp(logdir.str(), ".") != 0) { recursiveCreateDirectory(logdir.str()); } if(logdir.charAt(logdir.length() - 1) != PATHSEPCHAR) logdir.append(PATHSEPCHAR); openEspLogFile(logdir.str(), procpt.get()); StringBuffer componentfilesDir; if(procpt->hasProp("@componentfilesDir")) procpt->getProp("@componentfilesDir", componentfilesDir); if(componentfilesDir.length() > 0 && strcmp(componentfilesDir.str(), ".") != 0) { DBGLOG("componentfiles are under %s", componentfilesDir.str()); setCFD(componentfilesDir.str()); } StringBuffer sehsetting; procpt->getProp("@enableSEHMapping", sehsetting); if(!interactive && sehsetting.length() > 0 && (stricmp(sehsetting.str(), "true") == 0 || stricmp(sehsetting.str(), "1") == 0)) SEHMappingEnabled = true; if(SEHMappingEnabled) EnableSEHtoExceptionMapping(); CEspConfig* cfg = new CEspConfig(inputs.getLink(), envpt.getLink(), procpt.getLink(), false); if(cfg && cfg->isValid()) { config.setown(cfg); abortHandler.setConfig(cfg); } } catch(IException* e) { StringBuffer description; ERRLOG("ESP Unhandled IException (%d -- %s)", e->errorCode(), e->errorMessage(description).str()); e->Release(); return -1; } catch (...) { ERRLOG("ESP Unhandled General Exception."); return -1; } if (config && config->isValid()) { PROGLOG("Configuring Esp Platform..."); try { CEspServer *srv = new CEspServer(config); if(SEHMappingEnabled) srv->setSavedSEHHandler(SEHMappingEnabled); server.setown(srv); abortHandler.setServer(srv); setEspContainer(server.get()); config->loadAll(); config->bindServer(*server.get(), *server.get()); } catch(IException* e) { StringBuffer description; ERRLOG("ESP Unhandled IException (%d -- %s)", e->errorCode(), e->errorMessage(description).str()); e->Release(); return -1; } catch (...) { ERRLOG("ESP Unhandled General Exception."); return -1; } writeSentinelFile(sentinelFile); result = work_main(*config, *server.get()); } else { ERRLOG("!!! Unable to load ESP configuration."); } return result; }