From 73df2c296688e9075f9d27021dbeb77b88a36bcf Mon Sep 17 00:00:00 2001 From: laiguizhong Date: Tue, 10 May 2022 15:31:02 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9appspawn=5Flite=E5=BD=92?= =?UTF-8?q?=E4=B8=80=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: laiguizhong --- lite/bundle.json | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 lite/bundle.json diff --git a/lite/bundle.json b/lite/bundle.json new file mode 100644 index 00000000..e183e850 --- /dev/null +++ b/lite/bundle.json @@ -0,0 +1,44 @@ +{ + "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_lite", + "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" + ] + } + } +} \ No newline at end of file -- Gitee From 55700a6e97365a767d68c36c4835678089a99033 Mon Sep 17 00:00:00 2001 From: laiguizhong Date: Wed, 11 May 2022 14:29:45 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9L1=20Linux=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: laiguizhong --- lite/BUILD.gn | 3 +-- lite/appspawn_service.c | 25 ++++++++++++++----------- lite/bundle.json | 3 +++ lite/main.c | 6 +++++- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/lite/BUILD.gn b/lite/BUILD.gn index 742678ce..228184a6 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", @@ -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 4fa6ec3f..c3c220de 100644 --- a/lite/appspawn_service.c +++ b/lite/appspawn_service.c @@ -28,6 +28,7 @@ #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; @@ -118,8 +119,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; } @@ -139,26 +143,25 @@ static int Invoke(IServerProxy *iProxy, int funcId, void *origin, IpcIo *req, Ip IpcIoPushInt64(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); 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); + FreeMessageSt(&client.message); IpcIoPushInt64(reply, newPid); #ifdef OHOS_DEBUG diff --git a/lite/bundle.json b/lite/bundle.json index e183e850..843ec327 100644 --- a/lite/bundle.json +++ b/lite/bundle.json @@ -38,6 +38,9 @@ "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 569096e8..3c6592fc 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(); -- Gitee From fd927689e4eb78957d5806eff919121534ff7bd6 Mon Sep 17 00:00:00 2001 From: laiguizhong Date: Wed, 11 May 2022 14:58:27 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=90=8C=E6=AD=A5ipc=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: laiguizhong --- lite/BUILD.gn | 2 +- lite/appspawn_service.c | 24 +++++------------------- lite/bundle.json | 4 ++-- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/lite/BUILD.gn b/lite/BUILD.gn index 228184a6..a2810f44 100644 --- a/lite/BUILD.gn +++ b/lite/BUILD.gn @@ -57,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/distributedschedule/samgr_lite/samgr:samgr", "//third_party/bounds_checking_function:libsec_shared", "//utils/native/lite/kv_store:kv_store", diff --git a/lite/appspawn_service.c b/lite/appspawn_service.c index c3c220de..985478f7 100644 --- a/lite/appspawn_service.c +++ b/lite/appspawn_service.c @@ -85,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; } @@ -140,7 +126,7 @@ 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; } APPSPAWN_LOGI("[appspawn] invoke."); @@ -149,7 +135,7 @@ static int Invoke(IServerProxy *iProxy, int funcId, void *origin, IpcIo *req, Ip 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; } @@ -162,7 +148,7 @@ static int Invoke(IServerProxy *iProxy, int funcId, void *origin, IpcIo *req, Ip newPid = -1; } FreeMessageSt(&client.message); - IpcIoPushInt64(reply, newPid); + WriteInt64(reply, newPid); #ifdef OHOS_DEBUG struct timespec tmEnd = {0}; diff --git a/lite/bundle.json b/lite/bundle.json index 843ec327..41e26ed5 100644 --- a/lite/bundle.json +++ b/lite/bundle.json @@ -23,7 +23,7 @@ "components": [ "hilog_lite", "samgr_lite", - "ipc_lite", + "ipc_single", "kv_store", "aafwk_lite", "ace_engine_lite", @@ -44,4 +44,4 @@ ] } } -} \ No newline at end of file +} -- Gitee From 23f80a59059be1c01f218154b95d0d4b1cde905c Mon Sep 17 00:00:00 2001 From: laiguizhong Date: Wed, 11 May 2022 15:05:52 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=9B=B4=E6=96=B0kv=5Fst?= =?UTF-8?q?ore=E5=9C=B0=E5=9D=80=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: laiguizhong --- lite/BUILD.gn | 2 +- test/unittest/app_spawn_lite_test/BUILD.gn | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lite/BUILD.gn b/lite/BUILD.gn index a2810f44..0026d051 100644 --- a/lite/BUILD.gn +++ b/lite/BUILD.gn @@ -58,9 +58,9 @@ executable("appspawn") { "//base/startup/init_lite/interfaces/innerkits:libbegetutil", "//build/lite/config/component/cJSON:cjson_shared", "//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", - "//utils/native/lite/kv_store:kv_store", ] if (enable_ohos_appexecfwk_feature_ability == true) { diff --git a/test/unittest/app_spawn_lite_test/BUILD.gn b/test/unittest/app_spawn_lite_test/BUILD.gn index 1246f028..07dc5f39 100644 --- a/test/unittest/app_spawn_lite_test/BUILD.gn +++ b/test/unittest/app_spawn_lite_test/BUILD.gn @@ -51,10 +51,10 @@ 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", - "//utils/native/lite/kv_store:kv_store", ] deps += [ -- Gitee From 81a23c153b6f6a9df4714a8531f45a7c1b9434b4 Mon Sep 17 00:00:00 2001 From: laiguizhong Date: Wed, 11 May 2022 15:27:05 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: laiguizhong --- lite/appspawn_service.c | 2 +- test/unittest/app_spawn_lite_test/BUILD.gn | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lite/appspawn_service.c b/lite/appspawn_service.c index 985478f7..33e9d4af 100644 --- a/lite/appspawn_service.c +++ b/lite/appspawn_service.c @@ -22,7 +22,7 @@ #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" diff --git a/test/unittest/app_spawn_lite_test/BUILD.gn b/test/unittest/app_spawn_lite_test/BUILD.gn index 07dc5f39..90a93825 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/interfaces/innerkits/c/ipc:ipc_single", + "//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", -- Gitee