From 5a23a8d642848df6a98793f1fe661d69f4fb2ec6 Mon Sep 17 00:00:00 2001 From: chenbingbing Date: Fri, 9 Aug 2024 16:56:37 +0800 Subject: [PATCH 1/2] fix get proxy invalid after service dead Signed-off-by: chenbingbing --- samgr_client/source/remote_register_rpc.c | 10 +++++++--- samgr_endpoint/source/default_client.h | 1 + samgr_endpoint/source/default_client_rpc.c | 23 ++++++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/samgr_client/source/remote_register_rpc.c b/samgr_client/source/remote_register_rpc.c index 5a630dd..41ba76d 100644 --- a/samgr_client/source/remote_register_rpc.c +++ b/samgr_client/source/remote_register_rpc.c @@ -78,7 +78,10 @@ IUnknown *SAMGR_FindServiceApi(const char *service, const char *feature) SaName key = {service, feature}; int index = VECTOR_FindByKey(&g_remoteRegister.clients, &key); if (index != INVALID_INDEX) { - return VECTOR_At(&g_remoteRegister.clients, index); + IUnknown *proxy = VECTOR_At(&g_remoteRegister.clients, index); + if (SAMGR_IsProxyValid(proxy)) { + return proxy; + } } IUnknown *proxy = SAMGR_CreateIProxy(service, feature); if (proxy == NULL) { @@ -87,9 +90,10 @@ IUnknown *SAMGR_FindServiceApi(const char *service, const char *feature) MUTEX_Lock(g_remoteRegister.mtx); index = VECTOR_FindByKey(&g_remoteRegister.clients, &key); if (index != INVALID_INDEX) { + IUnknown *oldProxy = VECTOR_Swap(&g_remoteRegister.clients, index, proxy); MUTEX_Unlock(g_remoteRegister.mtx); - proxy->Release(proxy); - return VECTOR_At(&g_remoteRegister.clients, index); + oldProxy->Release(oldProxy); + return proxy; } VECTOR_Add(&g_remoteRegister.clients, proxy); MUTEX_Unlock(g_remoteRegister.mtx); diff --git a/samgr_endpoint/source/default_client.h b/samgr_endpoint/source/default_client.h index d1cfdb9..25b4066 100644 --- a/samgr_endpoint/source/default_client.h +++ b/samgr_endpoint/source/default_client.h @@ -28,6 +28,7 @@ struct SaName { const char *feature; }; +BOOL SAMGR_IsProxyValid(IUnknown *proxy); IUnknown *SAMGR_CreateIProxy(const char *service, const char *feature); IUnknown *SAMGR_CreateIRemoteProxy(const char *deviceId, const char *service, const char *feature); SaName *SAMGR_GetSAName(const IUnknown *proxy); diff --git a/samgr_endpoint/source/default_client_rpc.c b/samgr_endpoint/source/default_client_rpc.c index d18730b..ecfa3cb 100644 --- a/samgr_endpoint/source/default_client_rpc.c +++ b/samgr_endpoint/source/default_client_rpc.c @@ -24,6 +24,29 @@ static SvcIdentity QueryRemoteIdentity(const char *deviceId, const char *service static const IClientEntry DEFAULT_ENTRY = {CLIENT_IPROXY_BEGIN, .Invoke = ProxyInvoke, IPROXY_END}; static MutexId g_mutex = NULL; +BOOL SAMGR_IsProxyValid(IUnknown *proxy) +{ + if (proxy != NULL) { + IDefaultClient *client = GET_OBJECT(proxy, IDefaultClient, entry.iUnknown); + if (client == NULL) { + return false; + } + IClientHeader *header = &client->header; + if (header == NULL) { + return false; + } + if (header->deadId == INVALID_INDEX && + header->target.handle == INVALID_INDEX && + header->target.token == INVALID_INDEX && + header->target.cookie == INVALID_INDEX) { + return false; + } else { + return true; + } + } + return false; +} + IUnknown *SAMGR_CreateIProxy(const char *service, const char *feature) { SvcIdentity identity = QueryIdentity(service, feature); -- Gitee From a4ba46b5781e2376d0e55a1db10786096b22d19f Mon Sep 17 00:00:00 2001 From: chenbingbing Date: Tue, 13 Aug 2024 01:53:23 +0000 Subject: [PATCH 2/2] update samgr_client/source/remote_register_rpc.c. Signed-off-by: chenbingbing --- samgr_client/source/remote_register_rpc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/samgr_client/source/remote_register_rpc.c b/samgr_client/source/remote_register_rpc.c index 41ba76d..2471a04 100644 --- a/samgr_client/source/remote_register_rpc.c +++ b/samgr_client/source/remote_register_rpc.c @@ -92,7 +92,9 @@ IUnknown *SAMGR_FindServiceApi(const char *service, const char *feature) if (index != INVALID_INDEX) { IUnknown *oldProxy = VECTOR_Swap(&g_remoteRegister.clients, index, proxy); MUTEX_Unlock(g_remoteRegister.mtx); - oldProxy->Release(oldProxy); + if (oldProxy != NULL) { + oldProxy->Release(oldProxy); + } return proxy; } VECTOR_Add(&g_remoteRegister.clients, proxy); -- Gitee