!1415 add prefork policy

Merge pull request !1415 from 杨浩/weekly_20240826
This commit is contained in:
openharmony_ci 2024-08-27 10:52:14 +00:00 committed by Gitee
commit e7d8b6519f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 12 additions and 1 deletions

View File

@ -70,6 +70,7 @@ typedef struct AppSpawnContent {
char *propertyBuffer;
int isPrefork;
pid_t reservedPid;
int enablePerfork;
#endif
// system
void (*runAppSpawn)(struct AppSpawnContent *content, int argc, char *const argv[]);

View File

@ -687,7 +687,6 @@ static void ProcessPreFork(AppSpawnContent *content, AppSpawningCtx *property)
ProcessExit(0);
return;
}
property->client.id = client.id;
property->client.flags = client.flags;
property->isPrefork = true;
@ -750,6 +749,9 @@ static bool IsSupportPrefork(AppSpawnContent *content, AppSpawnClient *client)
if (client == NULL || content == NULL) {
return false;
}
if (!content->enablePerfork) {
return false;
}
if (!content->isPrefork) {
if (pipe(content->parentToChildFd) == 0) {
content->isPrefork = true;
@ -1134,6 +1136,13 @@ APPSPAWN_STATIC int AppSpawnClearEnv(AppSpawnMgr *content, AppSpawningCtx *prope
return 0;
}
static int IsEnablePerfork()
{
char buffer[32] = {0};
int ret = GetParameter("persist.sys.prefork.enable", "false", buffer, sizeof(buffer));
return (ret > 0 && strcmp(buffer, "true") == 0);
}
AppSpawnContent *AppSpawnCreateContent(const char *socketName, char *longProcName, uint32_t nameLen, int mode)
{
APPSPAWN_CHECK(socketName != NULL && longProcName != NULL, return NULL, "Invalid name");
@ -1154,6 +1163,7 @@ AppSpawnContent *AppSpawnCreateContent(const char *socketName, char *longProcNam
APPSPAWN_CHECK(ret == 0, AppSpawnDestroyContent(&appSpawnContent->content);
return NULL, "Failed to create server");
}
appSpawnContent->content.enablePerfork = IsEnablePerfork();
return &appSpawnContent->content;
}