Browse Source

Z991239-4958 #comment 启动判断root.ini是否存在,否则终端启动;获取dns(信创)

oilyang 1 year ago
parent
commit
216e84f651
2 changed files with 52 additions and 10 deletions
  1. 50 9
      Module/mod_vtmloader/VtmLoaderFSM.cpp
  2. 2 1
      Module/mod_vtmloader/VtmLoaderFSM.h

+ 50 - 9
Module/mod_vtmloader/VtmLoaderFSM.cpp

@@ -1310,32 +1310,39 @@ bool CVtmLoaderFSM::DetectHttpActive()
 	else
 		return false;
 }
-bool CVtmLoaderFSM::IsRootINIExist()
+bool CVtmLoaderFSM::IsRootINIExist(CSimpleStringA& path)
 {
 	CSimpleStringA csHardwareCfg(true);
 	ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("HardwareCfg", csHardwareCfg);
 	if (eErr != Error_Succeed)
 	{
+		path = CSimpleStringA::Format("GetPath of HardwareCfg failed(%d)", eErr);
 		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("get path of Run failed:%s", SpStrError(eErr));
-		return true;//return true in default
+		return false;
 	}
-	CSimpleStringA csRootINIPath = csHardwareCfg + SPLIT_SLASH_STR + "root.ini";
+	path = csHardwareCfg + SPLIT_SLASH_STR + "root.ini";
 #if defined(RVC_OS_WIN)
-	if (_access(csRootINIPath.GetData(), 0) == 0) {
+	if (_access(path.GetData(), 0) == 0) {
 #else
-	if (access(csRootINIPath.GetData(), F_OK) == 0) {
+	if (access(path.GetData(), F_OK) == 0) {
 #endif
 		return true;
 	}
 	else
 	{
-		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("root.ini(%s) is not exist.", csRootINIPath.GetData());
+		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("root.ini(%s) is not exist.", path.GetData());
 		return false;
 	}
 }
 bool CVtmLoaderFSM::GetConfig()
 {
-	//TODO 获取配置
+	//拉取配置前先检查root.ini文件
+	CSimpleStringA csTmpRootIni("");
+	if (!IsRootINIExist(csTmpRootIni))
+	{
+		LogWarn(Severity_High, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("root.ini不存在,请检查(%s)", csTmpRootIni.GetData()));
+		return false;
+	}
 	ErrorCodeEnum eErr = Error_Succeed;
 #ifdef DEVOPS_ON_ST /*DevOps流水线编译,ST环境*/
 	CSimpleString channelId = "5fdd82e3b90a4de69f9da4738e5f1216";
@@ -1494,9 +1501,11 @@ int CVtmLoaderFSM::HttpConnCheck(CSimpleStringA csHttAddr, HttpAddrType eType)
 			CAutoArray<NetworkAdapterItem> netList;
 			if (SP::Module::Net::GetINETMacAddresses(netList) == Error_Succeed)
 			{
+				string tmpDns;
+				GetDns(tmpDns);
 				for (int i = 0; i < netList.GetCount(); i++) {
-					LogWarn(Severity_Middle, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("(%d) interface:%s; ip:%s; mac:%s", i, netList[i].description.c_str()
-					, netList[i].ip.c_str(), netList[i].mac.c_str()));
+					LogWarn(Severity_Middle, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("(%d)interface:%s; ip:%s; mac:%s; %s", i, netList[i].description.c_str()
+						, netList[i].ip.c_str(), netList[i].mac.c_str(), tmpDns.c_str()));
 				}
 			}
 		}
@@ -1514,4 +1523,36 @@ int CVtmLoaderFSM::HttpConnCheck(CSimpleStringA csHttAddr, HttpAddrType eType)
 	} 
 
 	return -1;
+}
+void CVtmLoaderFSM::GetDns(string& dns)
+{
+	dns = "";
+#if defined(RVC_OS_LINUX)
+
+	FILE* stream;
+	char* line = NULL;
+	size_t len = 0;
+	ssize_t read;
+
+	stream = popen("cat /etc/resolv.conf", "r");
+	string tmpStr;
+	while ((read = getline(&line, &len, stream)) != -1)
+	{
+		tmpStr = line;
+		int pos = tmpStr.find("nameserver");
+		if (pos != string::npos)
+		{
+			tmpStr = tmpStr.replace(pos, strlen("nameserver"), "dns");
+			dns += tmpStr + ";";
+		}
+	}
+	int rnPos = dns.find("\n");
+	while (rnPos != string::npos)
+	{
+		dns.replace(rnPos, 1, " ");
+		rnPos = dns.find("\n");
+	}
+#else
+#endif
+	return;
 }

+ 2 - 1
Module/mod_vtmloader/VtmLoaderFSM.h

@@ -140,9 +140,10 @@ private:
 
 	ErrorCodeEnum AsyncStartEntity(const char* entity_name, const char* cmdline, void* pData);
 	void OnAnswer(CSmartPointer<IAsynWaitSp> pAsynWaitSp);
-	bool IsRootINIExist();
+	bool IsRootINIExist(CSimpleStringA& path);
 	ErrorCodeEnum SubscribeEntitysEvents();
 	void ShowEntityBootFailedAtFront(LPCTSTR lpcszEntityName, ErrorCodeEnum bootFailedResult, bool isBlock = true);
+	void GetDns(string& dns);
 
 private:
 	CSystemStaticInfo m_sysInfo;