Răsfoiți Sursa

Z991239-385 #comment 修复系统变量订阅结构体的引用计数未初始化的BUG

gifur 5 ani în urmă
părinte
comite
722232a49a

+ 25 - 8
Common/SpTest.h

@@ -8,6 +8,10 @@
 
 //helper macro for test temporary.
 
+#define TEST_MODE_SWITCH_ON 1
+
+#if defined(TEST_MODE_SWITCH_ON) && TEST_MODE_SWITCH_ON == 1
+
 #define IFFAILRET(func)	\
 do  {	\
 	ErrorCodeEnum errorCode = func;	\
@@ -30,7 +34,6 @@ do  {	\
 	}	\
 } while (false)
 
-
 #define REQUIRE(expr)	\
 do  {	\
 	if (!(expr)) {	\
@@ -40,10 +43,6 @@ do  {	\
 	}	\
 } while (false)
 
-
-#define REQUIRE_FALSE(expr)	\
-	REQUIRE(!(expr))
-
 #define CHECK(expr)	\
 do  {	\
 	if (!(expr)) {	\
@@ -53,9 +52,6 @@ do  {	\
 	}	\
 } while (false)
 
-#define CHECK_FALSE(expr)	\
-	CHECK(!(expr))
-
 #define THROW_FATAL(fmt, ...)	\
 	LogError(Severity_High, Error_Failed, 0, \
 	CSimpleStringA::Format("%s at file: <%s>, line: %d", \
@@ -66,6 +62,27 @@ do  {	\
 	CSimpleStringA::Format("%s at file: <%s>, line: %d", \
 		(LPCTSTR)CSimpleStringA::Format(fmt, ##__VA_ARGS__), _GetFileName(__FILE__), __LINE__))
 
+#else
+
+#define IFFAILRET(func)
+
+#define IFFAILBREAK(func)
+
+#define REQUIRE(expr)
+
+#define CHECK(expr)
+
+#define THROW_FATAL(fmt, ...)
+
+#define THROW_ERROR(fmt, ...)
+
+#endif
+
+#define REQUIRE_FALSE(expr)	\
+	REQUIRE(!(expr))
+
+#define CHECK_FALSE(expr)	\
+	CHECK(!(expr))
 
 /** Test Case */
 

+ 3 - 1
libtoolkit/unix/bus.c

@@ -1221,9 +1221,11 @@ TOOLKIT_API int bus_endpt_post_msg(bus_endpt_t* endpt, int msg, int nparam, para
 		rc = write(endpt->msg_fd, &wdata, sizeof wdata);
 	} while (rc < 0 && rc == EINTR);
 	if (rc == -1) {
-		WLog_ERR(TAG, "write to eventfd failed: %d", errno);
+		WLog_ERR(TAG, "<== endpt(%d) post msg: %d failed: %d", endpt->epid, msg, errno);
 		return -1;
 	}
+
+	WLog_DBG(TAG, "<== endpt(%d) post msg: %d", endpt->epid, msg);
 	return 0;
 }
 

+ 1 - 1
module/mod_helloclient/mod_helloclient.cpp

@@ -65,10 +65,10 @@ public:
 			Dbg("Connect failed!");
 			client->SafeDelete();
 		}
-#endif
 
 		m_pClient = new HelloService_ClientBase(this);
 		m_pClient->Connect();
+#endif
 	}
 
 	virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext) 

+ 4 - 1
module/mod_testNormalEntity/mod_testNormalEntity.cpp

@@ -57,7 +57,7 @@ ErrorCodeEnum CNormalEntityTest::__onTest()
 	if (0 == GetFunction()->GetEntityStaticInfo(GetEntityName(), entStaticInfo)) {
 		wDevID = entStaticInfo.wEntityDevelopID;
 	}
-
+#if 1
 	CSystemStaticInfo sysStaticInfo;
 	IFFAILRET(func->GetSystemStaticInfo(sysStaticInfo));
 	REQUIRE(sysStaticInfo.strTerminalID.GetLength() == 10);
@@ -144,6 +144,7 @@ ErrorCodeEnum CNormalEntityTest::__onTest()
 	REQUIRE(strStartedEntityNames.GetCount() > 0);
 	REQUIRE(strStartedEntityNames.GetCount() == strEntityInstanceIDs.GetCount());
 	for (int i = 0; i < strStartedEntityNames.GetCount(); ++i) {
+		Dbg("started entity name: %s", strStartedEntityNames[i].GetData());
 		CEntityRunInfo curRunInfo;
 		IFFAILRET(func->GetEntityRunInfo(strStartedEntityNames[i], curRunInfo));
 		CAutoArray<CEntitySessionInfo> sesInfos;
@@ -180,6 +181,8 @@ ErrorCodeEnum CNormalEntityTest::__onTest()
 	IFFAILRET(func->OpenConfig(Config_CenterSetting, configInfoPtr));
 	REQUIRE(configInfoPtr != NULL);
 
+#endif
+
 	return Error_Succeed;
 }
 

+ 5 - 0
module/mod_testPrivilegeEntity/mod_testPrivilegeEntity.cpp

@@ -34,6 +34,9 @@ private:
 
 ErrorCodeEnum CPrivilegeEntityTest::_onTest()
 {
+
+#if 1
+
 	REQUIRE(GetFunction()->HasPrivilege());
 	auto privilegeFunc = GetFunction()->GetPrivilegeFunction();
 	REQUIRE(privilegeFunc != NULL);
@@ -130,6 +133,8 @@ ErrorCodeEnum CPrivilegeEntityTest::_onTest()
 	CSmartPointer<IEntityFunctionPrivilege> privilegeFunc2 = GetFunction().ConvertCase<IEntityFunctionPrivilege>();
 	REQUIRE(privilegeFunc2 != NULL);
 	REQUIRE((uintptr_t)privilegeFunc2.GetRawPointer() == (uintptr_t)privilegeFunc.GetRawPointer());
+
+#endif
 	return Error_Succeed;
 }
 

+ 7 - 0
module/mod_testSendLog/mod_testSendLog.cpp

@@ -30,6 +30,9 @@ private:
 
 	ErrorCodeEnum __onTest()
 	{
+
+#if 1
+
 		WORD wDevID = 0;
 		CEntityStaticInfo entStaticInfo = { 0 };
 		IFFAILRET(GetFunction()->GetEntityStaticInfo(GetEntityName(), entStaticInfo));
@@ -51,6 +54,10 @@ private:
 			}
 		}
 		LOG_TRACE(SENDLOG_String_Context);
+
+
+#endif
+
 		return Error_Succeed;
 	}
 };

+ 11 - 6
module/mod_testSubscribe/mod_testSubscribe.cpp

@@ -94,9 +94,6 @@ public:
 	virtual void OnStarted()
 	{
 		LOG_FUNCTION();
-		//after TestLogSender started, it schedules a timer fired 10s and send some log. This entity would catch it
-		//so here set a timer to confirm its validity, the interval must great than 10s.
-		GetFunction()->SetTimer(1, this, SENDLOG_LOG_SEND_INTERVAL + 2000);
 	}
 
 	virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext) 
@@ -133,11 +130,11 @@ public:
 		if (m_logCalCount) {
 			m_logCalCount[wEntityDevelID][eLogType][eLevel]++;
 		}
-		bool isCorrected = true;
+		bool bDisplay = true;
 		do 
 		{
 			if (wEntityDevelID == SAMPLE_ENTITY_DEV_ID) {
-				isCorrected = false;
+				
 				if (CSimpleStringA(SENDLOG_String_Context).Compare(pszMessage)) {
 					THROW_ERROR("Log from testLogSender is not correct!");
 					break;
@@ -163,7 +160,8 @@ public:
 			}
 
 		} while (false);
-		if (isCorrected) {
+
+		if (bDisplay) {
 			Dbg("OnLog(%s, %d, %d, 0x%X, 0x%X, 0x%X, 0x%04X, %s, %s, %s",
 				(LPCTSTR)nLogID.ToString(), eLogType, eLevel, dwSysError, dwUserCode,
 				dwEntityInstanceID, wEntityDevelID, pszEntityName, pszModuleName, pszMessage);
@@ -177,6 +175,7 @@ private:
 
 	ErrorCodeEnum __onTest()
 	{
+		//Sleep(30000);
 		Dbg("to subscribe all entity log.");
 		IFFAILRET(GetFunction()->SubscribeLog(m_logSubUUID, this, Log_Ignore, Severity_None, Error_IgnoreAll, -2, NULL, false));
 		
@@ -194,6 +193,12 @@ private:
 		Dbg("to listeren specified sys key: %s", SYSVAL_CHANGED_KEY_NAME);
 		IFFAILRET(GetFunction()->RegistSysVarEvent(SYSVAL_CHANGED_KEY_NAME, this));
 
+#if 1
+		//after TestLogSender started, it schedules a timer fired 10s and send some log. This entity would catch it
+		//so here set a timer to confirm its validity, the interval must great than 10s.
+		GetFunction()->SetTimer(1, this, SENDLOG_LOG_SEND_INTERVAL + 2000);
+
+#endif
 		return Error_Succeed;
 	}
 };

+ 1 - 1
spbase/CodeSignVerify.cpp

@@ -436,7 +436,7 @@ bool CCodeSignVerify::GetSignCertInfo(HCERTSTORE hStore, PCMSG_SIGNER_INFO pSign
 		char szHash[64] = {};
 		for (int i = 0; i < 20; i++)
 		{
-			sprintf(szHash, "%s%02x", szHash, hash[i]);
+			sprintf(szHash, "%s%02x", szHash, hash[i]); //TODO: a little bit disgusting. 
 		}
 		strCertHash = szHash;
 

+ 1 - 3
spbase/SpEntity.cpp

@@ -1912,9 +1912,7 @@ void SpEntity::__on_rpc_request(sp_rpc_client_mgr_t *mgr, int epid, int svc_id,
 {
 	SpEntity *pThis = static_cast<SpEntity*>(user_data);	
 
-#if _DEBUG
-	//Dbg("on_rpc_req(), calltype: %d", call_type);
-#endif
+	Dbg("on_rpc_req(), calltype: %d", call_type);
 
 	if (call_type == ENTITY_CMD_REQ_QUERY_ENTITY_SESSIONS)
 	{

+ 9 - 4
spbase/sp_var.c

@@ -258,6 +258,7 @@ static void listener_on_pkt_threadpool(threadpool_t *threadpool, void *arg)
 	if (pkt)
 		iobuffer_dec_ref(pkt);
 
+	sp_dbg_debug("%s: dec ref", __FUNCTION__);
 	sp_var_listener_dec_ref(listener); //@
 
 	sp_svc_pop_runserial_context(svc);
@@ -274,8 +275,10 @@ static int listener_on_pkt(sp_svc_t *svc,int epid, int svc_id, int pkt_type, int
 		iobuffer_write_head(pkt, IOBUF_T_I4, &svc_id, 0);
 		iobuffer_write_head(pkt, IOBUF_T_I4, &epid, 0);
 		iobuffer_write_head(pkt, IOBUF_T_PTR, &listener, 0);
+		sp_dbg_debug("%s: inc ref", __FUNCTION__);
 		sp_var_listener_inc_ref(listener);//@
 		if (threadpool_queue_workitem(sp_svc_get_threadpool(svc), listener->strand, &listener_on_pkt_threadpool, pkt) < 0) {
+			sp_dbg_debug("%s: dec ref", __FUNCTION__);
 			sp_var_listener_dec_ref(listener);//@
 			iobuffer_dec_ref(pkt);
 		}
@@ -293,16 +296,17 @@ int sp_var_listener_create(sp_svc_t *svc, const char *key, sp_var_on_change on_c
 	listener->strand = strand_create();
 	listener->key = _strdup(key);
 	listener->svc = svc;
+	REF_COUNT_INIT(&listener->ref_cnt); // BugFix for @ [Gifur@202051]
 	*p_listener = listener;
 
-	sp_dbg_debug("create listener %llu for key %s (%llu)." , listener, listener->key, (void*)listener->key);
+	sp_dbg_debug("create listener %llu for key %s (%u)." , listener, listener->key, (void*)listener->key);
 	return 0;
 }
 
 static void __sp_var_listener_destroy(sp_var_listener_t *listener)
 {
 	strand_destroy(listener->strand);
-	sp_dbg_debug("free listener %llu for key %s (%llu).", listener, listener->key, (void*)listener->key);
+	sp_dbg_debug("free listener %llu for key %s (%u).", listener, listener->key, (void*)listener->key);
 	free(listener->key);
 	free(listener);
 }
@@ -310,6 +314,7 @@ IMPLEMENT_REF_COUNT_MT_STATIC(sp_var_listener, sp_var_listener_t, ref_cnt, __sp_
 
 void sp_var_listener_destroy(sp_var_listener_t *listener)
 {
+	sp_dbg_debug("%s: dec ref", __FUNCTION__);
 	sp_var_listener_dec_ref(listener);
 }
 
@@ -322,7 +327,7 @@ int sp_var_listener_subscribe(sp_var_listener_t *listener)
 		return Error_Duplication;
 
 	pkt = iobuffer_create(-1, -1);
-
+	//TODO: int is dangerous.
 	sp_svc_add_pkt_handler(listener->svc, (int)listener, SP_PKT_VAR, &listener_on_pkt, listener);
 
 	iobuffer_write(pkt, IOBUF_T_STR, listener->key, -1);
@@ -418,7 +423,7 @@ static int daemon_on_pkt(sp_svc_t *svc,int epid, int svc_id, int pkt_type, int p
 		daemon_lock(daemon);
 		for (i = 0; i < daemon->arr_listener->nelts; ++i) {
 			var_listener_entry* tmp = ARRAY_IDX(daemon->arr_listener, i, var_listener_entry*);
-			if (_stricmp(tmp->key, "*")==0 || _stricmp(key, tmp->key) == 0) {
+			if (_stricmp(tmp->key, "*") == 0 || _stricmp(key, tmp->key) == 0) {
 				iobuffer_t *copy_pkt;
 				if (i == daemon->arr_listener->nelts-1) {
 					copy_pkt = pkt;