📄 stafprocessservice.cpp
字号:
STAFProcessDisabledAuthAction_t &authAction, const STAFString &actionString){ static STAFString sIgnore("IGNORE"); static STAFString sError("ERROR"); STAFString upperAction = actionString.toUpperCase(); if (upperAction == sIgnore) authAction = kSTAFProcessDisabledAuthIgnore; else if (upperAction == sError) authAction = kSTAFProcessDisabledAuthError; else return kSTAFInvalidValue; return kSTAFOk;}STAFRC_t STAFProcessService::setDefaultDisabledAuthAction( STAFProcessDisabledAuthAction_t authAction){ // Get exclusive access to fAuthAction STAFMutexSemLock lock(sDefaultAuthDisabledActionSem); fAuthAction = authAction; return kSTAFOk;}STAFProcessDisabledAuthAction_tSTAFProcessService::getDefaultDisabledAuthAction(){ return fAuthAction;}STAFString STAFProcessService::getDefaultDisabledAuthActionAsString(){ static STAFString sIgnore("Ignore"); static STAFString sError("Error"); if (fAuthAction == kSTAFProcessDisabledAuthIgnore) return sIgnore; else // fAuthAction == kSTAFProcessDisabledAuthError return sError;}STAFRC_t STAFProcessService::setDefaultAuthUsername(const STAFString &username){ // Get exclusive access to fDefaultAuthUsername STAFMutexSemLock lock(sDefaultAuthUsernameSem); fDefaultAuthUsername = username; return kSTAFOk;}STAFString STAFProcessService::getDefaultAuthUsername(){ return fDefaultAuthUsername;}STAFRC_t STAFProcessService::setDefaultAuthPassword(const STAFString &password){ // Get exclusive access to fDefaultAuthPassword STAFMutexSemLock lock(sDefaultAuthPasswordSem); fDefaultAuthPassword = password; return kSTAFOk;}STAFString STAFProcessService::getDefaultAuthPassword(){ return fDefaultAuthPassword;}STAFRC_t isShellCommandValid(const STAFString &shellCommand){ return STAFProcessValidateShellSubstitutionChars(shellCommand);}STAFRC_t STAFProcessService::setDefaultShellCommand( const STAFString &shellCommand){ if ((shellCommand.length() != 0) && (isShellCommandValid(shellCommand) != kSTAFOk)) { return kSTAFInvalidValue; } // Get exclusive access to fDefaultShellCommand STAFMutexSemLock lock(sDefaultShellSem); fDefaultShellCommand = shellCommand; return kSTAFOk;}STAFString STAFProcessService::getDefaultShellCommand(){ return fDefaultShellCommand;}STAFRC_t STAFProcessService::setDefaultSameConsoleShell( const STAFString &shellCommand){ if ((shellCommand.length() != 0) && (isShellCommandValid(shellCommand) != kSTAFOk)) { return kSTAFInvalidValue; } // Get exclusive access to fDefaultSameConsoleShell STAFMutexSemLock lock(sDefaultSameConsoleShellSem); fDefaultSameConsoleShell = shellCommand; return kSTAFOk;}STAFString STAFProcessService::getDefaultSameConsoleShell(){ return fDefaultSameConsoleShell;}STAFRC_t STAFProcessService::setDefaultNewConsoleShell( const STAFString &shellCommand){ if ((shellCommand.length() != 0) && (isShellCommandValid(shellCommand) != kSTAFOk)) { return kSTAFInvalidValue; } // Get exclusive access to fDefaultNewConsoleShell STAFMutexSemLock lock(sDefaultNewConsoleShellSem); fDefaultNewConsoleShell = shellCommand; return kSTAFOk;}STAFString STAFProcessService::getDefaultNewConsoleShell(){ return fDefaultNewConsoleShell;}void STAFProcessService::handleProcessTermination(STAFProcessID_t pid, unsigned int retCode){ try { ProcessList::iterator iter; STAFMutexSemLock processLock(fProcessListSem); for (iter = fProcessList.begin(); (iter != fProcessList.end()) && (iter->second->pid != pid) || (iter->second->state != kRunning); iter++) { /* Do Nothing */ } if (iter == fProcessList.end()) { STAFTrace::trace(kSTAFTraceError, "PID was not in the list in " "handleProcessTermination()"); return; } ProcessPtr process = iter->second; process->RC = retCode; process->endStamp = STAFTimestamp::now(); process->state = kComplete; gHandleManagerPtr->unRegister(process->handle, process->pid); if (process->notify) process->notify->post(); // Send out the notification list fNotifySem.reset(); fNotifyProcess = process; gThreadManagerPtr->dispatch(sendNotificationCallback, 0); fNotifySem.wait(); fNotifyProcess = ProcessPtr(); } catch (STAFException &se) { se.trace("STAFProcessService::handleProcessTermination()"); } catch (...) { STAFTrace::trace( kSTAFTraceError, "Caught unknown exception in " "STAFProcessService::handleProcessTermination()"); }}void STAFProcessService::sendNotification(){ ProcessPtr process(fNotifyProcess); fNotifySem.post(); STAFString type("STAF/Process/End"); // Create the message to queue. The message is a marshalled map // containing the process completion information. STAFObjectPtr mc = STAFObject::createMarshallingContext(); STAFObjectPtr messageMap = STAFObject::createMap(); messageMap->put("handle", STAFString(process->handle)); messageMap->put("endTimestamp", process->endStamp.asString()); messageMap->put("rc", STAFString(process->RC)); messageMap->put("key", process->key); STAFObjectPtr fileList = STAFObject::createList(); if (process->retFileList.size() != 0) { for (STAFProcessService::Process::FileList::iterator iter = process->retFileList.begin(); iter != process->retFileList.end(); ++iter) { STAFServiceResult result = readFileIntoString(*iter); STAFObjectPtr retFileMap = STAFObject::createMap(); retFileMap->put("rc", STAFString(result.fRC)); retFileMap->put("data", STAFString(result.fResult)); fileList->append(retFileMap); } } messageMap->put("fileList", fileList); mc->setRootObject(messageMap); STAFString message = mc->marshall(); process->notificationList->sendNotification(type, message); // Delete the temporary StdOut/StdErr files if used and available for // deletion. deleteTempFiles(*process);}STAFServiceResult STAFProcessService::acceptRequest( const STAFServiceRequest &requestInfo){ // select word 1 as the action and the rest of the request as rest STAFString action = requestInfo.fRequest.subWord(0, 1).lowerCase(); if (action == "start") return handleStart(requestInfo); else if (action == "stop") return handleStop(requestInfo); else if (action == "query") return handleQuery(requestInfo); else if (action == "free") return handleFree(requestInfo); else if (action == "list") return handleList(requestInfo); else if (action == "notify") { STAFString subAction = requestInfo.fRequest.subWord(1, 1).lowerCase(); if (subAction == "register") return handleNotifyRegistration(1, requestInfo); else if (subAction == "unregister") return handleNotifyRegistration(0, requestInfo); else if (subAction == "list") return handleNotifyList(requestInfo); else return STAFServiceResult(kSTAFInvalidRequestString); } else if (action == "set") return handleSet(requestInfo); else if (action == "help") return handleHelp(requestInfo); else return STAFServiceResult(kSTAFInvalidRequestString);}STAFServiceResult STAFProcessService::handleStart( const STAFServiceRequest &requestInfo){ // Verify that the requesting machine/user has at least trust level 5 IVALIDATE_TRUST(5, "START"); // Parse the request STAFCommandParseResultPtr parsedResult = fStartParser.parse(requestInfo.fRequest); if (parsedResult->rc != kSTAFOk) { return STAFServiceResult(kSTAFInvalidRequestString, parsedResult->errorBuffer, 0); } STAFString errorBuffer; ProcessSync startMode = kAsync; if (parsedResult->optionTimes("WAIT") != 0) { startMode = kWait; } STAFProcessStartInfoLevel1 startData = { 0 }; ProcessPtr process(new Process(), ProcessPtr::INIT); unsigned int doNotify = parsedResult->optionTimes("NOTIFY"); unsigned int useName = parsedResult->optionTimes("NAME"); unsigned int priority = 5; STAFHandle_t theHandle = requestInfo.fHandle; STAFString machine = requestInfo.fEndpoint; STAFString name; STAFString password = ""; STAFString stdInp = ""; STAFString stdOut = ""; STAFString stdErr = ""; STAFString stopMethodString; STAFString focusString = ""; unsigned int timeout = 0; STAFString staticHandleName; if (parsedResult->optionTimes("STATICHANDLENAME") != 0) process->handleType = kStatic; else process->handleType = kPending; if (parsedResult->optionTimes("SHELL") != 0) process->processType = kShell; else process->processType = kCommand; process->authenticator = requestInfo.fAuthenticator; process->userIdentifier = requestInfo.fUserIdentifier; // Set up variable pool STAFVariablePoolPtr varPool(new STAFVariablePool, STAFVariablePoolPtr::INIT); if (parsedResult->optionTimes("VAR") != 0) { for (int i = 1; i <= parsedResult->optionTimes("VAR"); ++i) { STAFString nameAndValue = parsedResult->optionValue("VAR", i); unsigned int equalPos = nameAndValue.find(kUTF8_EQUAL); if (equalPos == STAFString::kNPos) { return STAFServiceResult( kSTAFInvalidValue, STAFString("The value for a VAR option must have format" " Variable=Value. Invalid value: ") + nameAndValue); } varPool->set(nameAndValue.subString(0, equalPos), nameAndValue.subString(equalPos + nameAndValue.sizeOfChar(equalPos))); } } // Create a STAF handle variable for this PROCESS START request that // contains the endpoint of the originating machine varPool->set("STAF/Service/Process/OrgEndpoint", requestInfo.fEndpoint); // Set up the master variable pool list and size // // Note: This is normally handled by a macro, but we need to handle it // specially here due to the use of the USEPROCESSVARS pool const STAFVariablePool *masterVarPoolList[] = { varPool, requestInfo.fRequestVarPool, requestInfo.fSourceSharedVarPool, requestInfo.fLocalSharedVarPool, requestInfo.fLocalSystemVarPool }; const STAFVariablePool **varPoolList = masterVarPoolList; unsigned int varPoolListSize =
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -