mirror of
https://gitee.com/openharmony/startup_appspawn
synced 2024-11-23 15:10:44 +00:00
This reverts commit68e1f1faed
, reversing changes made to7612f11ea9
. Signed-off-by: Caoruihong <crh.cao@huawei.com>
This commit is contained in:
parent
68e1f1faed
commit
3e344c5d65
12
BUILD.gn
12
BUILD.gn
@ -77,6 +77,18 @@ ohos_prebuilt_etc("asan.options") {
|
||||
part_name = "${part_name}"
|
||||
}
|
||||
|
||||
ohos_shared_library("appspawn_helper") {
|
||||
sources = [ "${appspawn_path}/common/appspawn_server.c" ]
|
||||
configs = [ ":appspawn_config" ]
|
||||
defines = [ "APPSPAWN_HELPER" ]
|
||||
cflags = [ "-fvisibility=hidden" ]
|
||||
external_deps = [ "hilog_native:libhilog" ]
|
||||
|
||||
install_enable = true
|
||||
subsystem_name = "${subsystem_name}"
|
||||
part_name = "${part_name}"
|
||||
}
|
||||
|
||||
ohos_static_library("appspawn_server") {
|
||||
sources = [
|
||||
"${appspawn_path}/adapter/appspawn_adapter.cpp",
|
||||
|
@ -43,6 +43,7 @@
|
||||
"sub_component": [
|
||||
"//base/startup/appspawn:appspawn",
|
||||
"//base/startup/appspawn:appspawn.rc",
|
||||
"//base/startup/appspawn:appspawn_helper",
|
||||
"//base/startup/appspawn:appspawn_server",
|
||||
"//base/startup/appspawn:nweb",
|
||||
"//base/startup/appspawn/etc:etc_files",
|
||||
|
@ -48,7 +48,7 @@ static void NotifyResToParent(struct AppSpawnContent_ *content, AppSpawnClient *
|
||||
}
|
||||
}
|
||||
|
||||
static void ProcessSafeExit(int code)
|
||||
static void ProcessExit(int code)
|
||||
{
|
||||
APPSPAWN_LOGI("App exit: %{public}d", code);
|
||||
#ifdef OHOS_LITE
|
||||
@ -60,6 +60,24 @@ static void ProcessSafeExit(int code)
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool g_IsAppRunning = false;
|
||||
|
||||
#ifdef APPSPAWN_HELPER
|
||||
__attribute__((visibility("default")))
|
||||
_Noreturn
|
||||
void exit(int code)
|
||||
{
|
||||
if (g_IsAppRunning) {
|
||||
APPSPAWN_LOGF("Unexpected exit call: %{public}d", code);
|
||||
abort();
|
||||
}
|
||||
// hook `exit` to `ProcessExit` to ensure app exit in a clean way
|
||||
ProcessExit(code);
|
||||
// should not come here
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
|
||||
int DoStartApp(struct AppSpawnContent_ *content, AppSpawnClient *client, char *longProcName, uint32_t longProcNameLen)
|
||||
{
|
||||
int32_t ret = 0;
|
||||
@ -110,7 +128,7 @@ int DoStartApp(struct AppSpawnContent_ *content, AppSpawnClient *client, char *l
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int AppSpawnChildInternal(void *arg)
|
||||
static int AppSpawnChildRun(void *arg)
|
||||
{
|
||||
APPSPAWN_CHECK(arg != NULL, return -1, "Invalid arg for appspawn child");
|
||||
AppSandboxArg *sandbox = (AppSandboxArg *)arg;
|
||||
@ -154,8 +172,10 @@ static int AppSpawnChildInternal(void *arg)
|
||||
|
||||
static int AppSpawnChild(void *arg)
|
||||
{
|
||||
ProcessSafeExit(AppSpawnChildInternal(arg));
|
||||
return -1;
|
||||
g_IsAppRunning = true;
|
||||
int ret = AppSpawnChildRun(arg);
|
||||
g_IsAppRunning = false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef APPSPAWN_TEST
|
||||
@ -163,8 +183,7 @@ pid_t AppSpawnFork(int (*childFunc)(void *arg), void *args)
|
||||
{
|
||||
pid_t pid = fork();
|
||||
if (pid == 0) {
|
||||
ProcessSafeExit(childFunc(args));
|
||||
return -1;
|
||||
ProcessExit(childFunc(args));
|
||||
}
|
||||
return pid;
|
||||
}
|
||||
|
@ -105,6 +105,8 @@ pid_t AppSpawnFork(int (*childFunc)(void *arg), void *args);
|
||||
APPSPAWN_LOG(LOG_DEBUG, APPSPAWN_DOMAIN, APPSPAWN_LABEL, fmt, ##__VA_ARGS__)
|
||||
#define APPSPAWN_LOGW(fmt, ...) \
|
||||
APPSPAWN_LOG(LOG_WARN, APPSPAWN_DOMAIN, APPSPAWN_LABEL, fmt, ##__VA_ARGS__)
|
||||
#define APPSPAWN_LOGF(fmt, ...) \
|
||||
APPSPAWN_LOG(LOG_FATAL, APPSPAWN_DOMAIN, APPSPAWN_LABEL, fmt, ##__VA_ARGS__)
|
||||
|
||||
#else
|
||||
|
||||
|
@ -597,9 +597,6 @@ static void AppSpawnRun(AppSpawnContent *content, int argc, char *const argv[])
|
||||
LE_CloseLoop(LE_GetDefaultLoop());
|
||||
free(content);
|
||||
g_appSpawnContent = NULL;
|
||||
#ifndef APPSPAWN_TEST
|
||||
quick_exit(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
static int CreateHashForApp(AppSpawnContentExt *appSpawnContent)
|
||||
|
@ -21,12 +21,35 @@
|
||||
#include "init_param.h"
|
||||
#include "syspara/parameter.h"
|
||||
|
||||
#define APPSPAWN_PRELOAD "libappspawn_helper.z.so"
|
||||
|
||||
static void CheckPreload(char *const argv[])
|
||||
{
|
||||
char *preload = getenv("LD_PRELOAD");
|
||||
if (preload && strstr(preload, APPSPAWN_PRELOAD)) {
|
||||
return;
|
||||
}
|
||||
char buf[128] = APPSPAWN_PRELOAD; // 128 is enough in most cases
|
||||
if (preload && preload[0]) {
|
||||
int len = sprintf_s(buf, sizeof(buf), "%s:" APPSPAWN_PRELOAD, preload);
|
||||
APPSPAWN_CHECK(len > 0, return, "preload too long: %{public}s", preload);
|
||||
}
|
||||
int ret = setenv("LD_PRELOAD", buf, true);
|
||||
APPSPAWN_CHECK(ret == 0, return, "setenv fail: %{public}s", buf);
|
||||
ssize_t nread = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
|
||||
APPSPAWN_CHECK(nread != -1, return, "readlink fail: /proc/self/exe: %{public}d", errno);
|
||||
buf[nread] = 0;
|
||||
ret = execv(buf, argv);
|
||||
APPSPAWN_LOGE("execv fail: %{public}s: %{public}d: %{public}d", buf, errno, ret);
|
||||
}
|
||||
|
||||
int main(int argc, char *const argv[])
|
||||
{
|
||||
if (argc <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
CheckPreload(argv);
|
||||
(void)signal(SIGPIPE, SIG_IGN);
|
||||
uint32_t argvSize = 0;
|
||||
int mode = 0;
|
||||
@ -65,5 +88,5 @@ int main(int argc, char *const argv[])
|
||||
}
|
||||
content->runAppSpawn(content, argc, argv);
|
||||
|
||||
_Exit(0);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user