diff --git a/adapter/appspawn_sandbox.cpp b/adapter/appspawn_sandbox.cpp index 70e6e9c6f31ab64c35def43fedb8986c7329ab77..c58d9cbba6fdae37c4901665995a2b4bbfabd7ee 100644 --- a/adapter/appspawn_sandbox.cpp +++ b/adapter/appspawn_sandbox.cpp @@ -15,15 +15,7 @@ #include "appspawn_adapter.h" -#include -#include -#include -#include #include -#include -#include -#include -#include #include #include @@ -37,9 +29,6 @@ using namespace OHOS::HiviewDFX; using namespace OHOS::AppSpawn; static constexpr HiLogLabel LABEL = {LOG_CORE, 0, "AppSpawn_SandboxUtil"}; -bool g_isPrivAppSandboxCreated = false; -bool g_isAppSandboxCreated = false; - namespace { #ifdef __aarch64__ const std::string APP_JSON_CONFIG("/system/etc/sandbox/appdata-sandbox64.json"); diff --git a/common/appspawn_server.c b/common/appspawn_server.c index 04f3b0bb449ad8618e70937bd031c58979591edd..e43375ac9bb337abb858bdce577b05d3d77c8dc9 100644 --- a/common/appspawn_server.c +++ b/common/appspawn_server.c @@ -23,13 +23,11 @@ #include #endif // OHOS_DEBUG -static int NotifyResToParent(struct AppSpawnContent_ *content, AppSpawnClient *client, int result) +static void NotifyResToParent(struct AppSpawnContent_ *content, AppSpawnClient *client, int result) { if (content->notifyResToParent != NULL) { content->notifyResToParent(content, client, result); } - - return 0; } static void ProcessExit(void) diff --git a/common/appspawn_server.h b/common/appspawn_server.h index c344470d65b25e60ca855701a046b557fd8f8237..571ea0f71dcf9c3a3e775743692b0fd25c2f9db8 100644 --- a/common/appspawn_server.h +++ b/common/appspawn_server.h @@ -62,7 +62,7 @@ typedef struct AppSpawnContent_ { int (*setUidGid)(struct AppSpawnContent_ *content, AppSpawnClient *client); int (*setCapabilities)(struct AppSpawnContent_ *content, AppSpawnClient *client); - int (*notifyResToParent)(struct AppSpawnContent_ *content, AppSpawnClient *client, int result); + void (*notifyResToParent)(struct AppSpawnContent_ *content, AppSpawnClient *client, int result); void (*runChildProcessor)(struct AppSpawnContent_ *content, AppSpawnClient *client); // for cold start diff --git a/lite/appspawn_message.c b/lite/appspawn_message.c index cad751cb396dff4c97a2cd0c9ff9ae9ded967312..9c350d92522834d7e46d49a533564132efad1e45 100644 --- a/lite/appspawn_message.c +++ b/lite/appspawn_message.c @@ -13,6 +13,7 @@ * limitations under the License. */ #include "appspawn_message.h" + #include #include #include @@ -145,6 +146,7 @@ static int GetCaps(const cJSON *curItem, MessageSt *msgSt) return EC_INVALID; } } + msgSt->capsCnt = capsCnt; return EC_SUCCESS; } diff --git a/lite/appspawn_service.c b/lite/appspawn_service.c index 33e9d4af71a6ee973c199fee19815a91a773debc..f58cdb04586f87c0461c3e554a6684764ea85b4f 100644 --- a/lite/appspawn_service.c +++ b/lite/appspawn_service.c @@ -13,13 +13,14 @@ * limitations under the License. */ +#include "appspawn_message.h" +#include "appspawn_server.h" + #ifdef OHOS_DEBUG #include #include #endif // OHOS_DEBUG -#include "appspawn_message.h" -#include "appspawn_server.h" #include "iproxy_server.h" #include "iunknown.h" #include "ipc_skeleton.h" @@ -45,7 +46,7 @@ typedef struct AppSpawnService { static const char *GetName(Service *service) { - (void)service; + UNUSED(service); APPSPAWN_LOGI("[appspawn] get service name %s.", APPSPAWN_SERVICE_NAME); return APPSPAWN_SERVICE_NAME; } @@ -67,15 +68,15 @@ static BOOL Initialize(Service *service, Identity identity) static BOOL MessageHandle(Service *service, Request *msg) { - (void)service; - (void)msg; + UNUSED(service); + UNUSED(msg); APPSPAWN_LOGE("[appspawn] message handle not support yet!"); return FALSE; } static TaskConfig GetTaskConfig(Service *service) { - (void)service; + UNUSED(service); TaskConfig config = {LEVEL_HIGH, PRI_BELOW_NORMAL, 0x800, 20, SHARED_TASK}; return config; } @@ -121,8 +122,8 @@ static int Invoke(IServerProxy *iProxy, int funcId, void *origin, IpcIo *req, Ip GetCurTime(&tmStart); #endif // OHOS_DEBUG - (void)iProxy; - (void)origin; + UNUSED(iProxy); + UNUSED(origin); if (reply == NULL || funcId != ID_CALL_CREATE_SERVICE || req == NULL) { APPSPAWN_LOGE("[appspawn] invoke, funcId %d invalid, reply %d.", funcId, INVALID_PID); diff --git a/standard/appspawn_process.c b/standard/appspawn_process.c index 38227397a587dd0b54ce3bbee3e95fcc9af1fe09..6a26c352fae4ce8df04e5faab0b4d84f7b042247 100644 --- a/standard/appspawn_process.c +++ b/standard/appspawn_process.c @@ -14,6 +14,7 @@ */ #include "appspawn_service.h" +#include "appspawn_adapter.h" #include #include @@ -28,10 +29,8 @@ #include #include -#include "appspawn_adapter.h" #include "securec.h" - #define DEVICE_NULL_STR "/dev/null" static int SetProcessName(struct AppSpawnContent_ *content, AppSpawnClient *client, @@ -272,7 +271,7 @@ static int ColdStartApp(struct AppSpawnContent_ *content, AppSpawnClient *client argv[PARAM_INDEX] = param; argv[0] = param + originLen; ret = strcpy_s(argv[0], APP_LEN_PROC_NAME, "/system/bin/appspawn"); - APPSPAWN_CHECK(ret >= 0, break, "Invalid strdup"); + APPSPAWN_CHECK(ret >= 0, break, "Invalid strcpy"); argv[START_INDEX] = strdup("cold-start"); APPSPAWN_CHECK(argv[START_INDEX] != NULL, break, "Invalid strdup"); argv[FD_INDEX] = strdup(buffer); @@ -319,6 +318,7 @@ int GetAppSpawnClientFromArg(int argc, char *const argv[], AppSpawnClientExt *cl APPSPAWN_LOGV("GetAppSpawnClientFromArg %s ", argv[PARAM_INDEX]); char *end = NULL; char *start = strtok_r(argv[PARAM_INDEX], ":", &end); + // clientid APPSPAWN_CHECK(start != NULL, return -1, "Failed to get client id"); client->client.id = atoi(start); @@ -328,6 +328,7 @@ int GetAppSpawnClientFromArg(int argc, char *const argv[], AppSpawnClientExt *cl start = strtok_r(NULL, ":", &end); APPSPAWN_CHECK(start != NULL, return -1, "Failed to get gid"); client->property.gid = atoi(start); + // gidCount start = strtok_r(NULL, ":", &end); APPSPAWN_CHECK(start != NULL, return -1, "Failed to get gidCount"); @@ -337,6 +338,7 @@ int GetAppSpawnClientFromArg(int argc, char *const argv[], AppSpawnClientExt *cl APPSPAWN_CHECK(start != NULL, return -1, "Failed to get gidTable"); client->property.gidTable[i] = atoi(start); } + // processname start = strtok_r(NULL, ":", &end); APPSPAWN_CHECK(start != NULL, return -1, "Failed to get processName"); @@ -350,6 +352,7 @@ int GetAppSpawnClientFromArg(int argc, char *const argv[], AppSpawnClientExt *cl APPSPAWN_CHECK(start != NULL, return -1, "Failed to get soPath"); ret = strcpy_s(client->property.soPath, sizeof(client->property.soPath), start); APPSPAWN_CHECK(ret == 0, return -1, "Failed to strcpy soPath"); + // accesstoken start = strtok_r(NULL, ":", &end); APPSPAWN_CHECK(start != NULL, return -1, "Failed to get accessTokenId"); @@ -362,6 +365,7 @@ int GetAppSpawnClientFromArg(int argc, char *const argv[], AppSpawnClientExt *cl APPSPAWN_CHECK(start != NULL, return -1, "Failed to get renderCmd"); ret = strcpy_s(client->property.renderCmd, sizeof(client->property.renderCmd), start); APPSPAWN_CHECK(ret == 0, return -1, "Failed to strcpy renderCmd"); + return 0; } diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 570d3d9a82aef926a3a5375acbe22fd9ccb509be..0076ca879e20e49dd54618758b35161ed5c363b9 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -15,6 +15,7 @@ #include "appspawn_service.h" #include "appspawn_adapter.h" +#include "appspawn_server.h" #include #include @@ -27,7 +28,6 @@ #include #include -#include "appspawn_server.h" #include "init_hashmap.h" #include "init_socket.h" #include "parameter.h" @@ -158,6 +158,7 @@ static void PrintProcessExitInfo(pid_t pid, uid_t uid, int status) APPSPAWN_CHECK(node != NULL, return, "Handle SIGCHLD from pid:%d status:%d", pid, status); AppInfo *appInfo = HASHMAP_ENTRY(node, AppInfo, node); APPSPAWN_CHECK(appInfo != NULL, return, "Handle SIGCHLD from pid:%d status:%d", pid, status); + if (WIFSIGNALED(status)) { APPSPAWN_LOGW("%s with pid %d exit with signal:%d", appInfo->name, pid, WTERMSIG(status)); } @@ -209,6 +210,7 @@ static void HandleSpecial(AppSpawnClientExt *appProperty) "com.ohos.medialibrary.MediaScannerAbilityA", "com.ohos.medialibrary.medialibrarydata" }; + for (size_t i = 0; i < sizeof(specialBundleNames) / sizeof(specialBundleNames[0]); i++) { if (strcmp(appProperty->property.bundleName, specialBundleNames[i]) == 0) { if (appProperty->property.gidCount < APP_MAX_GIDS) { @@ -231,6 +233,7 @@ static int WaitChild(int fd, int pid, const AppSpawnClientExt *appProperty) FD_SET(fd, &rd); tv.tv_sec = TV_SEC; tv.tv_usec = 0; + int ret = select(fd + 1, &rd, NULL, NULL, &tv); if (ret == 0) { // timeout APPSPAWN_LOGI("Time out for child %s %d fd %d", appProperty->property.processName, pid, fd); @@ -241,6 +244,7 @@ static int WaitChild(int fd, int pid, const AppSpawnClientExt *appProperty) } else { (void)read(fd, &result, sizeof(result)); } + return result; } @@ -249,6 +253,7 @@ static void StartColdApp(AppSpawnClientExt *appProperty) if (appProperty == NULL) { return; } + if (appProperty->property.flags & 0x01) { char cold[10] = {0}; // 10 cold int ret = GetParameter("appspawn.cold.boot", "false", cold, sizeof(cold)); @@ -280,6 +285,7 @@ static int GetProcessTerminationStatusInner(int32_t pid, int *status) APPSPAWN_LOGE("waitpid failed, return : %d, pid: %d, status: %d", exitPid, pid, *status); return -1; } + RemoveAppInfo(pid); return 0; } @@ -306,9 +312,11 @@ static void OnReceiveRequest(const TaskHandle taskHandle, const uint8_t *buffer, AppSpawnClientExt *appProperty = (AppSpawnClientExt *)LE_GetUserData(taskHandle); APPSPAWN_CHECK(appProperty != NULL, LE_CloseTask(LE_GetDefaultLoop(), taskHandle); return, "alloc client Failed"); + int ret = memcpy_s(&appProperty->property, sizeof(appProperty->property), buffer, buffLen); APPSPAWN_CHECK(ret == 0, LE_CloseTask(LE_GetDefaultLoop(), taskHandle); return, "Invalid buffer buffLen %u", buffLen); + #ifdef NWEB_SPAWN // get render process termination status, only nwebspawn need this logic. if (appProperty->property.code == GET_RENDER_TERMINATION_STATUS) { @@ -316,6 +324,7 @@ static void OnReceiveRequest(const TaskHandle taskHandle, const uint8_t *buffer, return; } #endif + APPSPAWN_CHECK(appProperty->property.gidCount <= APP_MAX_GIDS && strlen(appProperty->property.processName) > 0, LE_CloseTask(LE_GetDefaultLoop(), taskHandle); return, "Invalid property %u", appProperty->property.gidCount); @@ -333,6 +342,7 @@ static void OnReceiveRequest(const TaskHandle taskHandle, const uint8_t *buffer, LE_CloseTask(LE_GetDefaultLoop(), taskHandle); return; } + APPSPAWN_LOGI("OnReceiveRequest client.id %d appProperty %d processname %s buffLen %d flags 0x%x", appProperty->client.id, appProperty->property.uid, appProperty->property.processName, buffLen, appProperty->property.flags); @@ -369,10 +379,12 @@ static int OnConnection(const LoopHandle loopHandle, const TaskHandle server) info.disConntectComplete = NULL; info.sendMessageComplete = SendMessageComplete; info.recvMessage = OnReceiveRequest; + LE_STATUS ret = LE_AcceptStreamClient(LE_GetDefaultLoop(), server, &stream, &info); APPSPAWN_CHECK(ret == 0, return -1, "Failed to alloc stream"); AppSpawnClientExt *client = (AppSpawnClientExt *)LE_GetUserData(stream); APPSPAWN_CHECK(client != NULL, return -1, "Failed to alloc stream"); + client->stream = stream; client->client.id = ++clientId; client->client.flags = 0; @@ -380,7 +392,7 @@ static int OnConnection(const LoopHandle loopHandle, const TaskHandle server) return 0; } -static int NotifyResToParent(struct AppSpawnContent_ *content, AppSpawnClient *client, int result) +static void NotifyResToParent(struct AppSpawnContent_ *content, AppSpawnClient *client, int result) { AppSpawnClientExt *appProperty = (AppSpawnClientExt *)client; int fd = appProperty->fd[1]; @@ -388,7 +400,6 @@ static int NotifyResToParent(struct AppSpawnContent_ *content, AppSpawnClient *c write(appProperty->fd[1], &result, sizeof(result)); // close write close(fd); - return 0; } static void AppSpawnInit(AppSpawnContent *content) @@ -425,6 +436,7 @@ void AppSpawnColdRun(AppSpawnContent *content, int argc, char *const argv[]) if (ret == 0 && content->runChildProcessor != NULL) { content->runChildProcessor(content, &client->client); } + APPSPAWN_LOGI("App exit %d.", getpid()); free(client); free(appSpawnContent); @@ -436,6 +448,7 @@ static void AppSpawnRun(AppSpawnContent *content, int argc, char *const argv[]) APPSPAWN_LOGI("AppSpawnRun"); AppSpawnContentExt *appSpawnContent = (AppSpawnContentExt *)content; APPSPAWN_CHECK(appSpawnContent != NULL, return, "Invalid appspawn content"); + LE_STATUS status = LE_CreateSignalTask(LE_GetDefaultLoop(), &appSpawnContent->sigHandler, SignalHandler); if (status == 0) { status = LE_AddSignal(LE_GetDefaultLoop(), appSpawnContent->sigHandler, SIGCHLD); @@ -514,6 +527,7 @@ AppSpawnContent *AppSpawnCreateContent(const char *socketName, char *longProcNam info.server = path; info.baseInfo.close = NULL; info.incommingConntect = OnConnection; + ret = LE_CreateStreamServer(LE_GetDefaultLoop(), &appSpawnContent->server, &info); APPSPAWN_CHECK(ret == 0, free(appSpawnContent); return NULL, "Failed to create socket for %s", path); diff --git a/standard/main.c b/standard/main.c index 95d3cd037a648281addd5a90620e8b46ecf9a46a..aafb046a7e61b5b83ece50669872bd5520661124 100644 --- a/standard/main.c +++ b/standard/main.c @@ -22,10 +22,12 @@ int main(int argc, char *const argv[]) if (argc <= 0) { return 0; } + (void)signal(SIGPIPE, SIG_IGN); uint32_t argvSize = 0; char *buffer = (char *)argv[0]; int mode = 0; + if ((argc > PARAM_INDEX) && (strcmp(argv[START_INDEX], "cold-start") == 0)) { buffer = argv[0]; argvSize = APP_LEN_PROC_NAME; @@ -39,15 +41,18 @@ int main(int argc, char *const argv[]) } argvSize = end - start; } + APPSPAWN_LOGI("AppSpawnCreateContent argc %d mode %d %u", argc, mode, argvSize); AppSpawnContent *content = AppSpawnCreateContent(APPSPAWN_SOCKET_NAME, argv[0], argvSize, mode); APPSPAWN_CHECK(content != NULL, return -1, "Invalid content for appspawn"); APPSPAWN_CHECK(content->initAppSpawn != NULL, return -1, "Invalid content for appspawn"); APPSPAWN_CHECK(content->runAppSpawn != NULL, return -1, "Invalid content for appspawn"); + // set common operation content->loadExtendLib = LoadExtendLib; content->runChildProcessor = RunChildProcessor; content->initAppSpawn(content); content->runAppSpawn(content, argc, argv); + return 0; }