|
@@ -4,6 +4,7 @@
|
|
|
#include "EventCode.h"
|
|
|
#include "fileutil.h"
|
|
|
#include "toolkit.h"
|
|
|
+#include "osutil.h"
|
|
|
#include "CommEntityUtil.hpp"
|
|
|
|
|
|
#if defined(RVC_OS_WIN)
|
|
@@ -221,10 +222,109 @@ ErrorCodeEnum CDeviceControlFSM::RestartSogouServices()
|
|
|
std::string shutdown_service(shellScriptPath.GetData());
|
|
|
shutdown_service += "shutdown_sogouservice.sh";
|
|
|
|
|
|
+ std::string shutdown_service_without_monitor(shellScriptPath.GetData());
|
|
|
+ shutdown_service_without_monitor += "shutdown_sogouservice_without_monitor.sh";
|
|
|
+
|
|
|
const BOOL s1 = ExistsFileA(startup_service.c_str());
|
|
|
const BOOL s2 = ExistsFileA(shutdown_service.c_str());
|
|
|
+ const BOOL s3 = ExistsFileA(shutdown_service_without_monitor.c_str());
|
|
|
+
|
|
|
+ if (s3) {
|
|
|
+ char* relate_processes[3] = { "sogouImeWebSrv", "sogouImeService", "sogoumonitor.sh" };
|
|
|
+ int count = 4;
|
|
|
+ alive_process_info old_processes[4];
|
|
|
+ memset(old_processes, 0, sizeof(old_processes));
|
|
|
+ osutil_detect_unique_app(relate_processes, array_size(relate_processes), &count, old_processes);
|
|
|
+
|
|
|
+ int sogouImeWebSrv_PID(0), sogouImeServicePID(0);
|
|
|
+
|
|
|
+ bool monitor_exist(false), other_exists(false);
|
|
|
+ for (int i = 0; i < count; ++i) {
|
|
|
+ if (strcmp(old_processes[i].name, relate_processes[2]) == 0) {
|
|
|
+ monitor_exist = true;
|
|
|
+ } else {
|
|
|
+ other_exists = false;
|
|
|
+ }
|
|
|
+ if (strcmp(old_processes[i].name, relate_processes[0]) == 0) {
|
|
|
+ sogouImeWebSrv_PID = old_processes[i].pid;
|
|
|
+ } else if (strcmp(old_processes[i].name, relate_processes[1]) == 0) {
|
|
|
+ sogouImeServicePID = old_processes[i].pid;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!monitor_exist) {
|
|
|
+ return Error_InvalidState;
|
|
|
+ } else if(!other_exists){
|
|
|
+ return Error_NotExist;
|
|
|
+ } else {
|
|
|
+
|
|
|
+ std::string succStr, errStr;
|
|
|
+ std::string runStr("bash ");
|
|
|
+ runStr += shutdown_service_without_monitor;
|
|
|
+ if (!SP::Module::Util::ShelllExecute(runStr, succStr, errStr)) {
|
|
|
+ LogWarn(Severity_Middle, Error_Unexpect, LOG_DEVICECONTROL_SOGOU_SCRIPTS_EXECUTE_FAILED,
|
|
|
+ CSimpleStringA::Format("%s: %s, %s", shutdown_service_without_monitor.c_str(), succStr.c_str(), errStr.c_str()));
|
|
|
+ return Error_Unexpect;
|
|
|
+ } else {
|
|
|
+ Dbg("execute {%s} suc: %s", shutdown_service_without_monitor.c_str(), succStr.c_str());
|
|
|
+
|
|
|
+ /**等待服务进程退出 */
|
|
|
+ Sleep(300);
|
|
|
+
|
|
|
+ /** Sogou的监护服务每隔5s会检测搜狗服务是否存在,否则会重启,为什么不自己重启,因为搜狗服务得跑在普通用户权限下 [Gifur@20211230]*/
|
|
|
+ const DWORD defaultInterval = 3000;
|
|
|
+ const int maxtIntervalTimes(3);
|
|
|
+ int intervalTimes(0);
|
|
|
+
|
|
|
+ char* relate_processes2[2] = { "sogouImeWebSrv", "sogouImeService" };
|
|
|
+ int count2 = 3;
|
|
|
+ bool succ_flag(false);
|
|
|
+ int sogouImeWebSrv_newPID(0), sogouImeService_newPID(0);
|
|
|
+
|
|
|
+ alive_process_info new_processes[3];
|
|
|
+ memset(new_processes, 0, sizeof(new_processes));
|
|
|
+ osutil_detect_unique_app(relate_processes2, array_size(relate_processes2), &count2, new_processes);
|
|
|
+
|
|
|
+ while (intervalTimes < maxtIntervalTimes) {
|
|
|
+
|
|
|
+ if (count2 == 2/*normal process count*/) {
|
|
|
+ int exit_flag(0);
|
|
|
+ for (int i = 0; i < count2; ++i) {
|
|
|
+ if (strcmp(new_processes[i].name, relate_processes2[0]) == 0 && sogouImeWebSrv_PID != new_processes[i].pid) {
|
|
|
+ sogouImeWebSrv_newPID = new_processes[i].pid;
|
|
|
+ exit_flag += 1;
|
|
|
+ } else if (strcmp(new_processes[i].name, relate_processes2[1]) == 0 && sogouImeServicePID != new_processes[i].pid) {
|
|
|
+ exit_flag += 1;
|
|
|
+ sogouImeService_newPID = new_processes[i].pid;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (exit_flag == 2) {
|
|
|
+ succ_flag = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Sleep(defaultInterval);
|
|
|
+ count2 = 3;
|
|
|
+ memset(new_processes, 0, sizeof(new_processes));
|
|
|
+ osutil_detect_unique_app(relate_processes2, array_size(relate_processes2), &count2, new_processes);
|
|
|
+ intervalTimes++;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (succ_flag) {
|
|
|
+ LogWarn(Severity_Middle, Error_Debug, LOG_DEVICECONTROL_SOGOU_SCRIPTS_EXECUTE_SUCC,
|
|
|
+ CSimpleStringA::Format("auto restart sogou services succ: WebSrv pid: %u, Service pid: %u", sogouImeWebSrv_newPID, sogouImeService_newPID));
|
|
|
+ result = Error_Succeed;
|
|
|
+ } else {
|
|
|
+ LogWarn(Severity_Middle, Error_TimeOut, LOG_DEVICECONTROL_SOGOU_SCRIPTS_EXECUTE_SUCC, "wait sogou auto restart timeout");
|
|
|
+ result = Error_TimeOut;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if (s1 && s2) {
|
|
|
+ else if (s1 && s2) {
|
|
|
|
|
|
do {
|
|
|
std::string succStr, errStr;
|