⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stafprocessservice.cpp

📁 Software Testing Automation Framework (STAF)的开发代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        size = 0;        for (std::deque<STAFStringBufferPtr>::iterator iter = envList.begin();             iter != envList.end(); ++iter)        {            memcpy(envBuf + size, (*iter)->buffer(), (*iter)->length());            envBuf[size + (*iter)->length()] = 0;            size += (*iter)->length() + 1;        }        // Add the trailing null        envBuf[size] = 0;        startData.environment = (char *)envBuf;        // Now set up the user environment variables        userEnvArray = STAFRefPtr<STAFStringConst_t>(                       new STAFStringConst_t[userEnvList.size()],                       STAFRefPtr<STAFStringConst_t>::INIT);        for (unsigned int userEnvIndex = 0; userEnvIndex < userEnvList.size();             ++userEnvIndex)        {            userEnvArray[userEnvIndex] = userEnvList[userEnvIndex].getImpl();        }        startData.userEnvList = userEnvArray;        startData.userEnvCount = userEnvList.size();    }    else startData.environment = 0;    if (parsedResult->optionTimes("NEWCONSOLE") != 0)        startData.consoleMode = kSTAFProcessNewConsole;    else if (parsedResult->optionTimes("SAMECONSOLE") != 0)        startData.consoleMode = kSTAFProcessSameConsole;    else        startData.consoleMode = gDefaultConsoleMode;    startData.consoleFocus = process->consoleFocus;    STAFString defaultShellCommand;    STAFString defaultSameConsoleShell;    STAFString defaultNewConsoleShell;    if (process->processType == kCommand)    {        startData.commandType = kSTAFProcessCommand;        startData.shellCommand = 0;        process->shellCommand = "<No Shell>";    }    else    {   // process->processType == kShell        startData.commandType = kSTAFProcessShell;        if (process->shellCommand.length() != 0)        {            startData.shellCommand = process->shellCommand.getImpl();        }        else        {             // Assign the default shell command             defaultShellCommand = STAFProcessService::getDefaultShellCommand();             if (startData.consoleMode == kSTAFProcessSameConsole)             {                 defaultSameConsoleShell = STAFProcessService::getDefaultSameConsoleShell();                 if (defaultSameConsoleShell.length() != 0)                     startData.shellCommand = defaultSameConsoleShell.getImpl();                 else if (defaultShellCommand.length() != 0)                     startData.shellCommand = defaultShellCommand.getImpl();                 else                     startData.shellCommand = 0;             }             else             {                 // startData.consoleMode = kSTAFProcessNewConsole                 defaultNewConsoleShell = STAFProcessService::getDefaultNewConsoleShell();                 if (defaultNewConsoleShell.length() != 0)                     startData.shellCommand = defaultNewConsoleShell.getImpl();                 else if (defaultShellCommand.length() != 0)                     startData.shellCommand = defaultShellCommand.getImpl();                 else                     startData.shellCommand = 0;             }             // Assign shell command so query a process handle shows it             if (startData.shellCommand == 0)                 process->shellCommand = "<Default Shell>";             else                 process->shellCommand = startData.shellCommand;        }    }    // XXX: What to do about these conditionals?    STAFString commandNoPrivacyDelimiters = STAFHandle::removePrivacyDelimiters(        process->command);    startData.command = commandNoPrivacyDelimiters.getImpl();        STAFString parmsNoPrivacyDelimiters;    if (process->parms.length() != 0)    {        parmsNoPrivacyDelimiters = STAFHandle::removePrivacyDelimiters(            process->parms);        startData.parms = parmsNoPrivacyDelimiters.getImpl();    }    else    {        startData.parms = 0;    }    startData.title = (process->title.length() != 0) ?        process->title.getImpl() : 0;    startData.workdir = (process->workdir.length() != 0) ?        process->workdir.getImpl() : 0;    startData.workload = (process->workload.length() != 0) ?        process->workload.getImpl() : 0;    STAFString defaultUsername;    STAFString defaultPassword;    if (process->username.length() != 0)        startData.username = process->username.getImpl();    else    {        defaultUsername = STAFProcessService::getDefaultAuthUsername();        if (defaultUsername.length() != 0)            startData.username = defaultUsername.getImpl();        else            startData.username = 0;    }    STAFString passwordNoPrivacyDelimiters;    if (password.length() != 0)    {        passwordNoPrivacyDelimiters = STAFHandle::removePrivacyDelimiters(            password);        startData.password = passwordNoPrivacyDelimiters.getImpl();    }    else    {        defaultPassword = STAFProcessService::getDefaultAuthPassword();        if (defaultPassword.length() != 0)        {            defaultPassword = STAFHandle::removePrivacyDelimiters(                defaultPassword);            startData.password = defaultPassword.getImpl();        }        else        {            startData.password = 0;        }    }    startData.stdinRedirect  = stdInp.getImpl();    startData.stdoutRedirect = stdOut.getImpl();    startData.stderrRedirect = stdErr.getImpl();    if (parsedResult->optionTimes("DISABLEDAUTHISERROR"))        startData.disabledAuthAction = kSTAFProcessDisabledAuthError;    else if (parsedResult->optionTimes("IGNOREDISABLEDAUTH"))        startData.disabledAuthAction = kSTAFProcessDisabledAuthIgnore;    else        startData.disabledAuthAction = STAFProcessService::getDefaultDisabledAuthAction();    startData.authMode = STAFProcessService::getAuthMode();    STAFProcessEndCallbackLevel1 callback = { processTerminationCallback, 0 };    startData.callback = &callback;    unsigned int osRC = 0;    STAFString errorBuffer2;    // This block is here to make sure that the process is started and on    // the list before processTerminationCallback tries to remove it from    // the list.  We also get the HandleManager's lock so that we atomically    // start the process and add the pending handle.    {        STAFMutexSemLock processLock(fProcessListSem);        STAFMutexSemLock handleLock(gHandleManagerPtr->getHandleManagerSem());        rc = STAFProcess::startProcess2(            startData, process->pid, process->procHandle, osRC, errorBuffer2);        if (rc == kSTAFOk)        {            if (process->handleType == kPending)            {                gHandleManagerPtr->addAndGetPendingHandle(process->handle,                    process->pid, process->procHandle, varPool);            }            fProcessList[process->handle] = process;        }    }    if (rc != kSTAFOk)    {        // The process failed to start, but Stdout/Stderr files (temporary or        // not) may have been created and should be deleted before returning        try        {            if (stdOut.length() != 0)                STAFFSPath(stdOut).getEntry()->remove(&osRC);            if (stdErr.length() != 0)                STAFFSPath(stdErr).getEntry()->remove(&osRC);        }        catch (...)        { /* Ignore any errors */ }    }    delete [] envBuf;    if ((rc != kSTAFOk) && (process->handleType == kStatic))        gHandleManagerPtr->removeStaticHandle(process->handle);    if (rc != kSTAFOk)    {        STAFString errorMsg = errorBuffer2;        return STAFServiceResult(rc, errorMsg);    }    STAFString result(process->handle);    if (startMode == kWait)    {        process->notify->wait(timeout);        if (process->notify->query())        {            // We didn't time out waiting for the process to end            // So remove the process from the list, remove the handle,            // and return the RC            STAFMutexSemLock processLock(fProcessListSem);            if (process->handleType == kPending)            {                gHandleManagerPtr->removePendingHandle(process->handle,                                                       process->pid);            }            else            {                gHandleManagerPtr->removeStaticHandle(process->handle);            }            fProcessList.erase(process->handle);            // Create the marshalling context and set its map class definitions            STAFObjectPtr mc = STAFObject::createMarshallingContext();            mc->setMapClassDefinition(fCompletionMapClass->reference());            mc->setMapClassDefinition(fReturnFileMapClass->reference());            // Create a map to contain the completion information            STAFObjectPtr completionMap =                fCompletionMapClass->createInstance();            completionMap->put("rc", STAFString(process->RC));            if (process->key.length() != 0)                completionMap->put("key", process->key);            else                completionMap->put("key", STAFObject::createNone());            // Now, tack on any files that the user wanted returned            STAFObjectPtr returnFileList = STAFObject::createList();            if (process->retFileList.size() != 0)            {                for (STAFProcessService::Process::FileList::iterator iter =                         process->retFileList.begin();                     iter != process->retFileList.end();                     ++iter)                {                    STAFServiceResult fileResult = readFileIntoString(*iter);                    STAFObjectPtr returnFileMap =                         fReturnFileMapClass->createInstance();                    returnFileMap->put(                        "rc", STAFString(fileResult.fRC));                    returnFileMap->put(                        "data", STAFString(fileResult.fResult));                    returnFileList->append(returnFileMap);                }            }            completionMap->put("fileList", returnFileList);            mc->setRootObject(completionMap);            result = mc->marshall();            // Delete the temporary StdOut/Stderr files if used, with the            // force argument set to true so it doesn't check the deleteFlags            deleteTempFiles(*process, true);        }        else        {            // STAF timed out waiting for the process to end            rc = kSTAFTimeout;            // XXX: Is there a timing issue where the notify could have            // happened before this lock such that the temp files don't            // get deleted?            // Set the delete flag for the temporary Stdout/Stderr files            // if used so that the temp files will be deleted in the            // sendNotfication() method.            STAFMutexSemLock lock(*process->tempFileMutex);            if (process->stdoutTempFileInfo.name.length() != 0)                process->stdoutTempFileInfo.deleteFlag = true;            if (process->stderrTempFileInfo.name.length() != 0)                process->stderrTempFileInfo.deleteFlag = true;        }    }    return STAFServiceResult(rc, result);}STAFServiceResult STAFProcessService::handleStop(    const STAFServiceRequest &requestInfo){    // Verify that the requesting machine/user has at least trust level 4    IVALIDATE_TRUST(4, "STOP");    // Parse the request    STAFCommandParseResultPtr parsedResult =                              fStopParser.parse(requestInfo.fRequest);    if (parsedResult->rc != kSTAFOk)    {        return STAFServiceResult(kSTAFInvalidRequestString,                                 parsedResult->errorBuffer, 0);    }    DEFINE_VAR_POOL_LIST(varPoolList, varPoolListSize, requestInfo);    STAFHandle_t theHandle = 0;    STAFString stopMethodString;    STAFString errorBuffer;    STAFProcessStopMethod_t stopMethod;    bool userSpecifiedStopMethod = false;    STAFRC_t rc = RESOLVE_OPTIONAL_UINT_OPTION("HANDLE", theHandle);    if (!rc) rc = RESOLVE_OPTIONAL_STRING_OPTION("USING", stopMethodString);    if (rc) return STAFServiceResult(rc, errorBuffer);    if (stopMethodString.length() > 0)    {        STAFRC_t typeRC =            STAFProcessService::getStopMethodFromString(stopMethod,                                                        stopMethodString);        if (typeRC) return STAFServiceResult(kSTAFInvalidValue,                                             stopMethodString);        userSpecifiedStopMethod = true;    }    STAFString result;    STAFMutexSemLock processLock(fProcessListSem);    if (p

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -