From 4f03dd3ffc32314b1d71104918f80d3d0624c06b Mon Sep 17 00:00:00 2001 From: cheng_jinsong Date: Tue, 13 Sep 2022 10:55:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=8F=E5=B0=91=E4=B8=8D=E5=BF=85=E8=A6=81?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cheng_jinsong --- interfaces/innerkits/BUILD.gn | 2 +- services/init/init_service_manager.c | 11 +++++---- services/init/standard/init_cmds.c | 36 +++++++++++----------------- services/init/standard/switch_root.c | 1 + services/modules/bootchart/BUILD.gn | 1 - ueventd/BUILD.gn | 5 ---- watchdog/BUILD.gn | 10 ++++---- 7 files changed, 26 insertions(+), 40 deletions(-) diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn index e4c8d9c2..2291ba8e 100755 --- a/interfaces/innerkits/BUILD.gn +++ b/interfaces/innerkits/BUILD.gn @@ -254,7 +254,7 @@ if (defined(ohos_lite)) { external_deps = [ "c_utils:utils", "hilog_native:libhilog_base", - "ipc:ipc_core", + "ipc:ipc_single", "samgr:samgr_proxy", ] public_configs = [ ":exported_header_files" ] diff --git a/services/init/init_service_manager.c b/services/init/init_service_manager.c index 690a0eac..8a7779f3 100755 --- a/services/init/init_service_manager.c +++ b/services/init/init_service_manager.c @@ -1036,6 +1036,10 @@ void ParseAllServices(const cJSON *fileRoot) static Service *GetServiceByExtServName(const char *fullServName) { INIT_ERROR_CHECK(fullServName != NULL, return NULL, "Failed get parameters"); + Service *service = GetServiceByName(fullServName); + if (service != NULL) { // none parameter in fullServName + return service; + } char *tmpServName = strdup(fullServName); char *dstPtr[MAX_PATH_ARGS_CNT] = {NULL}; int returnCount = SplitString(tmpServName, "|", dstPtr, MAX_PATH_ARGS_CNT); @@ -1043,7 +1047,7 @@ static Service *GetServiceByExtServName(const char *fullServName) free(tmpServName); return NULL; } - Service *service = GetServiceByName(dstPtr[0]); + service = GetServiceByName(dstPtr[0]); if (service == NULL) { free(tmpServName); return NULL; @@ -1060,9 +1064,6 @@ static Service *GetServiceByExtServName(const char *fullServName) for (extArgc = 0; extArgc < (returnCount - 1); extArgc++) { service->extraArgs.argv[extArgc + argc] = strdup(dstPtr[extArgc + 1]); } - for (int i = 0; i < service->extraArgs.count - 1; i++) { - INIT_LOGI("service->extraArgs.argv[%d] is %s", i, service->extraArgs.argv[i]); - } service->extraArgs.argv[service->extraArgs.count] = NULL; free(tmpServName); return service; @@ -1102,7 +1103,7 @@ void StopAllServices(int flags, const char **exclude, int size, int (*filter)(const Service *service, const char **exclude, int size)) { Service *service = GetServiceByName("appspawn"); - if (service != NULL && service->pid != -1) { // notify appspawn stop + if (service != NULL && service->pid > 0) { // notify appspawn stop #ifndef STARTUP_INIT_TEST kill(service->pid, SIGTERM); waitpid(service->pid, 0, 0); diff --git a/services/init/standard/init_cmds.c b/services/init/standard/init_cmds.c index bea9bbee..e14e834b 100755 --- a/services/init/standard/init_cmds.c +++ b/services/init/standard/init_cmds.c @@ -89,11 +89,12 @@ int GetParamValue(const char *symValue, unsigned int symLen, char *paramValue, u return 0; } -static int SyncExecCommand(int argc, char * const *argv) +static void SyncExecCommand(int argc, char * const *argv) { - INIT_CHECK(!(argc == 0 || argv == NULL || argv[0] == NULL), return -1); + INIT_CHECK(!(argc == 0 || argv == NULL || argv[0] == NULL), return); + INIT_LOGI("sync exec: %s", argv[0]); pid_t pid = fork(); - INIT_ERROR_CHECK(!(pid < 0), return -1, "Fork new process to format failed: %d", errno); + INIT_ERROR_CHECK(!(pid < 0), return, "Fork new process to format failed: %d", errno); if (pid == 0) { INIT_CHECK_ONLY_ELOG(execv(argv[0], argv) == 0, "execv %s failed! err %d.", argv[0], errno); exit(-1); @@ -102,11 +103,10 @@ static int SyncExecCommand(int argc, char * const *argv) pid_t ret = waitpid(pid, &status, 0); if (ret != pid) { INIT_LOGE("Failed to wait pid %d, errno %d", pid, errno); - return ret; + return; } - INIT_CHECK_ONLY_ELOG(!(!WIFEXITED(status) || WEXITSTATUS(status) != 0), - "Command %s failed with status %d", argv[0], WEXITSTATUS(status)); - return 0; + INIT_LOGI("sync exec: %s result %d %d", argv[0], WEXITSTATUS(status), WIFEXITED(status)); + return; } static void DoIfup(const struct CmdArgs *ctx) @@ -198,8 +198,7 @@ static void DoSyncExec(const struct CmdArgs *ctx) // format: syncexec /xxx/xxx/xxx xxx INIT_ERROR_CHECK(ctx != NULL && ctx->argv[0] != NULL, return, "DoSyncExec: invalid arguments to exec \"%s\"", ctx->argv[0]); - int ret = SyncExecCommand(ctx->argc, ctx->argv); - INIT_LOGI("DoSyncExec end with ret %d", ret); + SyncExecCommand(ctx->argc, ctx->argv); return; } @@ -288,7 +287,8 @@ static void DoMakeDevice(const struct CmdArgs *ctx) static void DoMountFstabFile(const struct CmdArgs *ctx) { INIT_LOGI("Mount partitions from fstab file \" %s \"", ctx->argv[0]); - (void)MountAllWithFstabFile(ctx->argv[0], 0); + int ret = MountAllWithFstabFile(ctx->argv[0], 0); + INIT_LOGI("Mount partitions from fstab file \" %s \" finish ret %d", ctx->argv[0], ret); } static void DoUmountFstabFile(const struct CmdArgs *ctx) @@ -420,7 +420,6 @@ static bool InitFscryptPolicy(void) static void DoInitGlobalKey(const struct CmdArgs *ctx) { - INIT_LOGI("DoInitGlobalKey: start"); if (ctx == NULL || ctx->argc != 1) { INIT_LOGE("DoInitGlobalKey: para invalid"); return; @@ -442,13 +441,11 @@ static void DoInitGlobalKey(const struct CmdArgs *ctx) NULL }; int argc = ARRAY_LENGTH(argv); - int ret = SyncExecCommand(argc, argv); - INIT_LOGI("DoInitGlobalKey: end, ret = %d", ret); + SyncExecCommand(argc, argv); } static void DoInitMainUser(const struct CmdArgs *ctx) { - INIT_LOGI("DoInitMainUser: start"); if (ctx == NULL) { INIT_LOGE("DoInitMainUser: para invalid"); return; @@ -461,13 +458,11 @@ static void DoInitMainUser(const struct CmdArgs *ctx) NULL }; int argc = ARRAY_LENGTH(argv); - int ret = SyncExecCommand(argc, argv); - INIT_LOGI("DoInitMainUser: end, ret = %d", ret); + SyncExecCommand(argc, argv); } static void DoMkswap(const struct CmdArgs *ctx) { - INIT_LOGI("DoMkswap: start"); if (ctx == NULL) { INIT_LOGE("DoMkswap: para invalid"); return; @@ -478,13 +473,11 @@ static void DoMkswap(const struct CmdArgs *ctx) NULL }; int argc = ARRAY_LENGTH(argv); - int ret = SyncExecCommand(argc, argv); - INIT_LOGI("DoMkswap: end, ret = %d", ret); + SyncExecCommand(argc, argv); } static void DoSwapon(const struct CmdArgs *ctx) { - INIT_LOGI("DoSwapon: start"); if (ctx == NULL) { INIT_LOGE("DoSwapon: para invalid"); return; @@ -495,8 +488,7 @@ static void DoSwapon(const struct CmdArgs *ctx) NULL }; int argc = ARRAY_LENGTH(argv); - int ret = SyncExecCommand(argc, argv); - INIT_LOGI("DoSwapon: end, ret = %d", ret); + SyncExecCommand(argc, argv); } static void DoMkSandbox(const struct CmdArgs *ctx) diff --git a/services/init/standard/switch_root.c b/services/init/standard/switch_root.c index 8375a918..b91c3cf3 100644 --- a/services/init/standard/switch_root.c +++ b/services/init/standard/switch_root.c @@ -199,5 +199,6 @@ int SwitchRoot(const char *newRoot) return -1; } FreeRootDir(oldRoot, oldRootStat.st_dev); + INIT_LOGI("SwitchRoot to %s finish", newRoot); return 0; } diff --git a/services/modules/bootchart/BUILD.gn b/services/modules/bootchart/BUILD.gn index 5abae303..83427c84 100755 --- a/services/modules/bootchart/BUILD.gn +++ b/services/modules/bootchart/BUILD.gn @@ -23,7 +23,6 @@ ohos_shared_library("bootchart") { ] deps = [ - "//base/startup/init/interfaces/innerkits:libbegetutil", "//third_party/bounds_checking_function:libsec_shared", "//third_party/cJSON:cjson_static", ] diff --git a/ueventd/BUILD.gn b/ueventd/BUILD.gn index ba4f68c8..b53f0569 100644 --- a/ueventd/BUILD.gn +++ b/ueventd/BUILD.gn @@ -89,11 +89,6 @@ if (defined(ohos_lite)) { deps = service_ueventd_deps defines = [ "__RAMDISK__" ] cflags = [] - if (use_musl == false) { - deps += [ "//base/startup/init/services/param/base:parameterbase" ] - } else { - deps += [ "//base/startup/init/services/param/base:parameterbase_ext" ] - } if (build_selinux) { external_deps = [ "selinux:librestorecon" ] cflags += [ "-DWITH_SELINUX" ] diff --git a/watchdog/BUILD.gn b/watchdog/BUILD.gn index 3a592163..10ea17cf 100644 --- a/watchdog/BUILD.gn +++ b/watchdog/BUILD.gn @@ -32,16 +32,14 @@ if (defined(ohos_lite)) { } else { import("//build/ohos.gni") ohos_executable("watchdog_service") { - sources = [ "init_watchdog.c" ] + sources = [ + "//base/startup/init/services/log/init_commlog.c", + "init_watchdog.c", + ] deps = [ "//base/startup/init/services/log:init_log", "//third_party/bounds_checking_function:libsec_shared", ] - if (use_musl == false) { - deps += [ "//base/startup/init/services/param/base:parameterbase" ] - } else { - deps += [ "//base/startup/init/services/param/base:parameterbase_ext" ] - } defines = [ "LINUX_WATCHDOG" ] defines += [ "_GNU_SOURCE" ] install_enable = true -- GitLab