|
@@ -1,6 +1,6 @@
|
|
|
// guardian.cpp : Defines the entry point for the console application.
|
|
|
//
|
|
|
-//#include "stdafx.h"
|
|
|
+#include "StdAfx.h"
|
|
|
#ifdef linux
|
|
|
#include <sys/types.h>
|
|
|
#include <sys/stat.h>
|
|
@@ -30,7 +30,6 @@
|
|
|
#include <winpr/synch.h>
|
|
|
#include <winpr/environment.h>
|
|
|
|
|
|
-#define GUARDIAN_VERSION_STR "0.0.1"
|
|
|
|
|
|
int epfd;
|
|
|
struct epoll_event ev;
|
|
@@ -38,9 +37,7 @@ struct epoll_event ev;
|
|
|
#define OPEN_MAX 100
|
|
|
#define LISTENQ 20
|
|
|
#define INFTIM 1000
|
|
|
-
|
|
|
-#else //
|
|
|
-
|
|
|
+#else
|
|
|
#undef UNICODE
|
|
|
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
@@ -63,6 +60,8 @@ struct epoll_event ev;
|
|
|
#define MAX_PATH 260
|
|
|
#endif
|
|
|
|
|
|
+#define GUARDIAN_VERSION_STR "0.0.1"
|
|
|
+
|
|
|
#ifdef RVC_OS_WIN
|
|
|
static char spshell_execute_name[] = "SpShell.exe";
|
|
|
static char sphost_execute_name[] = "SpHost.exe";
|
|
@@ -92,6 +91,10 @@ typedef DWORD (*pDisableBluetooth)(BOOL bDisable);
|
|
|
pthread_mutex_t g_cs, g_cs_event, g_cs_log;
|
|
|
#define EnterCriticalSectionRVC(xType) pthread_mutex_lock(&xType)
|
|
|
#define LeaveCriticalSectionRVC(xType) pthread_mutex_unlock(&xType)
|
|
|
+ static int GetProcID()
|
|
|
+ {
|
|
|
+ return getpid();
|
|
|
+ }
|
|
|
#else
|
|
|
SOCKET g_sListen = INVALID_SOCKET;
|
|
|
#pragma comment (lib, "Ws2_32.lib")
|
|
@@ -99,6 +102,10 @@ typedef DWORD (*pDisableBluetooth)(BOOL bDisable);
|
|
|
CRITICAL_SECTION g_cs, g_cs_event, g_cs_log;
|
|
|
#define EnterCriticalSectionRVC(xType) EnterCriticalSection(&xType)
|
|
|
#define LeaveCriticalSectionRVC(xType) LeaveCriticalSection(&xType)
|
|
|
+ static int GetProcID()
|
|
|
+ {
|
|
|
+ return GetCurrentProcessId();
|
|
|
+ }
|
|
|
#endif //linux
|
|
|
|
|
|
//unsigned int __stdcall DoLog(void *pData);
|
|
@@ -108,8 +115,8 @@ const int SHAKEHAND_BUFZIE = 32;
|
|
|
const int default_port = 30005;
|
|
|
|
|
|
int g_needToRollBack = 0;
|
|
|
-bool g_bFrameQuit = false, g_bFrameOnline = false;
|
|
|
-bool g_bLogFileOpen = false, g_bAuthSuc = false, g_bInUpgrade = false;
|
|
|
+bool g_needUpgradeGuardianOnly = false;
|
|
|
+bool g_bFrameQuit = false,g_bFrameOnline = false,g_bLogFileOpen = false,g_bAuthSuc = false,g_bInUpgrade = false;
|
|
|
ULONGLONG g_dwTimeBegin = 0;
|
|
|
ULONGLONG g_dwUpgradeRestartTimeBegin = 0;
|
|
|
int cnt = 0;
|
|
@@ -118,7 +125,8 @@ char currDirBuf[256];
|
|
|
char chDisk[2];
|
|
|
void NetControl();
|
|
|
const int MAX_WAIT_TIME_TO_RESTART = 600000;
|
|
|
-const int MAX_WAIT_TIME_TO_RESTART_UPGRADE = 110000;
|
|
|
+//oilyang@20211208 change value from 110000 to 180000
|
|
|
+const int MAX_WAIT_TIME_TO_RESTART_UPGRADE = 180000;
|
|
|
int g_startDay = 0;
|
|
|
//HANDLE g_logHandle;
|
|
|
char g_allMsg[1024];
|
|
@@ -131,6 +139,17 @@ extern "C"
|
|
|
void* DoNetControlLinux(void* arg);
|
|
|
}
|
|
|
#define FUNCTION_STDCALL
|
|
|
+typedef unsigned short WORD;
|
|
|
+typedef struct _SYSTEMTIME {
|
|
|
+ WORD wYear;
|
|
|
+ WORD wMonth;
|
|
|
+ WORD wDayOfWeek;
|
|
|
+ WORD wDay;
|
|
|
+ WORD wHour;
|
|
|
+ WORD wMinute;
|
|
|
+ WORD wSecond;
|
|
|
+ WORD wMilliseconds;
|
|
|
+} SYSTEMTIME;
|
|
|
#else
|
|
|
typedef struct
|
|
|
{
|
|
@@ -184,7 +203,7 @@ void GetLocalTimeRVC(SYSTEMTIME& stTime)
|
|
|
stTime.wMilliseconds = wMilliseconds;
|
|
|
}
|
|
|
#else
|
|
|
- GetLocalTime(stTime);
|
|
|
+ GetLocalTime(&stTime);
|
|
|
#endif
|
|
|
}
|
|
|
|
|
@@ -608,10 +627,13 @@ int FrameworkShutdown(bool bUpgrade=false,bool bRestart = true)
|
|
|
csRestart = "sprestart.exe ";
|
|
|
csVerPath = chDisk;
|
|
|
csVerPath += ":\\Run\\version";
|
|
|
- csVerPath +="\\spexplorerfast.vbs";
|
|
|
+ //csVerPath +="\\spexplorerfast.vbs";
|
|
|
+ csVerPath +="\\VTM.exe";
|
|
|
if (!bRestart)
|
|
|
csReFlag = "n";
|
|
|
- csAll = csSep + csRestart + csSep + csBlank + csSep + csScript+csBlank + csVerPath + csSep
|
|
|
+ //csAll = csSep + csRestart + csSep + csBlank + csSep + csScript+csBlank + csVerPath + csSep
|
|
|
+ // + csBlank + csSep + csReFlag + csSep;
|
|
|
+ csAll = csSep + csRestart + csSep + csBlank + csSep + csVerPath + csSep
|
|
|
+ csBlank + csSep + csReFlag + csSep;
|
|
|
LPTSTR szCmdline = _strdup(csAll);
|
|
|
LogSingleMsg(szCmdline);
|
|
@@ -663,7 +685,7 @@ bool ReadRuninfoContent(string &strData)
|
|
|
runinfo.open(strGdRuninfoPath,std::fstream::in|std::fstream::out|std::fstream::binary);
|
|
|
if (!runinfo.is_open())
|
|
|
{
|
|
|
- LogToFile(true, true,false, "open gdruninfo(read) failed",strerror(errno), errno);
|
|
|
+ LogToFile(false, false,false, "open gdruninfo(read) failed.");
|
|
|
return false;
|
|
|
}
|
|
|
runinfo.seekg(0,ios::end);
|
|
@@ -1008,10 +1030,6 @@ void DataProcess(LPPER_HANDLE_DATA pPerHandleData,LPPER_IO_OPERATION_DATA pPerIo
|
|
|
if (!g_bFrameOnline)
|
|
|
{
|
|
|
g_bFrameOnline = true;
|
|
|
-#ifndef _WIN32
|
|
|
- g_SpShellPID = GetSpshellProcID();
|
|
|
- LogToFile(false, true, false, "get spshell proc id", NULL, g_SpShellPID);
|
|
|
-#endif //NOT _WIN32
|
|
|
StartDoNetControlRVC();
|
|
|
}
|
|
|
int rc,err;
|
|
@@ -1039,10 +1057,6 @@ void DataProcess(LPPER_HANDLE_DATA pPerHandleData,LPPER_IO_OPERATION_DATA pPerIo
|
|
|
if (!g_bFrameOnline)
|
|
|
{
|
|
|
g_bFrameOnline = true;
|
|
|
-#ifndef _WIN32
|
|
|
- g_SpShellPID = GetSpshellProcID();
|
|
|
- LogToFile(false, true, false, "get spshell proc id", NULL, g_SpShellPID);
|
|
|
-#endif //NOT _WIN32
|
|
|
//_beginthreadex(NULL,0,DoNetControl,NULL,0,NULL);
|
|
|
StartDoNetControlRVC();
|
|
|
}
|
|
@@ -1053,10 +1067,6 @@ void DataProcess(LPPER_HANDLE_DATA pPerHandleData,LPPER_IO_OPERATION_DATA pPerIo
|
|
|
if (!g_bFrameOnline)
|
|
|
{
|
|
|
g_bFrameOnline = true;
|
|
|
-#ifndef _WIN32
|
|
|
- g_SpShellPID = GetSpshellProcID();
|
|
|
- LogToFile(false, true, false, "get spshell proc id", NULL, g_SpShellPID);
|
|
|
-#endif //NOT _WIN32
|
|
|
//_beginthreadex(NULL,0,DoNetControl,NULL,0,NULL);
|
|
|
StartDoNetControlRVC();
|
|
|
}
|
|
@@ -1076,14 +1086,17 @@ void DataProcess(LPPER_HANDLE_DATA pPerHandleData,LPPER_IO_OPERATION_DATA pPerIo
|
|
|
break;
|
|
|
case GdOpUpgradeRestart:
|
|
|
{
|
|
|
+ if (pInfo->dwParam1 == 6)//need Upgrade guardian !!!Only!!!
|
|
|
+ {
|
|
|
+ g_needUpgradeGuardianOnly = true;
|
|
|
+ }
|
|
|
if (pInfo->dwParam1 == 4)//just know framework is starting...
|
|
|
{
|
|
|
LogSingleMsg("framework is starting...");
|
|
|
+ //oilyang@20211208 add the following if receive framework is starting ,reset g_dwUpgradeRestartTimeBegin
|
|
|
+ //in order to skip the cost time of "kill spshell"
|
|
|
+ g_dwUpgradeRestartTimeBegin = GetTickCountRVC();
|
|
|
g_bFrameOnline = true;
|
|
|
-#ifndef _WIN32
|
|
|
- g_SpShellPID = GetSpshellProcID();
|
|
|
- LogToFile(false, true, false, "get spshell proc id", NULL, g_SpShellPID);
|
|
|
-#endif //NOT _WIN32
|
|
|
g_bAuthSuc = false;
|
|
|
//_beginthreadex(NULL,0,DoNetControl,NULL,0,NULL);
|
|
|
StartDoNetControlRVC();
|
|
@@ -1098,10 +1111,6 @@ void DataProcess(LPPER_HANDLE_DATA pPerHandleData,LPPER_IO_OPERATION_DATA pPerIo
|
|
|
if (!g_bFrameOnline)
|
|
|
{
|
|
|
g_bFrameOnline = true;
|
|
|
-#ifndef _WIN32
|
|
|
- g_SpShellPID = GetSpshellProcID();
|
|
|
- LogToFile(false, true, false, "get spshell proc id", NULL, g_SpShellPID);
|
|
|
-#endif //NOT _WIN32
|
|
|
//_beginthreadex(NULL,0,DoNetControl,NULL,0,NULL);
|
|
|
StartDoNetControlRVC();
|
|
|
}
|
|
@@ -1141,10 +1150,6 @@ void DataProcess(LPPER_HANDLE_DATA pPerHandleData,LPPER_IO_OPERATION_DATA pPerIo
|
|
|
if (!g_bFrameOnline)
|
|
|
{
|
|
|
g_bFrameOnline = true;
|
|
|
-#ifndef _WIN32
|
|
|
- g_SpShellPID = GetSpshellProcID();
|
|
|
- LogToFile(false, true, false, "get spshell proc id", NULL, g_SpShellPID);
|
|
|
-#endif //NOT _WIN32
|
|
|
//_beginthreadex(NULL,0,DoNetControl,NULL,0,NULL);
|
|
|
StartDoNetControlRVC();
|
|
|
}
|
|
@@ -1236,9 +1241,9 @@ unsigned int __stdcall DoWork(void* pData)
|
|
|
LeaveCriticalSectionRVC(g_cs);
|
|
|
ULONGLONG dwTimeEnd = GetTickCountRVC();
|
|
|
//oilyang@20190828 add
|
|
|
- //升级重启后,在10分钟内,只要离最后一次交互时间大于2分钟,重启框架
|
|
|
- if ((g_bInUpgrade && ((dwTimeEnd - dwUpgradeTmpBegin) < MAX_WAIT_TIME_TO_RESTART))
|
|
|
- && (!g_bAuthSuc && ((dwTimeEnd - dwTmpBegin) > MAX_WAIT_TIME_TO_RESTART_UPGRADE)))
|
|
|
+ //升级重启后,在10分钟内,只要离最后一次交互时间大于MAX_WAIT_TIME_TO_RESTART_UPGRADE,重启框架
|
|
|
+ if (g_bInUpgrade && ((dwTimeEnd - dwTmpBegin) < MAX_WAIT_TIME_TO_RESTART)
|
|
|
+ && (!g_bAuthSuc && ((dwTimeEnd - dwUpgradeTmpBegin) > MAX_WAIT_TIME_TO_RESTART_UPGRADE)))
|
|
|
{
|
|
|
LogSingleMsg("**in upgrade restart**,to restart framework.");
|
|
|
FrameworkShutdown(true,true);
|
|
@@ -1268,7 +1273,11 @@ unsigned int __stdcall DoWork(void* pData)
|
|
|
else
|
|
|
{
|
|
|
//framework is down,to restart it! oilyang 20150413
|
|
|
- FrameworkShutdown();
|
|
|
+ //oilyang@20211221 if Upgrade guardian !!!Only!!! ,just reset dwTmpBegin
|
|
|
+ if (!g_needUpgradeGuardianOnly)
|
|
|
+ FrameworkShutdown();
|
|
|
+ else
|
|
|
+ dwTmpBegin = GetTickCountRVC();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1639,7 +1648,7 @@ void CheckGuardianDbgDirAndCreateDbgFile(bool bChangeDay = false)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+#if linux
|
|
|
static void sig_handle(int signo)
|
|
|
{
|
|
|
switch (signo) {
|
|
@@ -1706,16 +1715,17 @@ static void sig_handle(int signo)
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
int main()
|
|
|
{
|
|
|
//attach file descriptors 0,1,2 to /dev/null(for deamon app)
|
|
|
int fd0, fd1, fd2;
|
|
|
+ g_bFrameOnline = true;
|
|
|
+#ifdef linux
|
|
|
fd0 = open("/dev/null", O_RDWR);
|
|
|
fd1 = dup(0);
|
|
|
fd2 = dup(0);
|
|
|
- g_bFrameOnline = true;
|
|
|
-#ifdef linux
|
|
|
pthread_mutex_init(&g_cs_event,NULL);
|
|
|
pthread_mutex_init(&g_cs_log,NULL);
|
|
|
pthread_mutex_init(&g_cs,NULL);
|
|
@@ -1723,7 +1733,7 @@ int main()
|
|
|
InitializeCriticalSectionAndSpinCount(&g_cs_event, 100);
|
|
|
InitializeCriticalSectionAndSpinCount(&g_cs_log, 100);
|
|
|
InitializeCriticalSectionAndSpinCount(&g_cs, 100);
|
|
|
- g_logHandle = CreateEventA(NULL, FALSE, FALSE, NULL);
|
|
|
+// g_logHandle = CreateEventA(NULL, FALSE, FALSE, NULL);
|
|
|
#endif
|
|
|
|
|
|
g_dwTimeBegin = GetTickCountRVC();
|
|
@@ -1787,7 +1797,6 @@ void NetControl()
|
|
|
LogSingleMsg("load CmbPadDll failed!");
|
|
|
#endif //linux
|
|
|
}
|
|
|
-
|
|
|
void LogDebug(bool bRevMsg, bool bCode1,bool bCode2,const char *msg, const char *revmsg, int code1, int code2)
|
|
|
{
|
|
|
SYSTEMTIME st;
|
|
@@ -1799,22 +1808,22 @@ void LogDebug(bool bRevMsg, bool bCode1,bool bCode2,const char *msg, const char
|
|
|
{
|
|
|
if (bCode2)
|
|
|
sprintf(g_allMsg, "[%.2d:%.2d:%.2d.%.3d][%d][DEBUG]%s,%s,%d,%d\r\n", st.wHour, st.wMinute, st.wSecond, st.wMilliseconds,
|
|
|
- getpid(),
|
|
|
+ GetProcID(),
|
|
|
msg, revmsg, code1, code2);
|
|
|
else
|
|
|
sprintf(g_allMsg, "[%.2d:%.2d:%.2d.%.3d][%d][DEBUG]%s,%s %d\r\n", st.wHour, st.wMinute, st.wSecond, st.wMilliseconds,
|
|
|
- getpid(),
|
|
|
+ GetProcID(),
|
|
|
msg, revmsg, code1);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (bCode2)
|
|
|
sprintf(g_allMsg, "[%.2d:%.2d:%.2d.%.3d][%d][DEBUG]%s,%s %d\r\n", st.wHour, st.wMinute, st.wSecond, st.wMilliseconds,
|
|
|
- getpid(),
|
|
|
+ GetProcID(),
|
|
|
msg, revmsg,code2);
|
|
|
else
|
|
|
sprintf(g_allMsg, "[%.2d:%.2d:%.2d.%.3d][%d][DEBUG]%s,%s\r\n", st.wHour, st.wMinute, st.wSecond, st.wMilliseconds,
|
|
|
- getpid(),
|
|
|
+ GetProcID(),
|
|
|
msg, revmsg);
|
|
|
}
|
|
|
}
|
|
@@ -1824,21 +1833,21 @@ void LogDebug(bool bRevMsg, bool bCode1,bool bCode2,const char *msg, const char
|
|
|
{
|
|
|
if (bCode2)
|
|
|
sprintf(g_allMsg, "[%.2d:%.2d:%.2d.%.3d][%d][DEBUG]%s,%d,%d\r\n", st.wHour, st.wMinute, st.wSecond, st.wMilliseconds,
|
|
|
- getpid(),
|
|
|
+ GetProcID(),
|
|
|
msg, code1, code2);
|
|
|
else
|
|
|
sprintf(g_allMsg, "[%.2d:%.2d:%.2d.%.3d][%d][DEBUG]%s %d\r\n", st.wHour, st.wMinute, st.wSecond, st.wMilliseconds,
|
|
|
- getpid(),
|
|
|
+ GetProcID(),
|
|
|
msg, code1);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (bCode2)
|
|
|
sprintf(g_allMsg, "[%.2d:%.2d:%.2d.%.3d][%d][DEBUG]%s %d\r\n", st.wHour, st.wMinute, st.wSecond, st.wMilliseconds,
|
|
|
- getpid(),
|
|
|
+ GetProcID(),
|
|
|
msg, code2);
|
|
|
else
|
|
|
- sprintf(g_allMsg, "[%.2d:%.2d:%.2d.%.3d][%d][DEBUG]%s\r\n", st.wHour, st.wMinute, st.wSecond, st.wMilliseconds, getpid(), msg);
|
|
|
+ sprintf(g_allMsg, "[%.2d:%.2d:%.2d.%.3d][%d][DEBUG]%s\r\n", st.wHour, st.wMinute, st.wSecond, st.wMilliseconds, GetProcID(), msg);
|
|
|
}
|
|
|
}
|
|
|
|