mirror of
https://gitee.com/openharmony/startup_appspawn
synced 2024-11-23 15:10:44 +00:00
!622 fix:clone appspawn 退出时crash问题
Merge pull request !622 from cheng_jinsong/cloneappspawn
This commit is contained in:
commit
4902617612
@ -120,7 +120,7 @@ void RunChildProcessor(AppSpawnContent *content, AppSpawnClient *client)
|
||||
APPSPAWN_CHECK(client != NULL && content != NULL, return, "Invalid client");
|
||||
AppSpawnClientExt *appProperty = reinterpret_cast<AppSpawnClientExt *>(client);
|
||||
if (appProperty->property.code == SPAWN_NATIVE_PROCESS) {
|
||||
APPSPAWN_LOGI("renderCmd %s", appProperty->property.renderCmd);
|
||||
APPSPAWN_LOGI("renderCmd %{public}s", appProperty->property.renderCmd);
|
||||
(void)system(appProperty->property.renderCmd);
|
||||
return;
|
||||
}
|
||||
|
@ -21,4 +21,5 @@ module_output_path = "${part_name}/appspawn_l2"
|
||||
declare_args() {
|
||||
appspawn_support_nweb = true
|
||||
appspawn_report_event = true
|
||||
appspawn_test_cmd = false
|
||||
}
|
||||
|
@ -198,6 +198,13 @@ static int AppSpawnChild(void *arg)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int CloneAppSpawn(void *arg)
|
||||
{
|
||||
int ret = AppSpawnChild(arg);
|
||||
ProcessExit(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef APPSPAWN_TEST
|
||||
pid_t AppSpawnFork(int (*childFunc)(void *arg), void *args)
|
||||
{
|
||||
@ -221,7 +228,7 @@ int AppSpawnProcessMsg(AppSandboxArg *sandbox, pid_t *childPid)
|
||||
APPSPAWN_CHECK(client->cloneFlags & CLONE_NEWNS, return -1, "clone flags error");
|
||||
char *childStack = (char *)malloc(SANDBOX_STACK_SIZE);
|
||||
APPSPAWN_CHECK(childStack != NULL, return -1, "malloc failed");
|
||||
pid_t pid = clone(AppSpawnChild,
|
||||
pid_t pid = clone(CloneAppSpawn,
|
||||
childStack + SANDBOX_STACK_SIZE, client->cloneFlags | SIGCHLD, (void *)sandbox);
|
||||
if (pid > 0) {
|
||||
free(childStack);
|
||||
|
@ -212,7 +212,7 @@ int SetXpmRegion(struct AppSpawnContent_ *content)
|
||||
APPSPAWN_CHECK_ONLY_LOG(ret != -1, "set xpm region failed: %s", strerror(errno));
|
||||
|
||||
close(fd);
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int SetUidGid(struct AppSpawnContent_ *content, AppSpawnClient *client)
|
||||
|
@ -14,6 +14,26 @@
|
||||
import("//base/startup/appspawn/appspawn.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
ohos_executable("AppSpawnTest") {
|
||||
sources = [ "${appspawn_path}/test/moduletest/appspawn_test_cmd.cpp" ]
|
||||
|
||||
include_dirs = [
|
||||
"//commonlibrary/c_utils/base/include",
|
||||
"//third_party/zlib/contrib/minizip",
|
||||
"//third_party/zlib",
|
||||
]
|
||||
|
||||
configs = [ "${appspawn_path}:appspawn_config" ]
|
||||
|
||||
deps = [ "${appspawn_path}/interfaces/innerkits:appspawn_socket_client" ]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"init:libbegetutil",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_moduletest("AppSpawnModuleTest") {
|
||||
module_out_path = "${module_output_path}"
|
||||
|
||||
@ -51,4 +71,7 @@ group("moduletest") {
|
||||
testonly = true
|
||||
|
||||
deps = [ ":AppSpawnModuleTest" ]
|
||||
if (appspawn_test_cmd) {
|
||||
deps += [ ":AppSpawnTest" ]
|
||||
}
|
||||
}
|
||||
|
98
test/moduletest/appspawn_test_cmd.cpp
Normal file
98
test/moduletest/appspawn_test_cmd.cpp
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "appspawn_test_client.h"
|
||||
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
OHOS::AppSpawn::AppSpawnTestClient g_testClient;
|
||||
|
||||
static int DoRun(const char *server, const AppParameter *request)
|
||||
{
|
||||
int ret = g_testClient.ClientCreateSocket(server);
|
||||
if (ret != 0) {
|
||||
printf("Failed to connect server \n");
|
||||
return 1;
|
||||
}
|
||||
ret = g_testClient.ClientSendMsg(reinterpret_cast<const uint8_t *>(request), sizeof(AppParameter));
|
||||
if (ret != 0) {
|
||||
printf("Failed to send msg to server \n");
|
||||
g_testClient.ClientClose();
|
||||
return 1;
|
||||
}
|
||||
pid_t pid = 0;
|
||||
ret = g_testClient.ClientRecvMsg(pid);
|
||||
if (ret != 0) {
|
||||
printf("Failed spawn new app result %d \n", ret);
|
||||
g_testClient.ClientClose();
|
||||
quick_exit(0);
|
||||
return 1;
|
||||
}
|
||||
if (pid > 0) {
|
||||
printf("Success spawn new app pid %d \n", pid);
|
||||
}
|
||||
int index = 0;
|
||||
while (index < 5) { // wait 5s
|
||||
sleep(1);
|
||||
index++;
|
||||
}
|
||||
if (pid > 0) {
|
||||
APPSPAWN_LOGI("Success spawn new app pid %{public}d \n", pid);
|
||||
kill(pid, SIGKILL);
|
||||
}
|
||||
// close client
|
||||
g_testClient.ClientClose();
|
||||
quick_exit(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *const argv[])
|
||||
{
|
||||
int coldStart = 0;
|
||||
int withSandbox = 0;
|
||||
const char *cmd = "ls -l /data > /data/test.log";
|
||||
const char *bundleName = "ohos.samples.test";
|
||||
const char *server = "/dev/unix/socket/AppSpawn";
|
||||
for (int32_t i = 0; i < argc; i++) {
|
||||
if (strcmp(argv[i], "-c") == 0) {
|
||||
coldStart = 1;
|
||||
} else if (strcmp(argv[i], "-s") == 0) {
|
||||
withSandbox = 1;
|
||||
} else if (strcmp(argv[i], "--nwebspawn") == 0) {
|
||||
server = "/dev/unix/socket/NWebSpawn";
|
||||
} else if (strcmp(argv[i], "-b") == 0 && ((i + 1) < argc)) {
|
||||
i++;
|
||||
bundleName = argv[i];
|
||||
} else if (strcmp(argv[i], "-C") == 0 && ((i + 1) < argc)) {
|
||||
i++;
|
||||
cmd= argv[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (coldStart) {
|
||||
SetParameter("startup.appspawn.cold.boot", "1");
|
||||
SetParameter("persist.appspawn.client.timeout", "10");
|
||||
}
|
||||
|
||||
AppParameter request = {};
|
||||
memset_s((void *)(&request), sizeof(request), 0, sizeof(request));
|
||||
g_testClient.ClientFillMsg(&request, bundleName, cmd);
|
||||
|
||||
request.flags = coldStart ? APP_COLD_BOOT : 0;
|
||||
request.flags |= !withSandbox ? APP_NO_SANDBOX : 0;
|
||||
request.code = SPAWN_NATIVE_PROCESS;
|
||||
return DoRun(server, &request);
|
||||
}
|
Loading…
Reference in New Issue
Block a user