diff --git a/README.md b/README.md index a8b4fda2f15eee7689691866c64f0c02d75553ae..87f6aa005ac298b3a279d309bf5c00a625dfbd41 100755 --- a/README.md +++ b/README.md @@ -627,7 +627,7 @@ Main objects of the SA framework: ## Repositories Involved -[Distributed Scheduler subsystem](en-us_topic_0000001115719369.md) +Distributed Scheduler subsystem -**[samgr\_lite](https://gitee.com/openharmony/distributedschedule_services_samgr_lite)** +**samgr\_lite** diff --git a/README_zh.md b/README_zh.md index be87849ea928fe20cb7bfa8bedb0b00e050bf0bd..9e14fd19ab288bc22b6537df27d4c43f2fdec338 100755 --- a/README_zh.md +++ b/README_zh.md @@ -627,7 +627,7 @@ ## 涉及仓 -**[分布式任务调度子系统](zh-cn_topic_0000001115719369.md)** +分布式任务调度子系统 -[samgr\_lite](https://gitee.com/openharmony/distributedschedule_services_samgr_lite) +**samgr\_lite** diff --git a/interfaces/kits/registry/iproxy_client.h b/interfaces/kits/registry/iproxy_client.h index 302a6752707776354b7f8aa59befe648b3ff231f..19ec48e56bdd76feefb9ef5daa5abe7b47a0dc2f 100755 --- a/interfaces/kits/registry/iproxy_client.h +++ b/interfaces/kits/registry/iproxy_client.h @@ -52,7 +52,7 @@ extern "C" { #endif #endif -#define CLIENT_PROXY_VER 0x40 +#define CLIENT_PROXY_VER (0x40 | (uint16)DEFAULT_VERSION) /** * @brief Indicates the inherited macro of the client proxy. diff --git a/samgr/source/message.c b/samgr/source/message.c index 5fd850074fcf1d75153f8753763b19892fa51e95..3c31c27741a3a995d307f2023e729d99bd71574b 100755 --- a/samgr/source/message.c +++ b/samgr/source/message.c @@ -27,7 +27,7 @@ #define DONT_WAIT 0 #define WAIT_FOREVER (-1) -static int32 SharedSend(MQueueId queueId, Exchange *exchange); +static int32 SharedSend(MQueueId queueId, Exchange *exchange, int initRef); static BOOL FreeReference(Exchange *exchange); int32 SAMGR_SendRequest(const Identity *identity, const Request *request, Handler handler) @@ -54,7 +54,7 @@ int32 SAMGR_SendResponse(const Request *request, const Response *response) } Exchange *exchange = GET_OBJECT(request, Exchange, request); - if (exchange->type == MSG_NON) { + if (exchange->type != MSG_CON) { return EC_INVALID; } @@ -76,7 +76,7 @@ int32 SAMGR_SendResponse(const Request *request, const Response *response) } // Send back to the origin to process the task. - int32 ret = SharedSend(exchange->id.queueId, exchange); + int32 ret = SharedSend(exchange->id.queueId, exchange, 1); if (ret != EC_SUCCESS) { exchange->handler(&exchange->request, &exchange->response); (void)FreeReference(exchange); @@ -123,7 +123,7 @@ uint32 *SAMGR_SendSharedRequest(const Identity *identity, const Request *request Exchange exchange = {*identity, *request, {NULL, 0}, MSG_NON, handler, token}; exchange.type = (handler == NULL) ? MSG_NON : MSG_CON; exchange.id.queueId = NULL; - int32 err = SharedSend(identity->queueId, &exchange); + int32 err = SharedSend(identity->queueId, &exchange, 0); if (err != EC_SUCCESS) { HILOG_ERROR(HILOG_MODULE_SAMGR, "SharedSend [%p] failed(%d)!", identity->queueId, err); (void)FreeReference(&exchange); @@ -152,7 +152,7 @@ int32 SAMGR_SendSharedDirectRequest(const Identity *id, const Request *req, cons exchange.type = MSG_DIRECT; exchange.id = *id; exchange.id.queueId = NULL; - int32 err = SharedSend(id->queueId, &exchange); + int32 err = SharedSend(id->queueId, &exchange, 0); if (err != EC_SUCCESS) { HILOG_ERROR(HILOG_MODULE_SAMGR, "SharedSend [%p] failed(%d)!", id->queueId, err); (void)FreeReference(&exchange); @@ -177,7 +177,7 @@ int32 SAMGR_SendResponseByIdentity(const Identity *id, const Request *request, c return SAMGR_SendResponse(request, response); } -static int32 SharedSend(MQueueId queueId, Exchange *exchange) +static int32 SharedSend(MQueueId queueId, Exchange *exchange, int initRef) { /* if the msg data and response is NULL, we just direct copy, no need shared the message. */ if ((exchange->request.data == NULL || exchange->request.len <= 0) && @@ -188,12 +188,12 @@ static int32 SharedSend(MQueueId queueId, Exchange *exchange) /* 1.add reference */ MUTEX_GlobalLock(); if (exchange->sharedRef == NULL) { - exchange->sharedRef = (uint32 *)SAMGR_Malloc(sizeof(uint32)); + exchange->sharedRef = (uint32*)SAMGR_Malloc(sizeof(uint32)); if (exchange->sharedRef == NULL) { MUTEX_GlobalUnlock(); return EC_NOMEMORY; } - *(exchange->sharedRef) = 0; + *(exchange->sharedRef) = initRef; } (*(exchange->sharedRef))++; MUTEX_GlobalUnlock(); diff --git a/samgr_endpoint/source/sa_store.c b/samgr_endpoint/source/sa_store.c index c3731e0ceabb5878806dc133bf0b29a9b3d99b57..b9dd4230791f7483b2fd2c4c92e492642f790df5 100755 --- a/samgr_endpoint/source/sa_store.c +++ b/samgr_endpoint/source/sa_store.c @@ -162,6 +162,29 @@ int SASTORA_FindHandleByPid(SAStore *saStore, pid_t callingPid, PidHandle *handl return INVALID_INDEX; } +int SASTORA_FindHandleByUidPid(SAStore *saStore, uid_t callingUid, pid_t callingPid, PidHandle *handle) +{ + if (saStore == NULL || saStore->maps == NULL || handle == NULL) { + return INVALID_INDEX; + } + int16 high = saStore->mapTop - 1; + int16 low = 0; + while (low <= high) { + // binary search need div 2 + int16 mid = (high + low) / 2; + if (saStore->maps[mid].pid == callingPid && saStore->maps[mid].uid == callingUid) { + *handle = saStore->maps[mid]; + return mid; + } + if (saStore->maps[mid].pid < callingPid) { + low = mid + 1; + continue; + } + high = mid - 1; + } + return INVALID_INDEX; +} + PidHandle SASTORA_FindPidHandleByIpcHandle(const SAStore *saStore, uint32 handle) { PidHandle pidHandle = {INVALID_INDEX, INVALID_INDEX, INVALID_INDEX, INVALID_INDEX}; diff --git a/samgr_endpoint/source/sa_store.h b/samgr_endpoint/source/sa_store.h index 762badfebe11de4227f6f2f28d2483eeb5bf7f8d..d2492817f4c2d5ac486a9541f40e1306c10f46e6 100755 --- a/samgr_endpoint/source/sa_store.h +++ b/samgr_endpoint/source/sa_store.h @@ -75,6 +75,7 @@ static inline void SASTORA_Init(SAStore *saStore) int SASTORA_Save(SAStore *saStore, const char *service, const char *feature, const SvcIdentity *identity); int SASTORA_SaveHandleByPid(SAStore *saStore, PidHandle handle); int SASTORA_FindHandleByPid(SAStore *saStore, pid_t callingPid, PidHandle *handle); +int SASTORA_FindHandleByUidPid(SAStore *saStore, uid_t callingUid, pid_t callingPid, PidHandle *handle); SvcIdentity SASTORA_Find(SAStore *saStore, const char *service, const char *feature); int SASTORA_ClearByPid(SAStore *saStore, pid_t pid); PidHandle SASTORA_FindPidHandleByIpcHandle(const SAStore *saStore, uint32 handle); diff --git a/samgr_server/source/samgr_server.c b/samgr_server/source/samgr_server.c index b564136dc5d01871fa0e39d2f44984c374fe3a9f..107dd0b2c2a9647c2b5e1e524f51bc494c12fb83 100755 --- a/samgr_server/source/samgr_server.c +++ b/samgr_server/source/samgr_server.c @@ -194,10 +194,11 @@ static int32 ProcPutFeature(SamgrServer *server, const void *origin, IpcIo *req, return EC_INVALID; } pid_t pid = GetCallingPid(origin); + uid_t uid = GetCallingUid(origin); char *feature = IpcIoPopBool(req) ? NULL : (char *)IpcIoPopString(req, &len); MUTEX_Lock(server->mtx); PidHandle handle; - int index = SASTORA_FindHandleByPid(&server->store, pid, &handle); + int index = SASTORA_FindHandleByUidPid(&server->store, uid, pid, &handle); if (index == INVALID_INDEX) { MUTEX_Unlock(server->mtx); HILOG_ERROR(HILOG_MODULE_SAMGR, "Endpoint[%d] is not register", pid);