diff --git a/lite/BUILD.gn b/lite/BUILD.gn index 5087966a8f5f6bf9c31b048115038b458154f2df..0026d051f15dd28c2543da90526cef64ca1d9c61 100644 --- a/lite/BUILD.gn +++ b/lite/BUILD.gn @@ -20,7 +20,6 @@ lite_component("appspawn_lite") { # feature: appspawn executable("appspawn") { sources = [ - "../adapter/appspawn_log.cpp", "../common/appspawn_server.c", "appspawn_message.c", "appspawn_process.c", @@ -58,7 +57,7 @@ executable("appspawn") { "${aafwk_lite_path}/frameworks/ability_lite:aafwk_abilitykit_lite", "//base/startup/init_lite/interfaces/innerkits:libbegetutil", "//build/lite/config/component/cJSON:cjson_shared", - "//foundation/communication/ipc_lite:liteipc_adapter", + "//foundation/communication/ipc/interfaces/innerkits/c/ipc:ipc_single", "//foundation/distributeddatamgr/appdatamgr/frameworks/native/kv_store:kv_store", "//foundation/distributedschedule/samgr_lite/samgr:samgr", "//third_party/bounds_checking_function:libsec_shared", @@ -78,7 +77,7 @@ executable("appspawn") { } if (ohos_kernel_type == "linux") { - include_dirs += [] + defines += [ "__LINUX__" ] } } diff --git a/lite/appspawn_service.c b/lite/appspawn_service.c index 4fa6ec3f86fb8b00d72cd446b90b768246528d1e..33e9d4af71a6ee973c199fee19815a91a773debc 100644 --- a/lite/appspawn_service.c +++ b/lite/appspawn_service.c @@ -22,12 +22,13 @@ #include "appspawn_server.h" #include "iproxy_server.h" #include "iunknown.h" -#include "liteipc_adapter.h" +#include "ipc_skeleton.h" #include "message.h" #include "ohos_errno.h" #include "ohos_init.h" #include "samgr_lite.h" #include "service.h" +#include "securec.h" static const int INVALID_PID = -1; static const int CLIENT_ID = 100; @@ -84,29 +85,15 @@ static int GetMessageSt(MessageSt *msgSt, IpcIo *req) if (msgSt == NULL || req == NULL) { return EC_FAILURE; } -#ifdef __LINUX__ + size_t len = 0; - char *str = IpcIoPopString(req, &len); + char* str = ReadString(req, &len); if (str == NULL || len == 0) { APPSPAWN_LOGE("[appspawn] invoke, get data failed."); return EC_FAILURE; } int ret = SplitMessage(str, len, msgSt); // after split message, str no need to free(linux version) -#else - BuffPtr *dataPtr = IpcIoPopDataBuff(req); - if (dataPtr == NULL) { - APPSPAWN_LOGE("[appspawn] invoke, get data failed."); - return EC_FAILURE; - } - - int ret = SplitMessage((char *)dataPtr->buff, dataPtr->buffSz, msgSt); - - // release buffer - if (FreeBuffer(NULL, dataPtr->buff) != LITEIPC_OK) { - APPSPAWN_LOGE("[appspawn] invoke, free buffer failed!"); - } -#endif return ret; } @@ -118,8 +105,11 @@ AppSpawnContent *AppSpawnCreateContent(const char *socketName, char *longProcNam APPSPAWN_LOGI("AppSpawnCreateContent %s", socketName); AppSpawnContentLite *appSpawnContent = (AppSpawnContentLite *)malloc(sizeof(AppSpawnContentLite)); APPSPAWN_CHECK(appSpawnContent != NULL, return NULL, "Failed to alloc memory for appspawn"); + int ret = memset_s(appSpawnContent, sizeof(AppSpawnContentLite), 0, sizeof(AppSpawnContentLite)); + APPSPAWN_CHECK(ret == 0, free(appSpawnContent); + return NULL, "Failed to memset conent"); appSpawnContent->content.longProcName = NULL; - appSpawnContent->content.longProcNameLen = NULL; + appSpawnContent->content.longProcNameLen = 0; g_appSpawnContentLite = appSpawnContent; return appSpawnContent; } @@ -136,30 +126,29 @@ static int Invoke(IServerProxy *iProxy, int funcId, void *origin, IpcIo *req, Ip if (reply == NULL || funcId != ID_CALL_CREATE_SERVICE || req == NULL) { APPSPAWN_LOGE("[appspawn] invoke, funcId %d invalid, reply %d.", funcId, INVALID_PID); - IpcIoPushInt64(reply, INVALID_PID); + WriteInt64(reply, INVALID_PID); return EC_BADPTR; } - - AppSpawnClientLite *client = (AppSpawnClientLite *)malloc(sizeof(AppSpawnClientLite)); - APPSPAWN_CHECK(client != NULL, return -1, "malloc AppSpawnClientLite Failed"); - client->client.id = CLIENT_ID; - client->client.flags = 0; - if (GetMessageSt(&client->message, req) != EC_SUCCESS) { + APPSPAWN_LOGI("[appspawn] invoke."); + AppSpawnClientLite client = {}; + client.client.id = CLIENT_ID; + client.client.flags = 0; + if (GetMessageSt(&client.message, req) != EC_SUCCESS) { APPSPAWN_LOGE("[appspawn] invoke, parse failed! reply %d.", INVALID_PID); - IpcIoPushInt64(reply, INVALID_PID); + WriteInt64(reply, INVALID_PID); return EC_FAILURE; } - APPSPAWN_LOGI("[appspawn] invoke, msg<%s,%s,%d,%d %d>", client->message.bundleName, client->message.identityID, - client->message.uID, client->message.gID, client->message.capsCnt); + APPSPAWN_LOGI("[appspawn] invoke, msg<%s,%s,%d,%d %d>", client.message.bundleName, client.message.identityID, + client.message.uID, client.message.gID, client.message.capsCnt); pid_t newPid = 0; - int ret = AppSpawnProcessMsg(g_appSpawnContentLite, &client->client, &newPid); + int ret = AppSpawnProcessMsg(&g_appSpawnContentLite->content, &client.client, &newPid); if (ret != 0) { newPid = -1; } - FreeMessageSt(&client->message); - IpcIoPushInt64(reply, newPid); + FreeMessageSt(&client.message); + WriteInt64(reply, newPid); #ifdef OHOS_DEBUG struct timespec tmEnd = {0}; diff --git a/lite/bundle.json b/lite/bundle.json new file mode 100644 index 0000000000000000000000000000000000000000..41e26ed50f21e38b2b909d4f5b7689d64794a53f --- /dev/null +++ b/lite/bundle.json @@ -0,0 +1,47 @@ +{ + "name": "@ohos/startup_appspawn_lite", + "description": "lite app start manager", + "homePage": "https://gitee.com/openharmony", + "version": "3.1", + "license": "Apache License 2.0", + "repository": "https://gitee.com/openharmony/appspawn_standard", + "publishAs": "code-segment", + "segment": { + "destPath": "base/startup/appspawn_standard/lite" + }, + "dirs": {}, + "scripts": {}, + "component": { + "name": "appspawn_lite", + "subsystem": "startup", + "adapted_system_type": [ + "small" + ], + "rom": "26KB", + "ram": "~1.8M", + "deps": { + "components": [ + "hilog_lite", + "samgr_lite", + "ipc_single", + "kv_store", + "aafwk_lite", + "ace_engine_lite", + "surface", + "ui" + ], + "third_party": [ + "cJSON", + "bounds_checking_function" + ] + }, + "build": { + "sub_component": [ + "//base/startup/appspawn_standard/lite:appspawn_lite" + ], + "test": [ + "//base/startup/appspawn_standard/test/unittest/app_spawn_lite_test:unittest" + ] + } + } +} diff --git a/lite/main.c b/lite/main.c index 569096e87aed2533ca57945a764b8e86662c71ab..3c6592fc3e2ed4ecdf7e3fc758a643acfe36a10b 100644 --- a/lite/main.c +++ b/lite/main.c @@ -67,7 +67,11 @@ int main(int argc, char * const argv[]) sleep(1); APPSPAWN_LOGI("[appspawn] main, enter."); - AppSpawnContent *content = AppSpawnCreateContent("AppSpawn", NULL, 0, 0); + AppSpawnContent *content = AppSpawnCreateContent(APPSPAWN_SERVICE_NAME, NULL, 0, 0); + if (content == NULL) { + APPSPAWN_LOGE("Failed to create content for appspawn"); + return -1; + } SetContentFunction(content); // 1. ipc module init HOS_SystemInit(); diff --git a/test/unittest/app_spawn_lite_test/BUILD.gn b/test/unittest/app_spawn_lite_test/BUILD.gn index 4183b60cbb76f39285cf3d38c9fd09278796d545..90a9382517e2b83f12132600f8d96933793176e0 100644 --- a/test/unittest/app_spawn_lite_test/BUILD.gn +++ b/test/unittest/app_spawn_lite_test/BUILD.gn @@ -51,7 +51,7 @@ unittest("AppSpawnLiteTest") { "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", "//base/startup/init_lite/interfaces/innerkits:libbegetutil", "//build/lite/config/component/cJSON:cjson_shared", - "//foundation/communication/ipc_lite:liteipc_adapter", + "//foundation/communication/ipc/interfaces/innerkits/c/ipc:ipc_single", "//foundation/distributeddatamgr/appdatamgr/frameworks/native/kv_store:kv_store", "//foundation/distributedschedule/samgr_lite/samgr:samgr", "//third_party/bounds_checking_function:libsec_shared",