|
@@ -93,8 +93,6 @@ static int diskCheckFlag = 1;
|
|
|
#define HOURS_DIV (60 * 60)
|
|
|
#define MINUS_DIV (60)
|
|
|
|
|
|
-const char* SystemElapsedQuery = "\\System\\System Up Time";
|
|
|
-
|
|
|
#ifndef RVC_OS_LINUX
|
|
|
#define ENCODING (X509_ASN_ENCODING | PKCS_7_ASN_ENCODING)
|
|
|
#define SafeDeleteArraySize(pData) { if(pData){delete []pData;pData=NULL;} }
|
|
@@ -346,9 +344,6 @@ ErrorCodeEnum ResourceWatcherFSM::OnInit()
|
|
|
|
|
|
ErrorCodeEnum erroCode = Error_Succeed;
|
|
|
DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Complied at: %s %s", __DATE__, __TIME__);
|
|
|
-#ifdef WIDE_CONDITION
|
|
|
- setlocale(LC_ALL, "chs");
|
|
|
-#endif
|
|
|
CSmartPointer<IConfigInfo> spRunConfig;
|
|
|
CSmartPointer<IConfigInfo> spCtSettingConfig;
|
|
|
GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spRunConfig);
|
|
@@ -1391,113 +1386,6 @@ ErrorCodeEnum ResourceWatcherFSM::GetBizLinks(
|
|
|
return ec;
|
|
|
}
|
|
|
|
|
|
-///*TODO: 使用共用库的接口 (80374374@11/24/2023)*/
|
|
|
-BOOL ResourceWatcherFSM::GetSystemBootTime(CSmallDateTime& systemBootTime)
|
|
|
-{
|
|
|
-#ifdef RVC_OS_LINUX
|
|
|
- DWORD ticks = 0;
|
|
|
- SYSTEMTIME systemTime;
|
|
|
-
|
|
|
- struct sysinfo info;
|
|
|
- time_t curTime = 0;
|
|
|
- time_t bootTime = 0;
|
|
|
- struct tm* ptm = NULL;
|
|
|
- if (sysinfo(&info)) {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Failed to get sysinfo, errno:%u, reason:%s", errno, strerror(errno));
|
|
|
- return FALSE;
|
|
|
- }
|
|
|
- time(&curTime);
|
|
|
- if (curTime > info.uptime) {
|
|
|
- bootTime = curTime - info.uptime;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- bootTime = info.uptime - curTime;
|
|
|
- }
|
|
|
- ptm = localtime(&bootTime);
|
|
|
- struct timespec ts;
|
|
|
- if (!clock_gettime(CLOCK_MONOTONIC_RAW, &ts))
|
|
|
- ticks = (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000);
|
|
|
-
|
|
|
- systemTime.wYear = (WORD)(ptm->tm_year + 1900);
|
|
|
- systemTime.wMonth = (WORD)(ptm->tm_mon + 1);
|
|
|
- systemTime.wDayOfWeek = (WORD)ptm->tm_wday;
|
|
|
- systemTime.wDay = (WORD)ptm->tm_mday;
|
|
|
- systemTime.wHour = (WORD)ptm->tm_hour;
|
|
|
- systemTime.wMinute = (WORD)ptm->tm_min;
|
|
|
- systemTime.wSecond = (WORD)ptm->tm_sec;
|
|
|
- systemTime.wMilliseconds = (WORD)(ticks % 1000);
|
|
|
-
|
|
|
- systemBootTime.FromSystemTime(systemTime);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("OSStartTime: %s", systemBootTime.ToTimeString().GetData());
|
|
|
- return TRUE;
|
|
|
-#else
|
|
|
- PDH_STATUS Status;
|
|
|
- HQUERY Query = NULL;
|
|
|
- HCOUNTER hcElapsedTimeCount;
|
|
|
- BOOL fSuc = FALSE;
|
|
|
- /** 杀毒软件会对附件这几个系统调用函数有所监控,导致有时会耗费5s时间 Gifur@20221019]*/
|
|
|
- Status = PdhOpenQuery(NULL, NULL, &Query);
|
|
|
- PDH_FMT_COUNTERVALUE counterValue;
|
|
|
- if (Status != ERROR_SUCCESS) {
|
|
|
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("PdhOpenQuery failed with status 0x%x.", Status);
|
|
|
- goto Cleanup;
|
|
|
- }
|
|
|
- Status = PdhAddCounter(Query, SystemElapsedQuery, NULL, &hcElapsedTimeCount);
|
|
|
- if (Status != ERROR_SUCCESS) {
|
|
|
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("PdhAddCounter for SystemElapsedQuery failed with status 0x%x.", Status);
|
|
|
- goto Cleanup;
|
|
|
- }
|
|
|
- // 查询性能监视器数据
|
|
|
- Status = PdhCollectQueryData(Query);
|
|
|
- if (Status != ERROR_SUCCESS) {
|
|
|
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("PdhCollectQueryData failed with 0x%x.", Status);
|
|
|
- goto Cleanup;
|
|
|
- }
|
|
|
- Status = PdhGetFormattedCounterValue(hcElapsedTimeCount, PDH_FMT_LARGE, NULL, &counterValue);
|
|
|
- if (Status == ERROR_SUCCESS) {
|
|
|
- ULONGLONG ulSinceSeconds = counterValue.largeValue;
|
|
|
- ULONG days = 0, hours = 0, minutes = 0, seconds = 0;
|
|
|
- days = ULONG(ulSinceSeconds / DAY_DIV);
|
|
|
- ulSinceSeconds %= DAY_DIV;
|
|
|
- hours = ULONG(ulSinceSeconds / HOURS_DIV);
|
|
|
- ulSinceSeconds %= HOURS_DIV;
|
|
|
- minutes = ULONG(ulSinceSeconds / MINUS_DIV);
|
|
|
- ulSinceSeconds %= MINUS_DIV;
|
|
|
- seconds = ULONG(ulSinceSeconds);
|
|
|
-
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("SystemElapseTime: %u %02u:%02u:%02u", days, hours, minutes, seconds);
|
|
|
-
|
|
|
- FILETIME ftCurTime, ftStartTime;
|
|
|
- GetSystemTimeAsFileTime(&ftCurTime);
|
|
|
- ULARGE_INTEGER uliCurTime;
|
|
|
- uliCurTime.HighPart = ftCurTime.dwHighDateTime;
|
|
|
- uliCurTime.LowPart = ftCurTime.dwLowDateTime;
|
|
|
- uliCurTime.QuadPart -= counterValue.largeValue * 1e7;
|
|
|
-
|
|
|
- ftStartTime.dwHighDateTime = uliCurTime.HighPart;
|
|
|
- ftStartTime.dwLowDateTime = uliCurTime.LowPart;
|
|
|
-
|
|
|
- SYSTEMTIME stUTC, stLocal;
|
|
|
-
|
|
|
- FileTimeToSystemTime(&ftStartTime, &stUTC);
|
|
|
- char temp[22];
|
|
|
- SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);
|
|
|
- sprintf_s(temp, 22, "%d-%02d-%02d %02d:%02d:%02d",
|
|
|
- stLocal.wYear, stLocal.wMonth, stLocal.wDay, stLocal.wHour, stLocal.wMinute, stLocal.wSecond);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("OSStartTime: %s", temp);
|
|
|
- systemBootTime.FromSystemTime(stLocal);
|
|
|
- fSuc = TRUE;
|
|
|
- }
|
|
|
-Cleanup:
|
|
|
- Status = PdhRemoveCounter(hcElapsedTimeCount);
|
|
|
- if (Query) {
|
|
|
- PdhCloseQuery(Query);
|
|
|
- }
|
|
|
- return fSuc;
|
|
|
-#endif // RVC_OS_LINUX
|
|
|
-}
|
|
|
-
|
|
|
#ifdef _MSC_VER
|
|
|
bool ResourceWatcherFSM::CreateLinkFile(const CSimpleStringA& szStartAppPath, const CSimpleStringA& szAddCmdLine,
|
|
|
const CSimpleStringA& szDestLnkPath, const CSimpleStringA& szIconPath)
|
|
@@ -1975,9 +1863,9 @@ void ResourceWatcherFSM::DetectVersionHasChangedAndWarn()
|
|
|
CSimpleStringA rootVerPath;
|
|
|
CSimpleStringA warnInfo = CSimpleStringA::Format("version changed from %s to %s", lastVer.ToString().GetData(), m_RvcSysinfo.InstallVersion.ToString().GetData());
|
|
|
GetEntityBase()->GetFunction()->GetPath("RootVer", rootVerPath);
|
|
|
- CSimpleStringA csPath = rootVerPath + "\\active.txt";
|
|
|
+ CSimpleStringA csPath = rootVerPath + SPLIT_SLASH_STR + "active.txt";
|
|
|
if (!ExistsFileA(csPath)) {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA5A0A").setAPI("DetectVersionHasChangedAndWarn")
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA5A0A").setAPI(__FUNCTION__)
|
|
|
("%s: active.txt not exist!", warnInfo.GetData());
|
|
|
LogWarn(Severity_Middle, Error_Debug, LOG_WARN_ACTIVE_FILE_CHANGE, CSimpleStringA::Format("%s: active.txt not exist!", warnInfo.GetData()));
|
|
|
}
|
|
@@ -1993,7 +1881,7 @@ void ResourceWatcherFSM::DetectVersionHasChangedAndWarn()
|
|
|
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS,
|
|
|
NULL);
|
|
|
if (hFile == INVALID_HANDLE_VALUE) {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA5A0A").setAPI("DetectVersionHasChangedAndWarn")
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA5A0A").setAPI(__FUNCTION__)
|
|
|
("%s: active.txt open failed %u", warnInfo.GetData(), GetLastError());
|
|
|
LogWarn(Severity_Middle, Error_Debug, LOG_WARN_ACTIVE_FILE_CHANGE, CSimpleStringA::Format("%s: active.txt open failed %u", warnInfo.GetData(), GetLastError()));
|
|
|
}
|
|
@@ -2008,7 +1896,7 @@ void ResourceWatcherFSM::DetectVersionHasChangedAndWarn()
|
|
|
GetTimeFormatStr(szFormat2, 128, (FILETIME*)&activeFileInfo.mftAccess);
|
|
|
char szFormat3[128] = { 0 };
|
|
|
GetTimeFormatStr(szFormat3, 128, (FILETIME*)&activeFileInfo.mftModified);
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA5A0A").setAPI("DetectVersionHasChangedAndWarn")
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA5A0A").setAPI(__FUNCTION__)
|
|
|
("%s: active.txt create at %s, access at %s, modified at %s", warnInfo.GetData(), szFormat1, szFormat2, szFormat3);
|
|
|
LogWarn(Severity_Middle, Error_Debug, LOG_WARN_ACTIVE_FILE_CHANGE, CSimpleStringA::Format(
|
|
|
"%s: active.txt create at %s, access at %s, modified at %s", warnInfo.GetData(), szFormat1, szFormat2, szFormat3));
|
|
@@ -3763,31 +3651,15 @@ void ResourceWatcherFSM::AlarmSystemBasicInfo()
|
|
|
|
|
|
BOOL ResourceWatcherFSM::DetectIsFirstRunAtBoot()
|
|
|
{
|
|
|
- CSystemRunInfo runInfo = { 0 };
|
|
|
- GetEntityBase()->GetFunction()->GetSystemRunInfo(runInfo);
|
|
|
- BOOL bSet = FALSE;
|
|
|
- CBootInfo bootInfo = { 0 };
|
|
|
- CSmallDateTime dateTime(0);
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("systemRunInfo time: %s", (LPCTSTR)runInfo.tmStart.ToTimeString());
|
|
|
- ErrorCodeEnum erroCode = GetEntityBase()->GetFunction()->GetRebootInfo(/*runInfo.tmStart*/dateTime, bootInfo);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("bootInfor time: %s", (LPCTSTR)bootInfo.tmStart.ToTimeString());
|
|
|
- CSmallDateTime systemBootTime;
|
|
|
- BOOL bRet = GetSystemBootTime(systemBootTime);
|
|
|
- if (bRet && systemBootTime > bootInfo.tmStart) {
|
|
|
- ErrorCodeEnum eRet = GetEntityBase()->GetFunction()->SetSysVar(SYSVAR_FRAMEWORK_FIRST_BOOT, SYSVAR_FRAMEWORK_FIRST_BOOT_YES);
|
|
|
- if (eRet != Error_Succeed) {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Set %s with %s failed: %d", SYSVAR_FRAMEWORK_FIRST_BOOT, SYSVAR_FRAMEWORK_FIRST_BOOT_YES, eRet);
|
|
|
- }
|
|
|
- bSet = TRUE;
|
|
|
- std::map<std::string, std::string> srcData;
|
|
|
- CSimpleStringA strData = CSimpleStringA::Format("{\"AppLastStartTime\":\"%s\",\"AppStartTime\":\"%s\",\"OSStartTime\":\"%s\"}"
|
|
|
- , (LPCTSTR)bootInfo.tmStart.ToTimeString(), (LPCTSTR)runInfo.tmStart.ToTimeString(), systemBootTime.ToTimeString().GetData());
|
|
|
- LogWarn(Severity_Low, Error_Debug, LOG_RESOURCEWATCHER_FIRST_RUN_AFTER_BOOT, strData.GetData());
|
|
|
+ const BOOL bSet = SP::Module::Comm::IsFirsRunAppAfterSystemBoot(GetEntityBase());
|
|
|
+ if (bSet) {
|
|
|
+ ErrorCodeEnum eRet = GetEntityBase()->GetFunction()->SetSysVar(SYSVAR_FRAMEWORK_FIRST_BOOT, SYSVAR_FRAMEWORK_FIRST_BOOT_YES);
|
|
|
+ if (eRet != Error_Succeed) {
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Set %s with %s failed: %d", SYSVAR_FRAMEWORK_FIRST_BOOT, SYSVAR_FRAMEWORK_FIRST_BOOT_YES, eRet);
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- GetEntityBase()->GetFunction()->SetSysVar(SYSVAR_FRAMEWORK_FIRST_BOOT, SYSVAR_FRAMEWORK_FIRST_BOOT_NO);
|
|
|
- bSet = FALSE;
|
|
|
+ else {
|
|
|
+ GetEntityBase()->GetFunction()->SetSysVar(SYSVAR_FRAMEWORK_FIRST_BOOT, SYSVAR_FRAMEWORK_FIRST_BOOT_NO);
|
|
|
}
|
|
|
return bSet;
|
|
|
}
|
|
@@ -3974,15 +3846,6 @@ void ResourceWatcherFSM::UploadSysVersionInfo(UINT& ver)
|
|
|
}
|
|
|
srcData.insert(std::make_pair("cpu-type", sucContent));
|
|
|
} while (false);
|
|
|
-
|
|
|
- //#if defined(RVC_OS_LINUX)
|
|
|
- // CSystemStaticInfo sysInfo;
|
|
|
- // ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetSystemStaticInfo(sysInfo);
|
|
|
- // if (eErr == Error_Succeed) {
|
|
|
- // termInfo["MachineMode"] = (LPCTSTR)sysInfo.strMachineModel;
|
|
|
- // termInfo["MachineSN"] = (LPCTSTR)sysInfo.strMachineSN;
|
|
|
- // }
|
|
|
- //#endif //RVC_OS_LINUX
|
|
|
auto ret = generateJsonStr(srcData);
|
|
|
LogWarn(Severity_Low, Error_Hardware, LOG_RESOURCEWATCHER_SYSTEMINFO, ret.second.c_str());
|
|
|
}
|