diff --git a/adapter/appspawn_ace.cpp b/adapter/appspawn_ace.cpp index 09b5c90ce3056a04ff738db705f5ade1c8fd9bc3..15f465aeb1303e82b3a1285db8ee01c8d41f0ef3 100644 --- a/adapter/appspawn_ace.cpp +++ b/adapter/appspawn_ace.cpp @@ -24,12 +24,12 @@ void LoadExtendLib(AppSpawnContent *content) #else const char *acelibdir("/system/lib/libace.z.so"); #endif - void *AceAbilityLib = NULL; + void *AceAbilityLib = nullptr; APPSPAWN_LOGI("MainThread::LoadAbilityLibrary. Start calling dlopen acelibdir."); #ifndef APPSPAWN_TEST AceAbilityLib = dlopen(acelibdir, RTLD_NOW | RTLD_GLOBAL); #endif - if (AceAbilityLib == NULL) { + if (AceAbilityLib == nullptr) { APPSPAWN_LOGE("Fail to dlopen %s, [%s]", acelibdir, dlerror()); } else { APPSPAWN_LOGI("Success to dlopen %s", acelibdir); @@ -43,4 +43,4 @@ void RunChildProcessor(AppSpawnContent *content, AppSpawnClient *client) #ifndef APPSPAWN_TEST OHOS::AppExecFwk::MainThread::Start(); #endif -} \ No newline at end of file +} diff --git a/adapter/appspawn_log.cpp b/adapter/appspawn_log.cpp index 8fcb72f6deb70bc1c4900671f33ba644f6f8507b..58eb479447c8b976107ca6de6ee8fbfc0357cf79 100644 --- a/adapter/appspawn_log.cpp +++ b/adapter/appspawn_log.cpp @@ -24,11 +24,13 @@ #include "hilog/log.h" #include "securec.h" - -static AppspawnLogLevel g_logLevel = AppspawnLogLevel::INFO; -static constexpr int MAX_LOG_SIZE = 1024; -static constexpr int BASE_YEAR = 1900; -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, APPSPAWN_LABEL}; +namespace { + AppspawnLogLevel g_logLevel = AppspawnLogLevel::INFO; + constexpr int MAX_LOG_SIZE = 1024; + constexpr int BASE_YEAR = 1900; + constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, APPSPAWN_LABEL}; + const char *APPSPAWN_LOG_PATH = "/data/init_agent/appspawn.log"; +} void AppspawnLogPrint(AppspawnLogLevel logLevel, const char *file, int line, const char *fmt, ...) { @@ -70,7 +72,7 @@ void AppspawnLogPrint(AppspawnLogLevel logLevel, const char *file, int line, con return; } struct tm *t = localtime(&second); - FILE *outfile = fopen("/data/init_agent/appspawn.log", "a+"); + FILE *outfile = fopen(APPSPAWN_LOG_PATH, "a+"); if (t == nullptr || outfile == nullptr) { return; } diff --git a/adapter/appspawn_nweb.cpp b/adapter/appspawn_nweb.cpp index 926ac939bbc856efad8b17a706d8122724381b9d..c76354eed88958382b2937a067fca9d49336579e 100644 --- a/adapter/appspawn_nweb.cpp +++ b/adapter/appspawn_nweb.cpp @@ -28,14 +28,15 @@ struct RenderProcessNode { }; namespace { -constexpr int32_t RENDER_PROCESS_MAX_NUM = 16; -std::map g_renderProcessMap; -void *g_nwebHandle = nullptr; + constexpr int32_t RENDER_PROCESS_MAX_NUM = 16; + std::map g_renderProcessMap; + void *g_nwebHandle = nullptr; } void LoadExtendLib(AppSpawnContent *content) { const std::string LOAD_LIB_DIR = "/data/app/el1/bundle/public/com.ohos.nweb/libs/arm"; + #ifdef __MUSL__ Dl_namespace dlns; dlns_init(&dlns, "nweb_ns"); @@ -50,6 +51,7 @@ void LoadExtendLib(AppSpawnContent *content) } else { APPSPAWN_LOGI("Success to dlopen libweb_engine.so"); } + #ifdef __MUSL__ g_nwebHandle = dlopen_ns(&dlns, "libnweb_render.so", RTLD_NOW | RTLD_GLOBAL); #else @@ -67,17 +69,20 @@ void RunChildProcessor(AppSpawnContent *content, AppSpawnClient *client) { AppSpawnClientExt *appProperty = (AppSpawnClientExt *)client; using FuncType = void (*)(const char *cmd); + FuncType funcNWebRenderMain = reinterpret_cast(dlsym(g_nwebHandle, "NWebRenderMain")); if (funcNWebRenderMain == nullptr) { APPSPAWN_LOGI("webviewspawn dlsym ERROR=%s", dlerror()); return; } + funcNWebRenderMain(appProperty->property.renderCmd); } static void DumpRenderProcessExitedMap() { APPSPAWN_LOGI("dump render process exited array:"); + for (auto& it : g_renderProcessMap) { APPSPAWN_LOGV("[pid, time, exitedStatus] = [%d, %ld, %d]", it.first, it.second.recordTime_, it.second.exitStatus_); @@ -98,6 +103,7 @@ void RecordRenderProcessExitedStatus(pid_t pid, int status) [](const std::pair& left, const std::pair& right) { return left.second.recordTime_ < right.second.recordTime_; }); + g_renderProcessMap.erase(oldestData); RenderProcessNode node(time(nullptr), status); g_renderProcessMap.insert({pid, node}); @@ -116,7 +122,8 @@ int GetRenderProcessTerminationStatus(int32_t pid, int *status) g_renderProcessMap.erase(it); return 0; } + APPSPAWN_LOGE("not find pid[%d] in render process exited map", pid); DumpRenderProcessExitedMap(); return -1; -} \ No newline at end of file +} diff --git a/adapter/appspawn_sandbox.cpp b/adapter/appspawn_sandbox.cpp index d89780f6bca1015a9891b4e163d196a860df434c..70e6e9c6f31ab64c35def43fedb8986c7329ab77 100644 --- a/adapter/appspawn_sandbox.cpp +++ b/adapter/appspawn_sandbox.cpp @@ -53,6 +53,7 @@ void LoadAppSandboxConfig(void) { // load sandbox config nlohmann::json appSandboxConfig; + bool rc = JsonUtils::GetJsonObjFromJson(appSandboxConfig, APP_JSON_CONFIG); if (!rc) { HiLog::Error(LABEL, "AppSpawnServer::Failed to load app private sandbox config"); @@ -69,6 +70,7 @@ void LoadAppSandboxConfig(void) int32_t SetAppSandboxProperty(struct AppSpawnContent_ *content, AppSpawnClient *client) { APPSPAWN_CHECK(client != NULL, return -1, "Invalid appspwn client"); + AppSpawnClientExt *appProperty = (AppSpawnClientExt *)client; return SandboxUtils::SetAppSandboxProperty(&appProperty->property); } diff --git a/adapter/sysevent/event_reporter.cpp b/adapter/sysevent/event_reporter.cpp index c00be6aa2c04a99a8dd02d40b91f69b2a0195d8b..54b20df702091863fa37a0f729e1c4473426247d 100644 --- a/adapter/sysevent/event_reporter.cpp +++ b/adapter/sysevent/event_reporter.cpp @@ -26,6 +26,7 @@ constexpr char KEY_PID[] = "PID"; constexpr char KEY_UID[] = "UID"; constexpr char KEY_STATUS[] = "STATUS"; constexpr int32_t MAX_NAME_LENGTH = 1024; + void ReportProcessExitInfo(const char* processName, int pid, int uid, int status) { std::string pname = "Unknown"; diff --git a/common/appspawn_server.c b/common/appspawn_server.c index 3528b095db81b5279f3918edde872efc585fb035..04f3b0bb449ad8618e70937bd031c58979591edd 100644 --- a/common/appspawn_server.c +++ b/common/appspawn_server.c @@ -28,12 +28,14 @@ static int NotifyResToParent(struct AppSpawnContent_ *content, AppSpawnClient *c if (content->notifyResToParent != NULL) { content->notifyResToParent(content, client, result); } + return 0; } static void ProcessExit(void) { APPSPAWN_LOGI("App exit %d.", getpid()); + #ifdef OHOS_LITE _exit(0x7f); // 0x7f user exit #else @@ -47,16 +49,19 @@ int DoStartApp(struct AppSpawnContent_ *content, AppSpawnClient *client, char *l { APPSPAWN_LOGI("DoStartApp id %d longProcNameLen %u", client->id, longProcNameLen); int32_t ret = 0; + if (content->setAppSandbox) { ret = content->setAppSandbox(content, client); APPSPAWN_CHECK(ret == 0, NotifyResToParent(content, client, ret); return ret, "Failed to set app sandbox"); } + if (content->setKeepCapabilities) { ret = content->setKeepCapabilities(content, client); APPSPAWN_CHECK(ret == 0, NotifyResToParent(content, client, ret); return ret, "Failed to set KeepCapabilities"); } + if (content->setProcessName) { ret = content->setProcessName(content, client, longProcName, longProcNameLen); APPSPAWN_CHECK(ret == 0, NotifyResToParent(content, client, ret); @@ -68,6 +73,7 @@ int DoStartApp(struct AppSpawnContent_ *content, AppSpawnClient *client, char *l APPSPAWN_CHECK(ret == 0, NotifyResToParent(content, client, ret); return ret, "Failed to setUidGid"); } + #ifndef APPSPAWN_TEST if (content->setFileDescriptors) { ret = content->setFileDescriptors(content, client); @@ -75,11 +81,13 @@ int DoStartApp(struct AppSpawnContent_ *content, AppSpawnClient *client, char *l return ret, "Failed to setFileDescriptors"); } #endif + if (content->setCapabilities) { ret = content->setCapabilities(content, client); APPSPAWN_CHECK(ret == 0, NotifyResToParent(content, client, ret); return ret, "Failed to setCapabilities"); } + // notify success to father process and start app process NotifyResToParent(content, client, 0); return 0; @@ -104,9 +112,11 @@ int AppSpawnProcessMsg(struct AppSpawnContent_ *content, AppSpawnClient *client, if (content->clearEnvironment != NULL) { content->clearEnvironment(content, client); } + if (content->setAppAccessToken != NULL) { content->setAppAccessToken(content, client); } + int ret = -1; if (client->flags & APP_COLD_START) { if (content->coldStartApp != NULL && content->coldStartApp(content, client) == 0) { @@ -118,6 +128,7 @@ int AppSpawnProcessMsg(struct AppSpawnContent_ *content, AppSpawnClient *client, } else { ret = DoStartApp(content, client, content->longProcName, content->longProcNameLen); } + #ifdef OHOS_DEBUG struct timespec tmEnd = {0}; GetCurTime(&tmEnd); @@ -125,6 +136,7 @@ int AppSpawnProcessMsg(struct AppSpawnContent_ *content, AppSpawnClient *client, long timeUsed = (tmEnd.tv_sec - tmStart.tv_sec) * 1000000000L + (tmEnd.tv_nsec - tmStart.tv_nsec); APPSPAWN_LOGI("App timeused %d %ld ns.", getpid(), timeUsed); #endif // OHOS_DEBUG + if (ret == 0 && content->runChildProcessor != NULL) { content->runChildProcessor(content, client); } @@ -140,6 +152,7 @@ void GetCurTime(struct timespec *tmCur) if (tmCur == NULL) { return; } + if (clock_gettime(CLOCK_REALTIME, tmCur) != 0) { APPSPAWN_LOGE("[appspawn] invoke, get time failed! err %d", errno); } diff --git a/util/src/sandbox_utils.cpp b/util/src/sandbox_utils.cpp index 3b80bb01415e8d476a39d8249f784460a3fe4de4..4dc57bcdb57b6a4128e1599997f8cb295f15c115 100644 --- a/util/src/sandbox_utils.cpp +++ b/util/src/sandbox_utils.cpp @@ -99,7 +99,7 @@ nlohmann::json SandboxUtils::GetProductJsonConfig() return SandboxUtils::productSandboxConfig_; } -static void MakeDirRecursive(const std::string path, mode_t mode) +static void MakeDirRecursive(const std::string &path, mode_t mode) { size_t size = path.size(); if (size == 0) {