From d3b07584997c11014d65457ecd5ae220418d706b Mon Sep 17 00:00:00 2001 From: yh Date: Mon, 21 Oct 2024 21:22:48 +0800 Subject: [PATCH] modify process name Signed-off-by: yh Change-Id: I7a7555056c711334efd9a8aad97fb889b55da5a7 --- standard/appspawn_service.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 79d783ae..1a529080 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -52,6 +52,7 @@ #define PATH_SIZE 256 #define FD_PATH_SIZE 128 #define MAX_MEM_SIZE (4 * 1024) +#define PREFORK_PROCESS "apppool" #ifndef PIDFD_NONBLOCK #define PIDFD_NONBLOCK O_NONBLOCK #endif @@ -686,6 +687,28 @@ static void ClearMMAP(int clientId) } } +static int SetPreforkProcessName(AppSpawnContent *content) +{ + int ret = prctl(PR_SET_NAME, PREFORK_PROCESS); + if (ret == -1) { + return errno; + } + + ret = memset_s(content->longProcName, + (size_t)content->longProcNameLen, 0, (size_t)content->longProcNameLen); + if (ret != EOK) { + return EINVAL; + } + + ret = strncpy_s(content->longProcName, content->longProcNameLen, + PREFORK_PROCESS, strlen(PREFORK_PROCESS)); + if (ret != EOK) { + return EINVAL; + } + + return 0; +} + static void ProcessPreFork(AppSpawnContent *content, AppSpawningCtx *property) { APPSPAWN_CHECK(pipe(content->preforkFd) == 0, return, "prefork with prefork pipe failed %{public}d", errno); @@ -702,7 +725,7 @@ static void ProcessPreFork(AppSpawnContent *content, AppSpawningCtx *property) if (content->reservedPid == 0) { (void)close(property->forkCtx.fd[0]); (void)close(property->forkCtx.fd[1]); - int isRet = prctl(PR_SET_NAME, "apppool"); + int isRet = SetPreforkProcessName(content); APPSPAWN_LOGI("prefork process start wait read msg with set processname %{public}d", isRet); AppSpawnClient client = {0, 0}; int infoSize = read(content->parentToChildFd[0], &client, sizeof(AppSpawnClient));