From 77ad0f3d5ddd935813f9caacf95bb0b073070753 Mon Sep 17 00:00:00 2001 From: linruijie Date: Sat, 17 Dec 2022 17:41:46 +0800 Subject: [PATCH] =?UTF-8?q?1572=20=E5=A2=9E=E5=8A=A0=E7=89=B9=E6=80=A7?= =?UTF-8?q?=E5=BC=80=E5=85=B3-startup=5Finit=5Fwith=5Fparam=5Fbase;1599=20?= =?UTF-8?q?setcon=20according=20to=20actual=20process=20name=20=E6=8C=91?= =?UTF-8?q?=E5=8D=95=E5=88=B0monthly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: linruijie --- begetd.gni | 5 +++++ interfaces/innerkits/BUILD.gn | 14 +++----------- services/begetctl/BUILD.gn | 6 +----- services/init/lite/BUILD.gn | 3 ++- services/init/standard/BUILD.gn | 6 +----- services/modules/selinux/selinux_adp.c | 13 ++++++++++++- services/param/BUILD.gn | 4 ++-- services/param/base/BUILD.gn | 22 +++++++++++++++++----- ueventd/BUILD.gn | 9 +++------ 9 files changed, 46 insertions(+), 36 deletions(-) diff --git a/begetd.gni b/begetd.gni index 07ff1952..45657e99 100644 --- a/begetd.gni +++ b/begetd.gni @@ -29,4 +29,9 @@ declare_args() { config_ohos_startup_init_lite_memory_size = 5120 # boot_kernel_extended_cmdline for extend cmdline + + startup_init_with_param_base = false + if (!use_musl) { + startup_init_with_param_base = true + } } diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn index c977f05b..bb1db62d 100755 --- a/interfaces/innerkits/BUILD.gn +++ b/interfaces/innerkits/BUILD.gn @@ -86,7 +86,7 @@ if (defined(ohos_lite)) { defines += [ "__LINUX__" ] deps += [ "//base/startup/init/services/loopevent:loopevent", - "//base/startup/init/services/param/base:parameterbase", + "//base/startup/init/services/param/base:param_base", "//base/startup/init/services/param/linux:param_client", ] } @@ -197,11 +197,7 @@ if (defined(ohos_lite)) { "//third_party/cJSON:cjson", "//third_party/mbedtls:mbedtls_shared", ] - if (use_musl == false) { - deps += [ "//base/startup/init/services/param/base:parameterbase" ] - } else { - deps += [ "//base/startup/init/services/param/base:parameterbase_ext" ] - } + deps += [ "//base/startup/init/services/param/base:param_base" ] external_deps = [ "c_utils:utils", "hilog_native:libhilog_base", @@ -294,11 +290,7 @@ if (defined(ohos_lite)) { "//third_party/bounds_checking_function:libsec_shared", "//third_party/mbedtls:mbedtls_shared", ] - if (use_musl == false) { - deps += [ "//base/startup/init/services/param/base:parameterbase" ] - } else { - deps += [ "//base/startup/init/services/param/base:parameterbase_ext" ] - } + deps += [ "//base/startup/init/services/param/base:param_base" ] external_deps = [ "c_utils:utils", "hilog_native:libhilog_base", diff --git a/services/begetctl/BUILD.gn b/services/begetctl/BUILD.gn index 9de62950..ed8accee 100755 --- a/services/begetctl/BUILD.gn +++ b/services/begetctl/BUILD.gn @@ -201,11 +201,7 @@ if (defined(ohos_lite)) { "//base/startup/init/services/utils:libinit_utils", "//third_party/bounds_checking_function:libsec_static", ] - if (use_musl == false) { - deps += [ "//base/startup/init/services/param/base:parameterbase" ] - } else { - deps += [ "//base/startup/init/services/param/base:parameterbase_ext" ] - } + deps += [ "//base/startup/init/services/param/base:param_base" ] external_deps = [ "c_utils:utils", "hilog_native:libhilog_base", diff --git a/services/init/lite/BUILD.gn b/services/init/lite/BUILD.gn index 9f0d0216..77f69f3e 100644 --- a/services/init/lite/BUILD.gn +++ b/services/init/lite/BUILD.gn @@ -49,6 +49,7 @@ executable("init") { include_dirs = [ "//base/startup/init/interfaces/innerkits/include", "//base/startup/init/interfaces/innerkits/fd_holder", + "//base/startup/init/services/include/param", "//base/startup/init/services/init/include", "//third_party/cJSON", "//third_party/bounds_checking_function/include", @@ -61,7 +62,7 @@ executable("init") { "//base/startup/init/services/log:init_log", "//base/startup/init/services/loopevent:loopevent", "//base/startup/init/services/modules/init_hook:inithook", - "//base/startup/init/services/param/base:parameterbase", + "//base/startup/init/services/param/base:param_base", "//base/startup/init/services/utils:libinit_utils", "//build/lite/config/component/cJSON:cjson_static", "//third_party/bounds_checking_function:libsec_static", diff --git a/services/init/standard/BUILD.gn b/services/init/standard/BUILD.gn index 706fb0f0..56997e65 100644 --- a/services/init/standard/BUILD.gn +++ b/services/init/standard/BUILD.gn @@ -69,11 +69,7 @@ ohos_executable("init") { "//base/startup/init/services/param/linux:param_init", "//base/startup/init/services/utils:libinit_utils", ] - if (use_musl == false) { - deps += [ "//base/startup/init/services/param/base:parameterbase" ] - } else { - deps += [ "//base/startup/init/services/param/base:parameterbase_ext" ] - } + deps += [ "//base/startup/init/services/param/base:param_base" ] deps += [ "//base/customization/config_policy/frameworks/config_policy:configpolicy_util_for_init_static", diff --git a/services/modules/selinux/selinux_adp.c b/services/modules/selinux/selinux_adp.c index 7519c1fc..8ebe2cf9 100755 --- a/services/modules/selinux/selinux_adp.c +++ b/services/modules/selinux/selinux_adp.c @@ -19,6 +19,7 @@ #include "init_hook.h" #include "init_module_engine.h" #include "plugin_adapter.h" +#include "securec.h" #include #include @@ -30,8 +31,13 @@ enum { CMD_RESTORE_INDEX = 3, }; +extern char *__progname; + static int LoadSelinuxPolicy(int id, const char *name, int argc, const char **argv) { + int ret; + char process_context[MAX_SECON_LEN]; + UNUSED(id); UNUSED(name); UNUSED(argc); @@ -44,7 +50,12 @@ static int LoadSelinuxPolicy(int id, const char *name, int argc, const char **ar PLUGIN_LOGI("main, load_policy success."); } - setcon("u:r:init:s0"); + ret = snprintf_s(process_context, sizeof(process_context), sizeof(process_context) - 1, "u:r:%s:s0", __progname); + if (ret == -1) { + setcon("u:r:init:s0"); + } else { + setcon(process_context); + } (void)RestoreconRecurse("/dev"); return 0; } diff --git a/services/param/BUILD.gn b/services/param/BUILD.gn index f32bf01a..c2a36bbc 100755 --- a/services/param/BUILD.gn +++ b/services/param/BUILD.gn @@ -19,7 +19,7 @@ group("parameter") { if (defined(ohos_lite)) { if (ohos_kernel_type == "linux") { deps += [ - "base:parameterbase", + "base:param_base", "linux:param_client", "linux:param_init", ] @@ -31,7 +31,7 @@ group("parameter") { } } else { deps += [ - "base:parameterbase", + "base:param_base", "linux:param_client", "linux:param_init", ] diff --git a/services/param/base/BUILD.gn b/services/param/base/BUILD.gn index d012356b..f13774d1 100644 --- a/services/param/base/BUILD.gn +++ b/services/param/base/BUILD.gn @@ -75,7 +75,7 @@ if (defined(ohos_lite)) { } } } else { - if (use_musl) { + if (!startup_init_with_param_base) { inherited_configs = [ "//build/config/compiler:afdo", "//build/config/compiler:afdo_optimize_size", @@ -113,13 +113,13 @@ if (defined(ohos_lite)) { deps = [] if (use_musl) { + defines += [ "__MUSL__" ] + } + if (!startup_init_with_param_base) { ldflags = [ "-nostdlib" ] configs -= inherited_configs configs += [ "//build/config/compiler:compiler" ] - defines += [ - "PARAM_BASE", - "__MUSL__", - ] + defines += [ "PARAM_BASE" ] } else { include_dirs += [ "//third_party/bounds_checking_function/include" ] sources += [ "//base/startup/init/services/log/init_commlog.c" ] @@ -174,3 +174,15 @@ if (defined(ohos_lite)) { subsystem_name = "startup" } } + +group("param_base") { + if (defined(ohos_lite)) { + deps = [ ":parameterbase" ] + } else { + if (startup_init_with_param_base) { + deps = [ ":parameterbase" ] + } else { + deps = [ ":parameterbase_ext" ] + } + } +} diff --git a/ueventd/BUILD.gn b/ueventd/BUILD.gn index e6e0c4fb..64f04616 100644 --- a/ueventd/BUILD.gn +++ b/ueventd/BUILD.gn @@ -10,13 +10,14 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import("//base/startup/init/begetd.gni") if (defined(ohos_lite)) { if (ohos_kernel_type == "linux") { service_ueventd_deps = [ "//base/startup/init/interfaces/innerkits/socket:libsocket", "//base/startup/init/services/log:init_log", - "//base/startup/init/services/param/base:parameterbase", + "//base/startup/init/services/param/base:param_base", "//base/startup/init/services/utils:libinit_utils", "//third_party/bounds_checking_function:libsec_static", ] @@ -113,11 +114,7 @@ if (defined(ohos_lite)) { deps = service_ueventd_deps deps += [ "//base/startup/init/services/param/linux:param_client" ] cflags = [] - if (use_musl == false) { - deps += [ "//base/startup/init/services/param/base:parameterbase" ] - } else { - deps += [ "//base/startup/init/services/param/base:parameterbase_ext" ] - } + deps += [ "//base/startup/init/services/param/base:param_base" ] if (build_selinux) { external_deps = [ "selinux:librestorecon" ] cflags += [ "-DWITH_SELINUX" ] -- GitLab