diff --git a/ipc/native/c/ipc/include/ipc_invoker.h b/ipc/native/c/ipc/include/ipc_invoker.h index 73de89cb26719f67bb6f43cd113b4c17fc51dbba..a254e8f1a25062c6ace2d88698cc793b021a7278 100644 --- a/ipc/native/c/ipc/include/ipc_invoker.h +++ b/ipc/native/c/ipc/include/ipc_invoker.h @@ -25,7 +25,7 @@ extern "C" { #endif /* __cplusplus */ RemoteInvoker *GetIpcInvoker(void); - +void DeinitIpcInvoker(RemoteInvoker *invoker); #ifdef __cplusplus #if __cplusplus } diff --git a/ipc/native/c/ipc/src/linux/ipc_invoker.c b/ipc/native/c/ipc/src/linux/ipc_invoker.c index 5c2328256db446f462d499804dba80e9b308c3b2..293b515c3d16b786fc125c6b712b46519f632daf 100644 --- a/ipc/native/c/ipc/src/linux/ipc_invoker.c +++ b/ipc/native/c/ipc/src/linux/ipc_invoker.c @@ -91,10 +91,12 @@ static void DeleteBinderConnector(void) if (g_connector == NULL) { return; } + pthread_mutex_lock(&g_connectorMutex); munmap(g_connector->mmapAddr, g_connector->mmapSize); close(g_connector->fd); free(g_connector); g_connector = NULL; + pthread_mutex_unlock(&g_connectorMutex); } static int32_t BinderWrite(void *data, size_t len) @@ -564,3 +566,11 @@ RemoteInvoker *GetIpcInvoker(void) } return &g_ipcInvoker; } + +void DeinitIpcInvoker(RemoteInvoker *invoker) +{ + if (invoker != &g_ipcInvoker) { + return; + } + DeleteBinderConnector(); +} \ No newline at end of file diff --git a/ipc/native/c/manager/include/iremote_invoker.h b/ipc/native/c/manager/include/iremote_invoker.h index a3ad6d0cac43cc15896a6ae0682e080858a79ef3..22e8ec6f315588ae242d2e5af2c535c0d5894da2 100644 --- a/ipc/native/c/manager/include/iremote_invoker.h +++ b/ipc/native/c/manager/include/iremote_invoker.h @@ -44,6 +44,7 @@ typedef struct { } RemoteInvoker; RemoteInvoker *InitRemoteInvoker(int32_t proto); +void DeinitRemoteInvoker(RemoteInvoker *invoker, int32_t proto); #ifdef __cplusplus #if __cplusplus } diff --git a/ipc/native/c/manager/src/ipc_process_skeleton.c b/ipc/native/c/manager/src/ipc_process_skeleton.c index af76fc745251bae3c62a7d6960a592016cd2fbf4..64dca147ddd96f82f3e89c26d5f54239675a2403 100644 --- a/ipc/native/c/manager/src/ipc_process_skeleton.c +++ b/ipc/native/c/manager/src/ipc_process_skeleton.c @@ -132,18 +132,22 @@ void JoinMainWorkThread(void) pid_t ProcessGetCallingPid(void) { - ThreadContext *currentContext = GetCurrentThreadContext(); - if (currentContext != NULL) { - return currentContext->callerPid; + if (g_ipcSkeleton != NULL) { + ThreadContext *currentContext = GetCurrentThreadContext(); + if (currentContext != NULL) { + return currentContext->callerPid; + } } return RpcGetPid(); } pid_t ProcessGetCallingUid(void) { - ThreadContext *currentContext = GetCurrentThreadContext(); - if (currentContext != NULL) { - return currentContext->callerUid; + if (g_ipcSkeleton != NULL) { + ThreadContext *currentContext = GetCurrentThreadContext(); + if (currentContext != NULL) { + return currentContext->callerUid; + } } return RpcGetUid(); } diff --git a/ipc/native/c/manager/src/ipc_skeleton.c b/ipc/native/c/manager/src/ipc_skeleton.c index 44635e4f160e59bc1362296b3e3d536e7b2246eb..33bc4d080c3e7a390b0f9e197d41bcf1457e882a 100644 --- a/ipc/native/c/manager/src/ipc_skeleton.c +++ b/ipc/native/c/manager/src/ipc_skeleton.c @@ -48,19 +48,11 @@ void JoinWorkThread(void) pid_t GetCallingPid(void) { - if (GetCurrentSkeleton() == NULL) { - RPC_LOG_ERROR("init ipc process skeleton failed."); - return ERR_IPC_SKELETON_NOT_INIT; - } return ProcessGetCallingPid(); } pid_t GetCallingUid(void) { - if (GetCurrentSkeleton() == NULL) { - RPC_LOG_ERROR("init ipc process skeleton failed."); - return ERR_IPC_SKELETON_NOT_INIT; - } return ProcessGetCallingUid(); } diff --git a/ipc/native/c/manager/src/ipc_thread_pool.c b/ipc/native/c/manager/src/ipc_thread_pool.c index c901be3e67eed4d6027915ecd22f9e9f6ab03c5b..4d6b58327f045d4cefefa98692f169a2d94fd122 100644 --- a/ipc/native/c/manager/src/ipc_thread_pool.c +++ b/ipc/native/c/manager/src/ipc_thread_pool.c @@ -133,6 +133,7 @@ void DeinitThreadPool(ThreadPool *threadPool) pthread_key_delete(g_localKey); free(threadPool); for (int32_t index = 0; index < PROTO_NUM; ++index) { + DeinitRemoteInvoker(g_invoker[index], index); g_invoker[index] = NULL; } } diff --git a/ipc/native/c/manager/src/iremote_invoker.c b/ipc/native/c/manager/src/iremote_invoker.c index 477290936a7f95f451fe8c8a26342e81cc18ef81..284dfea3c026d99ece81a0bd7198a22b3126d42d 100644 --- a/ipc/native/c/manager/src/iremote_invoker.c +++ b/ipc/native/c/manager/src/iremote_invoker.c @@ -28,4 +28,14 @@ RemoteInvoker *InitRemoteInvoker(int32_t proto) remoteInvoker = GetRpcInvoker(); } return remoteInvoker; +} + +void DeinitRemoteInvoker(RemoteInvoker *invoker, int32_t proto) +{ + if (invoker == NULL) { + return; + } + if (proto == IF_PROT_BINDER) { + DeinitIpcInvoker(invoker); + } } \ No newline at end of file