|
|
@@ -15,9 +15,13 @@
|
|
|
#include <winpr/sysinfo.h>
|
|
|
#endif //RVC_OS_LINUX
|
|
|
|
|
|
+#include "XUnZipZilb.h"
|
|
|
+
|
|
|
#include "publicFunExport.h"
|
|
|
#include <map>
|
|
|
#include <regex.h>
|
|
|
+#include "../mod_healthmanager/HealthManager_client_g.h"
|
|
|
+using namespace HealthManager;
|
|
|
|
|
|
struct SogouRunVersionInfo
|
|
|
{
|
|
|
@@ -182,6 +186,30 @@ void ResourceWatcherServiceSession::Handle_UninstallThirdPartyProgram(SpReqAnsCo
|
|
|
m_pEntity->UninstallThirdPartyProgram(ctx);
|
|
|
}
|
|
|
|
|
|
+void ResourceWatcherServiceSession::Handle_RestartThirdPartyProgram(SpReqAnsContext<ResourceWatcherService_RestartThirdPartyProgram_Req, ResourceWatcherService_RestartThirdPartyProgram_Ans>::Pointer ctx)
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+ m_pEntity->RestartThirdPartyProgram(ctx);
|
|
|
+}
|
|
|
+
|
|
|
+void ResourceWatcherServiceSession::Handle_ProcessDetectThirdPartyProgram(SpReqAnsContext<ResourceWatcherService_ProcessDetectThirdPartyProgram_Req, ResourceWatcherService_ProcessDetectThirdPartyProgram_Ans>::Pointer ctx)
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+ m_pEntity->ProcessDetectThirdPartyProgram(ctx);
|
|
|
+}
|
|
|
+
|
|
|
+void ResourceWatcherServiceSession::Handle_FilesClean(SpReqAnsContext<ResourceWatcherService_FilesClean_Req, ResourceWatcherService_FilesClean_Ans>::Pointer ctx)
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+ m_pEntity->FilesClean(ctx);
|
|
|
+}
|
|
|
+
|
|
|
+void ResourceWatcherServiceSession::Handle_FetchSystemSnapshot(SpReqAnsContext<ResourceWatcherService_FetchSystemSnapshot_Req, ResourceWatcherService_FetchSystemSnapshot_Ans>::Pointer ctx)
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+ m_pEntity->FetchSystemSnapshot(ctx);
|
|
|
+}
|
|
|
+
|
|
|
void ResourceWatcherEntity::UpdateDNS(SpReqAnsContext<ResourceWatcherService_UpdateDNS_Req, ResourceWatcherService_UpdateDNS_Ans>::Pointer ctx)
|
|
|
{
|
|
|
ctx->Answer(Error_NotImpl);
|
|
|
@@ -403,25 +431,164 @@ ErrorCodeEnum SetFileExecutePriviledge(LPCTSTR lpcszDirOrFilePath)
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ErrorCodeEnum ResourceWatcherEntity::GetUnzipTempDir(CSimpleStringA& strUnzipDir)
|
|
|
+{
|
|
|
+ CSimpleStringA strDownloadsPath;
|
|
|
+ auto rc = GetFunction()->GetPath("Downloads", strDownloadsPath);
|
|
|
+ assert(rc == Error_Succeed);
|
|
|
+
|
|
|
+ strUnzipDir = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strDownloadsPath, strUnzipDir);
|
|
|
+ if (strUnzipDir.IsEndWith(".zip") || strUnzipDir.IsEndWith(".cab"))
|
|
|
+ strUnzipDir = strUnzipDir.SubString(0, strUnzipDir.GetLength() - 4);
|
|
|
+
|
|
|
+ return Error_Succeed;
|
|
|
+}
|
|
|
+
|
|
|
+ErrorCodeEnum ResourceWatcherEntity::UnzipPack(const char* unZipPackName)
|
|
|
+{
|
|
|
+ CSimpleStringA strDownloadsPath;
|
|
|
+ auto rc = GetFunction()->GetPath("Downloads", strDownloadsPath);
|
|
|
+ assert(rc == Error_Succeed);
|
|
|
+
|
|
|
+ CSimpleStringA strTempPath;
|
|
|
+ CSmartPointer<IEntityFunction> spFunction2 = GetFunction();
|
|
|
+ ErrorCodeEnum rc2 = spFunction2->GetPath("Temp", strTempPath);
|
|
|
+ assert(rc2 == Error_Succeed);
|
|
|
+
|
|
|
+ CSimpleStringA strUnzipPath;
|
|
|
+ strUnzipPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", strTempPath.GetData(), unZipPackName);
|
|
|
+ if (strUnzipPath.IsEndWith(".zip") || strUnzipPath.IsEndWith(".cab"))
|
|
|
+ {
|
|
|
+ strUnzipPath = strUnzipPath.SubString(0, strUnzipPath.GetLength() - 4);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如目标目录存在,则先删除
|
|
|
+ if (ExistsDirA(strUnzipPath))
|
|
|
+ {
|
|
|
+ if (!RemoveDirRecursiveA(strUnzipPath)) {
|
|
|
+ LogError(Severity_Low, Error_NotExist, 0, CSimpleStringA::Format("remove old unzip dir [%s] fail", strUnzipPath.GetData()));
|
|
|
+ return Error_NotExist;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 创建临时解压目录
|
|
|
+ CreateDirA(strUnzipPath.GetData(), false);
|
|
|
+
|
|
|
+ // 解压
|
|
|
+ CSimpleStringA strZipFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", strDownloadsPath.GetData(), unZipPackName);
|
|
|
+ string zipFileStr = strZipFile.GetData();
|
|
|
+ string zipTempDir = strUnzipPath.GetData();
|
|
|
+
|
|
|
+ if (!ExistsFileA(strZipFile.GetData()))
|
|
|
+ {
|
|
|
+ LogError(Severity_Low, Error_NotExist, 0, CSimpleStringA::Format("pack [%s] not exists", unZipPackName));
|
|
|
+ return Error_NotExist;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (UnZipToDir(zipFileStr, zipTempDir) != 0)
|
|
|
+ {
|
|
|
+ LogError(Severity_Low, Error_Unexpect, 0, CSimpleStringA::Format("unzip pack [%s] fail", unZipPackName));
|
|
|
+ return Error_NotExist;
|
|
|
+ }
|
|
|
+ return Error_Succeed;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
void ResourceWatcherEntity::InstallThirdPartyProgram(SpReqAnsContext<ResourceWatcherService_InstallThirdPartyProgram_Req, ResourceWatcherService_InstallThirdPartyProgram_Ans>::Pointer ctx)
|
|
|
{
|
|
|
ErrorCodeEnum result(Error_Succeed);
|
|
|
ErrorCodeEnum tmpResult(Error_Succeed);
|
|
|
CSimpleStringA tmpMsg(true);
|
|
|
|
|
|
+ Dbg("ctx-req context: %d, %d, %d", ctx->Req.type, ctx->Req.reserved1, ctx->Req.reserved2);
|
|
|
+
|
|
|
+ bool sogouInstalled = false;
|
|
|
+ const bool doTryRestart = (ctx->Req.reserved1 != 1);
|
|
|
+
|
|
|
if (ctx->Req.type == 1) {//安装搜狗输入法
|
|
|
+ bool zipFind = false;
|
|
|
+ time_t newestWrite = 0;
|
|
|
+ CSimpleStringA newSogouPath(true);
|
|
|
+ CSimpleStringA strDownloadDirPath(true);
|
|
|
+ GetFunction()->GetPath("Downloads", strDownloadDirPath);
|
|
|
+ CSimpleStringA strTempDirPath(true);
|
|
|
+ GetFunction()->GetPath("Temp", strTempDirPath);
|
|
|
+
|
|
|
+ if (strDownloadDirPath.IsNullOrEmpty()) {
|
|
|
+ tmpResult = Error_Unexpect;
|
|
|
+ tmpMsg = CSimpleStringA::Format("搜狗安装包目录[Downloads]不存在!");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DIR* dp;
|
|
|
+ struct dirent* dirp;
|
|
|
+ if ((dp = opendir(strDownloadDirPath.GetData())) != NULL)
|
|
|
+ {
|
|
|
+ while ((dirp = readdir(dp)) != NULL)
|
|
|
+ {
|
|
|
+ CSimpleStringA tmpName(dirp->d_name);
|
|
|
+ if ((tmpName.IsStartWith("sogou", true) || tmpName.IsStartWith("uos-sogou", true))
|
|
|
+ && tmpName.IsEndWith(".zip", true)) {
|
|
|
+
|
|
|
+ struct stat buf;
|
|
|
+ memset(&buf, 0x00, sizeof(buf));
|
|
|
+ const int ret = stat(CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", strDownloadDirPath.GetData(), dirp->d_name).GetData(), &buf);
|
|
|
+ if (ret != 0) {
|
|
|
+ Dbg("获取文件[%s]状态信息出错。", tmpName.GetData());
|
|
|
+ } else if(buf.st_mtim.tv_sec > newestWrite){
|
|
|
+ newestWrite = buf.st_mtim.tv_sec;
|
|
|
+ newSogouPath = CSimpleStringA(tmpName.GetData());
|
|
|
+ zipFind = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ closedir(dp);
|
|
|
+
|
|
|
+ if(!zipFind)
|
|
|
+ {
|
|
|
+ tmpResult = Error_NotExist;
|
|
|
+ tmpMsg = CSimpleStringA::Format("在路径[%s]下未找到搜狗安装包!", strDownloadDirPath.GetData());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ tmpResult = Error_NotExist;
|
|
|
+ tmpMsg = CSimpleStringA::Format("打开[Downloads]目录失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ CSimpleStringA strInstallPkgPath(true);
|
|
|
+ if (zipFind)
|
|
|
+ {
|
|
|
+ if (UnzipPack(newSogouPath.GetData()) != Error_Succeed)
|
|
|
+ {
|
|
|
+ tmpResult = Error_Unexpect;
|
|
|
+ tmpMsg = CSimpleStringA::Format("解压搜狗安装包失败!");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ newSogouPath = newSogouPath.SubString(0, newSogouPath.GetLength() - 4);
|
|
|
+ strInstallPkgPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s",
|
|
|
+ strTempDirPath.GetData(), newSogouPath.GetData());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ tmpResult = GetSogouPkgDirPath(strInstallPkgPath);
|
|
|
+ if (tmpResult != Error_Succeed) {
|
|
|
+ tmpMsg =CSimpleStringA::Format(" 指定位置 [Ad] 找不到输入法安装包");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
Dbg("to install sogou input...");
|
|
|
const bool doNotStartup(true); //安装后是否启动搜狗输入法服务,据搜狗反馈,不能通过root权限启动Sogou输入法
|
|
|
- CSimpleStringA strInstallPkgPath;
|
|
|
- tmpResult = GetSogouPkgDirPath(strInstallPkgPath);
|
|
|
- if (tmpResult != 0) {
|
|
|
- tmpMsg = CSimpleStringA::Format("指定位置找不到输入法安装包");
|
|
|
- } else {
|
|
|
+ if(tmpResult == Error_Succeed)
|
|
|
+ {
|
|
|
tmpResult = SetFileExecutePriviledge(strInstallPkgPath);
|
|
|
if (tmpResult != Error_Succeed) {
|
|
|
tmpMsg = CSimpleStringA::Format("%s 修改文件夹权限失败", strInstallPkgPath.GetData());
|
|
|
tmpResult = Error_NotExist;
|
|
|
+
|
|
|
} else {
|
|
|
CSimpleStringA strRunIniFilePath = strInstallPkgPath + SPLIT_SLASH_STR + "Run.ini";
|
|
|
if (ExistsFileA(strRunIniFilePath)) {
|
|
|
@@ -435,13 +602,15 @@ void ResourceWatcherEntity::InstallThirdPartyProgram(SpReqAnsContext<ResourceWat
|
|
|
tmpResult = RunShellScript(app);
|
|
|
if (tmpResult != 0) {
|
|
|
tmpMsg = CSimpleStringA::Format("执行 '%s' 失败", app);
|
|
|
- } else if(!doNotStartup) {
|
|
|
+ }
|
|
|
+ else if (!doNotStartup) {
|
|
|
CSimpleStringA strStartupScriptFile(strInstallPkgPath + SPLIT_SLASH_STR + "startup_service.sh");
|
|
|
Dbg("startup script file: %s", strStartupScriptFile.GetData());
|
|
|
if (!ExistsFileA(strStartupScriptFile)) {
|
|
|
tmpMsg = CSimpleStringA::Format("%s 启动脚本文件不存在,请重启设备再次验证", strStartupScriptFile.GetData());
|
|
|
tmpResult = Error_NotExist;
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
Sleep(1000);
|
|
|
do {
|
|
|
char app[MAX_PATH] = { '\0' };
|
|
|
@@ -454,7 +623,8 @@ void ResourceWatcherEntity::InstallThirdPartyProgram(SpReqAnsContext<ResourceWat
|
|
|
auto users = GetUserNameList(true);
|
|
|
if (users.size() == 1) {
|
|
|
sprintf(app, "su -m -p -c \"bash %s\" %s", strStartupScriptFile.GetData(), users[0].c_str());
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
for (auto it = users.cbegin(); it != users.cend(); ++it) {
|
|
|
Dbg("user:%s", it->c_str());
|
|
|
}
|
|
|
@@ -468,18 +638,21 @@ void ResourceWatcherEntity::InstallThirdPartyProgram(SpReqAnsContext<ResourceWat
|
|
|
if (0 == res) {
|
|
|
FREE(process);
|
|
|
Dbg("execute {%s} suc", app);
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
tmpMsg = CSimpleStringA::Format("执行 '%s' 失败:%s", app, toolkit_strerror(res));
|
|
|
tmpResult = Error_Process;
|
|
|
}
|
|
|
} while (false);
|
|
|
}
|
|
|
}
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
tmpMsg = CSimpleStringA::Format("%s 执行文件不存在", strInstallScriptFile.GetData());
|
|
|
tmpResult = Error_NotExist;
|
|
|
}
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
tmpMsg = CSimpleStringA::Format("%s 文件不存在,请检查安装包完整性", strRunIniFilePath.GetData());
|
|
|
tmpResult = Error_NotExist;
|
|
|
}
|
|
|
@@ -488,7 +661,7 @@ void ResourceWatcherEntity::InstallThirdPartyProgram(SpReqAnsContext<ResourceWat
|
|
|
if (tmpResult == Error_Succeed) {
|
|
|
Sleep(1500);
|
|
|
const CSimpleStringA strResultLogFilePath = strInstallPkgPath + SPLIT_SLASH_STR + "result.log";
|
|
|
- do
|
|
|
+ do
|
|
|
{
|
|
|
const int maxTimes = 5;
|
|
|
int curTimes = 0;
|
|
|
@@ -501,13 +674,15 @@ void ResourceWatcherEntity::InstallThirdPartyProgram(SpReqAnsContext<ResourceWat
|
|
|
if (!ExistsFileA(strResultLogFilePath)) {
|
|
|
tmpResult = Error_NotExist;
|
|
|
tmpMsg = CSimpleStringA::Format("安装成功标志文件不存在!");
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
FILE* pResultLog = fopen(strResultLogFilePath, "r");
|
|
|
if (pResultLog == NULL) {
|
|
|
tmpResult = Error_IO;
|
|
|
tmpMsg = CSimpleStringA::Format("打开安装成功标志文件失败!%s", strerror(errno));
|
|
|
- } else {
|
|
|
- char szTmp[1024] = {'\0'};
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ char szTmp[1024] = { '\0' };
|
|
|
int nRead = fread(szTmp, 1, sizeof(szTmp), pResultLog);
|
|
|
int installResult(-1);
|
|
|
char installMsg[256] = { '\0' };
|
|
|
@@ -517,7 +692,8 @@ void ResourceWatcherEntity::InstallThirdPartyProgram(SpReqAnsContext<ResourceWat
|
|
|
if (installResult != 0) {
|
|
|
tmpResult = Error_Unexpect;
|
|
|
tmpMsg = CSimpleStringA::Format("%s", szTmp);
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
SogouInstallInfo info;
|
|
|
info.state.dwInstalledStatus = Sogou_GetInstallStatus();
|
|
|
info.state.strInstallDate = Sogou_GetInstallTime();
|
|
|
@@ -538,15 +714,22 @@ void ResourceWatcherEntity::InstallThirdPartyProgram(SpReqAnsContext<ResourceWat
|
|
|
if (!info.IsInstalledSuccess()) {
|
|
|
tmpResult = Error_FailVerify;
|
|
|
tmpMsg = CSimpleStringA::Format("检测安装状态失败!");
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
ctx->Ans.path = info.program.strInstallDir;
|
|
|
ctx->Ans.reserverd1 = info.program.strVersion;
|
|
|
ctx->Ans.reserverd2 = info.state.GetInstallTime().ToTimeString();
|
|
|
+
|
|
|
+ if (doTryRestart) {
|
|
|
+ tmpMsg = CSimpleStringA::Format(" 从[%s]安装搜狗输入法成功,设备即将重启。", strInstallPkgPath.GetData());
|
|
|
+ }
|
|
|
+ sogouInstalled = true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
} else if (ctx->Req.type == 2) {//安装花了钱的字体
|
|
|
|
|
|
Dbg("to install cmb font input...%d", m_bInitMode);
|
|
|
@@ -616,6 +799,36 @@ void ResourceWatcherEntity::InstallThirdPartyProgram(SpReqAnsContext<ResourceWat
|
|
|
ctx->Ans.result = tmpResult;
|
|
|
ctx->Ans.msg = tmpMsg;
|
|
|
ctx->Answer(result);
|
|
|
+
|
|
|
+ if (sogouInstalled && doTryRestart)
|
|
|
+ {
|
|
|
+ HealthManagerService_ClientBase* m_pRWClient = new HealthManagerService_ClientBase(this);
|
|
|
+ ErrorCodeEnum eErr = m_pRWClient->Connect();
|
|
|
+
|
|
|
+ if (eErr != Error_Succeed) {
|
|
|
+ Dbg("HealthManager connected failed.");
|
|
|
+ m_pRWClient->SafeDelete();
|
|
|
+ m_pRWClient = NULL;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ HealthManagerService_ControlTerminalLife_Req detReq;
|
|
|
+ HealthManagerService_ControlTerminalLife_Ans detAns;
|
|
|
+ detReq.cmdType = 4;
|
|
|
+ detReq.reason = 0;
|
|
|
+ eErr = m_pRWClient->ControlTerminalLife(detReq, detAns, 3000);
|
|
|
+ if (eErr == Error_Succeed)
|
|
|
+ {
|
|
|
+ LogWarn(Severity_Middle, Error_Succeed, 0, "搜狗安装成功, 设备即将重启。");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ LogWarn(Severity_Middle, Error_Unexpect, 0, "调用健康实体重启设备失败!");
|
|
|
+ }
|
|
|
+ m_pRWClient->GetFunction()->CloseSession();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -843,6 +1056,157 @@ void ResourceWatcherEntity::UninstallThirdPartyProgram(SpReqAnsContext<ResourceW
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+void ResourceWatcherEntity::RestartThirdPartyProgram(SpReqAnsContext<ResourceWatcherService_RestartThirdPartyProgram_Req, ResourceWatcherService_RestartThirdPartyProgram_Ans>::Pointer ctx)
|
|
|
+{
|
|
|
+ ErrorCodeEnum result(Error_Succeed);
|
|
|
+ ErrorCodeEnum tmpResult(Error_Succeed);
|
|
|
+ CSimpleStringA tmpMsg(true);
|
|
|
+
|
|
|
+ if (ctx->Req.type == 1)
|
|
|
+ {//重启搜狗输入法
|
|
|
+ static int old_process_id[2] = { -1, -1 };
|
|
|
+ char* relate_processes[2] = { "sogouImeWebSrv", "sogouImeService" };
|
|
|
+
|
|
|
+ int count = 3;
|
|
|
+ alive_process_info processes[3];
|
|
|
+ memset(processes, 0, sizeof(processes));
|
|
|
+
|
|
|
+ osutil_detect_unique_app(relate_processes, array_size(relate_processes), &count, processes);
|
|
|
+
|
|
|
+ CAutoArray<CSimpleStringA> msgs(array_size(relate_processes));
|
|
|
+ int cnt(0);
|
|
|
+
|
|
|
+ for (int i = 0; i < array_size(relate_processes); ++i)
|
|
|
+ {
|
|
|
+ int k = -1;
|
|
|
+ for (int j = 0; j < count; ++j) {
|
|
|
+ if (strcmp(processes[j].name, relate_processes[i]) == 0) {
|
|
|
+ k = j;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (k != -1)
|
|
|
+ {
|
|
|
+ cnt++;
|
|
|
+ old_process_id[k] = processes[k].pid;
|
|
|
+
|
|
|
+ std::string sucContent, failedContent;
|
|
|
+ CSimpleStringA strCmd = CSimpleStringA::Format("kill -9 %d", old_process_id[k]);
|
|
|
+ bool ret = SP::Module::Util::ShellExecute(strCmd.GetData(), sucContent, failedContent);
|
|
|
+ Dbg("{%s}:{%s}{%s}", strCmd.GetData(), sucContent.c_str(), failedContent.c_str());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ int cnt2(0);
|
|
|
+ if (cnt > 0)
|
|
|
+ {
|
|
|
+ ///**TODO(Gifur@7/5/2022): 待优化处理 */
|
|
|
+ Sleep(2000);
|
|
|
+
|
|
|
+ int newCount = 3;
|
|
|
+ int notSame = 0;
|
|
|
+ vector<CSimpleStringA> tKillmsg;
|
|
|
+ alive_process_info newProcesses[3];
|
|
|
+ memset(newProcesses, 0, sizeof(newProcesses));
|
|
|
+ osutil_detect_unique_app(relate_processes, array_size(relate_processes), &newCount, newProcesses);
|
|
|
+ for (int i = 0; i < array_size(relate_processes); ++i)
|
|
|
+ {
|
|
|
+ int k = -1;
|
|
|
+ for (int j = 0; j < count; ++j) {
|
|
|
+ if (strcmp(newProcesses[j].name, relate_processes[i]) == 0 && newProcesses[j].pid > 0) {
|
|
|
+ k = j;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (k != -1)
|
|
|
+ {
|
|
|
+ cnt2++;
|
|
|
+ if (newProcesses[k].pid != old_process_id[k])
|
|
|
+ {
|
|
|
+ notSame++;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ tmpResult = Error_Unexpect;
|
|
|
+ CSimpleStringA tmsg = CSimpleStringA::Format("{杀死当前搜狗进程[%s]失败,pid[%d]。}",
|
|
|
+ newProcesses[k].name, newProcesses[k].pid);
|
|
|
+ tKillmsg.push_back(tmsg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (cnt2 == 0)
|
|
|
+ {
|
|
|
+ tmpMsg = "已杀死搜狗进程。但重启搜狗进程失败,请确认守护进程正常运行。";
|
|
|
+ tmpResult = Error_Unexpect;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (tKillmsg.size() != 0)
|
|
|
+ {
|
|
|
+ for (int i = 0; i < tKillmsg.size(); ++i)
|
|
|
+ {
|
|
|
+ tmpMsg += tKillmsg[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ tmpMsg = "已成功重启搜狗输入法进程。";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ tmpMsg = "当前系统无搜狗进程,请确认已安装搜狗输入法,并重启计算机以尝试启动搜狗输入法!";
|
|
|
+ tmpResult = Error_Unexpect;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ tmpResult = Error_NotSupport;
|
|
|
+ tmpMsg = CSimpleStringA::Format("接口调用参数错误。");
|
|
|
+ }
|
|
|
+
|
|
|
+ ctx->Ans.result = tmpResult;
|
|
|
+ ctx->Ans.msg = tmpMsg;
|
|
|
+
|
|
|
+ ctx->Answer(result);
|
|
|
+ return;
|
|
|
+}
|
|
|
+
|
|
|
+void ResourceWatcherEntity::ProcessDetectThirdPartyProgram(SpReqAnsContext<ResourceWatcherService_ProcessDetectThirdPartyProgram_Req, ResourceWatcherService_ProcessDetectThirdPartyProgram_Ans>::Pointer ctx)
|
|
|
+{
|
|
|
+ ErrorCodeEnum result(Error_Succeed);
|
|
|
+ ErrorCodeEnum tmpResult(Error_Succeed);
|
|
|
+
|
|
|
+ CSimpleStringA tmpMsg(true);
|
|
|
+ std::string res("");
|
|
|
+
|
|
|
+ if (ctx->Req.type == 1) {//检测搜狗输入法进程
|
|
|
+ CAutoArray<CSimpleStringA> pName(2);
|
|
|
+ pName[0] = "sogouImeWebSrv";
|
|
|
+ pName[1] = "sogouImeService";
|
|
|
+ res = DoCheckCertainProcessStatus(pName);
|
|
|
+
|
|
|
+ if (res.length() == 0)
|
|
|
+ {
|
|
|
+ tmpResult = Error_Failed;
|
|
|
+ tmpMsg = "Can't find Sogou Process.";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ tmpMsg = CSimpleStringA::Format("%s", res.c_str());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ctx->Ans.result = tmpResult;
|
|
|
+ ctx->Ans.msg = tmpMsg;
|
|
|
+
|
|
|
+ ctx->Answer(result);
|
|
|
+ return;
|
|
|
+}
|
|
|
+
|
|
|
#if defined(RVC_OS_WIN)
|
|
|
//1: 32bit process running at 64bit platform
|
|
|
//0:
|
|
|
@@ -1292,6 +1656,122 @@ void ResourceWatcherEntity::OnSysVarEvent(const char* pszKey, const char* pszVal
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+std::string ResourceWatcherEntity::DoCheckCertainProcessStatus(const CAutoArray<CSimpleStringA>& pName)
|
|
|
+{
|
|
|
+ int pSize = pName.GetCount();
|
|
|
+ /*static int old_process_id[pSize];
|
|
|
+ memset(old_process_id, -1, sizeof(old_process_id));*/
|
|
|
+ vector<int> old_process_id;
|
|
|
+ CAutoArray<CSimpleStringA> msgs;
|
|
|
+ alive_process_info* processes = new alive_process_info[pSize];
|
|
|
+ char** relate_processes = new char* [pSize];
|
|
|
+ int count = pSize;
|
|
|
+
|
|
|
+ for (int i = 0; i < pSize; ++i)
|
|
|
+ {
|
|
|
+ old_process_id.push_back(-1);
|
|
|
+
|
|
|
+ CSimpleStringA temp("");
|
|
|
+ msgs.Append(&temp, 0, 1);
|
|
|
+ relate_processes[i] = const_cast<char*>(pName[i].GetData());
|
|
|
+ Dbg("relate_process name: %s.", relate_processes[i]);
|
|
|
+ }
|
|
|
+ Dbg("COUNT = %d!", count);
|
|
|
+ osutil_detect_unique_app(relate_processes, pSize, &count, processes);
|
|
|
+
|
|
|
+ int cnt(0);
|
|
|
+ for (int i = 0; i < pSize; ++i) {
|
|
|
+ int k = -1;
|
|
|
+ for (int j = 0; j < count; ++j) {
|
|
|
+ if (strcmp(processes[j].name, relate_processes[i]) == 0) {
|
|
|
+ k = j;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (k != -1 && old_process_id[i] == -1) {
|
|
|
+ msgs[cnt++] = CSimpleStringA::Format("{\"name\":\"%s\", \"pid\":%d}"
|
|
|
+ , relate_processes[i], processes[k].pid);
|
|
|
+ old_process_id[i] = processes[k].pid;
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (k != -1 && (processes[k].pid != old_process_id[i])) {
|
|
|
+ msgs[cnt++] = CSimpleStringA::Format("{\"name\":\"%s\", \"prev\":%d, \"pid\":%d}"
|
|
|
+ , relate_processes[i], old_process_id[i], processes[k].pid);
|
|
|
+ old_process_id[i] = processes[k].pid;
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (k == -1 && old_process_id[i] != 0) {
|
|
|
+ msgs[cnt++] = CSimpleStringA::Format("{\"name\":\"%s\", \"prev\":%d, \"pid\":%d}"
|
|
|
+ , relate_processes[i], old_process_id[i], 0);
|
|
|
+ old_process_id[i] = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ std::string uploadInfo("");
|
|
|
+ if (cnt > 0) {
|
|
|
+ if (cnt > 1) {
|
|
|
+ uploadInfo = "{";
|
|
|
+ }
|
|
|
+ for (int i = 0; i < cnt; ++i) {
|
|
|
+ if (i != 0) {
|
|
|
+ uploadInfo += ",";
|
|
|
+ }
|
|
|
+ uploadInfo += msgs[i].GetData();
|
|
|
+ }
|
|
|
+ if (cnt > 1) {
|
|
|
+ uploadInfo += "}";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return uploadInfo;
|
|
|
+}
|
|
|
+
|
|
|
+void ResourceWatcherEntity::FilesClean(SpReqAnsContext<ResourceWatcherService_FilesClean_Req, ResourceWatcherService_FilesClean_Ans>::Pointer ctx)
|
|
|
+{
|
|
|
+ ErrorCodeEnum result(Error_Succeed);
|
|
|
+ ErrorCodeEnum tmpResult(Error_Succeed);
|
|
|
+ CSimpleStringA tmpMsg(true);
|
|
|
+
|
|
|
+ if (ctx->Req.type == 1)//清理浏览器缓存
|
|
|
+ {
|
|
|
+ BrowserCacheClean browserCacheClean;
|
|
|
+ browserCacheClean.needClean = 1;
|
|
|
+
|
|
|
+ SpSendBroadcast(GetFunction(),
|
|
|
+ SP_MSG_OF(BrowserCacheClean), SP_MSG_SIG_OF(BrowserCacheClean), browserCacheClean);
|
|
|
+
|
|
|
+ tmpMsg = "已发送重启命令";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ tmpResult = Error_NotExist;
|
|
|
+ tmpMsg = "非法的调用参数";
|
|
|
+ }
|
|
|
+
|
|
|
+ ctx->Ans.result = tmpResult;
|
|
|
+ ctx->Ans.msg = tmpMsg;
|
|
|
+ ctx->Answer(result);
|
|
|
+}
|
|
|
+
|
|
|
+void ResourceWatcherEntity::FetchSystemSnapshot(
|
|
|
+ SpReqAnsContext<ResourceWatcherService_FetchSystemSnapshot_Req, ResourceWatcherService_FetchSystemSnapshot_Ans>::Pointer ctx)
|
|
|
+{
|
|
|
+ CSimpleStringA info(true);
|
|
|
+ const bool ret = m_fsm.GetMonitorInfo(info);
|
|
|
+ if (ret) {
|
|
|
+ ctx->Ans.result = 0;
|
|
|
+ ctx->Ans.msg = info;
|
|
|
+ LogWarn(Severity_Low, Error_Debug, LOG_INFO_MONITOR_SETTINGS_GET, info);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ ctx->Ans.result = -1;
|
|
|
+ ctx->Ans.msg = "调用 GetMonitorInfo 接口失败";
|
|
|
+ }
|
|
|
+ ctx->Answer(Error_Succeed);
|
|
|
+}
|
|
|
+
|
|
|
SP_BEGIN_ENTITY_MAP()
|
|
|
SP_ENTITY(ResourceWatcherEntity)
|
|
|
SP_END_ENTITY_MAP()
|
|
|
@@ -1301,3 +1781,4 @@ SP_END_ENTITY_MAP()
|
|
|
|
|
|
|
|
|
|
|
|
+
|