diff --git a/begetd.gni b/begetd.gni index 437ce8bc6a2e6d09c54142e4483466aeecfa6bd0..6941aa72901f449076929a3b93885639de3279de 100644 --- a/begetd.gni +++ b/begetd.gni @@ -28,5 +28,13 @@ declare_args() { enable_ohos_startup_init_lite_use_posix_file_api = false config_ohos_startup_init_lite_data_path = "/" + # config memory size for liteos-m + 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/device_info/BUILD.gn b/device_info/BUILD.gn index c3ac559eea1133f46c643116384dbbdf82786825..541d95b4d0c4da5c55146cebfa470318c143ab87 100644 --- a/device_info/BUILD.gn +++ b/device_info/BUILD.gn @@ -33,6 +33,8 @@ if (!defined(ohos_lite)) { "device_info_stub.cpp", ] + shlib_type = "sa" + include_dirs = [ "//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include/", ".", diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn index e0c5e6a06212f077829c50fc68f2cc0200aa7e07..1439b45d56756882386ea03c1b79555108b6077f 100755 --- a/interfaces/innerkits/BUILD.gn +++ b/interfaces/innerkits/BUILD.gn @@ -85,7 +85,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", ] } @@ -171,6 +171,11 @@ if (defined(ohos_lite)) { sources += [ "syspara/param_wrapper.cpp" ] sources += modulemgr_sources + innerapi_tags = [ + "chipsetsdk", + "platformsdk", + ] + defines = [ "INIT_AGENT", "_GNU_SOURCE", @@ -194,11 +199,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", @@ -224,6 +225,8 @@ if (defined(ohos_lite)) { "service_watcher/service_watcher.c", ] + version_script = "libbeget_proxy.versionscript" + include_dirs = include_common deps = [ ":libbegetutil", @@ -291,11 +294,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/interfaces/innerkits/fs_manager/fstab_mount.c b/interfaces/innerkits/fs_manager/fstab_mount.c index c536ceefb97f8e5856642078d0837756c15d7c14..41750a50099b8c37c283deee48a17b32952b27dd 100644 --- a/interfaces/innerkits/fs_manager/fstab_mount.c +++ b/interfaces/innerkits/fs_manager/fstab_mount.c @@ -326,7 +326,7 @@ static int GetSlotInfoFromBootctrl(off_t offset, off_t size) BEGET_ERROR_CHECK(lseek(fd, offset, SEEK_SET) >= 0, close(fd); return -1, "Failed to lseek bootctrl device fd, errno %d", errno); int slotInfo = 0; - BEGET_INFO_CHECK(read(fd, &slotInfo, size) == size, close(fd); return -1, + BEGET_INFO_CHECK(read(fd, &slotInfo, sizeof(slotInfo)) == size, close(fd); return -1, "Failed to read current slot from bootctrl, errno %d", errno); close(fd); return slotInfo; diff --git a/interfaces/innerkits/init_module_engine/BUILD.gn b/interfaces/innerkits/init_module_engine/BUILD.gn index c206211c16a6a3350d8d96954d9106f433470d57..d5d633ca502649e3dfed57f168b3885f09ba81b6 100644 --- a/interfaces/innerkits/init_module_engine/BUILD.gn +++ b/interfaces/innerkits/init_module_engine/BUILD.gn @@ -61,6 +61,7 @@ if (defined(ohos_lite)) { install_images = [ "system", "updater", + "ramdisk", ] symlink_target_name = [ "libinit_module_engine.so" ] } diff --git a/interfaces/innerkits/libbeget_proxy.versionscript b/interfaces/innerkits/libbeget_proxy.versionscript new file mode 100644 index 0000000000000000000000000000000000000000..f35cd896b0e92c2e49e715eccfd26d16ef7d8ba4 --- /dev/null +++ b/interfaces/innerkits/libbeget_proxy.versionscript @@ -0,0 +1,24 @@ +# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +1.0 { + global: + AclGetDevUdid; + AclGetSerial; + ServiceWatchForStatus; + SystemWatchParameter; + WatchParameter; + RemoveParameterWatcher; + local: + *; +}; diff --git a/services/begetctl/BUILD.gn b/services/begetctl/BUILD.gn index cc5ba48d696fcfb9b15adbb1ea804617c725f1e8..c2737d3cb9ca9329a1d2ce0e5d7c3bd650d4b8ec 100755 --- a/services/begetctl/BUILD.gn +++ b/services/begetctl/BUILD.gn @@ -187,11 +187,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/begetctl/partitionslot.cpp b/services/begetctl/partitionslot.cpp index 71888175d66ab941b3648ed52f4b438b06d68609..fc512d17894785780a9da396a595face1b762096 100644 --- a/services/begetctl/partitionslot.cpp +++ b/services/begetctl/partitionslot.cpp @@ -49,9 +49,9 @@ static int GetSlot(BShellHandle handle, int32_t argc, char *argv[]) } std::cout << "Command: partitionslot getslot" << std::endl; sptr partitionslot = IPartitionSlot::Get(); - int bootSlots = 0; - int currentSlot = 0; if (partitionslot != nullptr) { + int bootSlots = 0; + int currentSlot = 0; partitionslot->GetCurrentSlot(currentSlot, bootSlots); std::cout << "The number of slots: " << bootSlots << "," << "current slot: " << currentSlot << std::endl; } @@ -70,9 +70,9 @@ static int GetSuffix(BShellHandle handle, int32_t argc, char *argv[]) } std::cout << "Command: partitionslot getsuffix" << std::endl; int slot = atoi(argv[1]); - std::string suffix = ""; sptr partitionslot = IPartitionSlot::Get(); if (partitionslot != nullptr) { + std::string suffix = ""; partitionslot->GetSlotSuffix(slot, suffix); std::cout << "The slot " << slot << " matches with suffix: " << suffix << std::endl; } diff --git a/services/etc/BUILD.gn b/services/etc/BUILD.gn index ee82d5e203ca6a5159d414b243634b951655ac14..159081b9927643779eb5eb20cd4f0bc8ed5b0251 100755 --- a/services/etc/BUILD.gn +++ b/services/etc/BUILD.gn @@ -119,9 +119,38 @@ if (defined(ohos_lite)) { ] part_name = "init" subsystem_name = "startup" + extra_paras = [] if (target_cpu == "arm64") { - extra_paras = [ "const.product.cpu.abilist=arm64-v8a" ] + extra_paras += [ "const.product.cpu.abilist=arm64-v8a" ] } + if (build_variant == "user") { + extra_paras += [ + "const.secure=1", + "const.debuggable=0", + ] + } else if (build_variant == "root") { + extra_paras += [ + "const.secure=0", + "const.debuggable=1", + ] + } + if (device_type != "default") { + extra_paras += [ + "const.product.devicetype=${device_type}", + "const.build.characteristics=${device_type}", + ] + } + module_install_dir = "etc/param" + } + + ohos_prebuilt_para("ohos.startup.para") { + source = "//base/startup/init/services/etc/param/ohos.startup.para" + install_images = [ + "system", + "updater", + ] + part_name = "init" + subsystem_name = "startup" module_install_dir = "etc/param" } @@ -204,6 +233,7 @@ if (defined(ohos_lite)) { ":ohos.para", ":ohos.para.dac", ":ohos.para.size", + ":ohos.startup.para", ":ohos_const.para", ":passwd", ":syscap.json", diff --git a/services/etc/appender/file_appender.gni b/services/etc/appender/file_appender.gni new file mode 100755 index 0000000000000000000000000000000000000000..dfed821f0179b7be14257b23d02419cca286d7d3 --- /dev/null +++ b/services/etc/appender/file_appender.gni @@ -0,0 +1,124 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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("//build/config/python.gni") +import("//build/templates/common/copy.gni") + +# Append something (files or lines) to a file and install it. +# +# Variables: +# source: file to be appended (Required) +# deps: some targets deps on (Optional) +# output: the final install file name (Optional); +# If not set, it will install with the source file name +# files: files to be appended to the end of source file (Optional) +# lines: lines of strings to be appended to the end of souce file (Optional) +# +# Example: +# ohos_file_appender("cust_passwd") { +# source = "//base/startup/init/services/etc/passwd" +# deps = [ "//base/startup/init/services/etc:passwd" ] +# files = [ "cust_passwd", "passwd2" ] +# lines = [ "tses::1222:1222:/bin/false", "tses2::1223:1223:/bin/false" ] +# output = "passwd" +# } +# It will append files and lines to source passwd file after deps targets +# +template("ohos_file_appender") { + assert(defined(invoker.source), "source full target name must be defined.") + + _file_appender_target = "${target_name}_appended" + + if (defined(invoker.output)) { + _final_install_name = get_path_info(invoker.output, "file") + } else { + _final_install_name = get_path_info(invoker.source, "file") + } + + _appended_file = + target_gen_dir + "/${target_name}.appended/" + _final_install_name + + action_with_pydeps(_file_appender_target) { + script = "//base/startup/init/services/etc/appender/file_appender.py" + depfile = "${target_gen_dir}/${target_name}.d" + if (defined(invoker.deps)) { + deps = invoker.deps + } else { + deps = [] + } + args = [ + "--output", + rebase_path(_appended_file, root_build_dir), + "--source-file", + rebase_path(invoker.source, root_build_dir), + "--depfile", + rebase_path(depfile, root_build_dir), + ] + if (defined(invoker.files)) { + foreach(file, invoker.files) { + args += [ + "--append-file", + rebase_path(file, root_build_dir), + ] + } + } + if (defined(invoker.lines)) { + foreach(line, invoker.lines) { + args += [ + "--append-line", + line, + ] + } + } + inputs = [ invoker.source ] + outputs = [ _appended_file ] + } + + ohos_copy(target_name) { + forward_variables_from(invoker, + [ + "testonly", + "visibility", + + "deps", + "public_configs", + "subsystem_name", + "part_name", + + # For generate_module_info + "install_images", + "module_install_dir", + "relative_install_dir", + "symlink_target_name", + + # Open source license related + "license_file", + "license_as_sources", + ]) + if (defined(deps)) { + deps += [ ":$_file_appender_target" ] + } else { + deps = [ ":$_file_appender_target" ] + } + set_sources_assignment_filter([]) + sources = [ _appended_file ] + outputs = [ "${target_out_dir}/${target_name}/${_final_install_name}" ] + module_type = "etc" + install_enable = true + module_source_dir = "${target_out_dir}/${target_name}" + module_install_name = _final_install_name + if (defined(invoker.install_enable)) { + install_enable = invoker.install_enable + } + } +} diff --git a/services/etc/appender/file_appender.py b/services/etc/appender/file_appender.py new file mode 100755 index 0000000000000000000000000000000000000000..a7a7db2d574dfb80ba8a4fbf1b6ac53741b1183f --- /dev/null +++ b/services/etc/appender/file_appender.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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 optparse +import os +import sys +import stat +import json + + +def parse_args(args): + from scripts.util import build_utils # noqa: E402 + + args = build_utils.expand_file_args(args) + + parser = optparse.OptionParser() + build_utils.add_depfile_option(parser) + parser.add_option('--output', help='fixed para file') + parser.add_option('--source-file', help='source para file') + parser.add_option('--append-file', action="append", type="string", dest="files", help='appended files') + parser.add_option('--append-line', action="append", type="string", dest="lines", help='appended lines') + + options, _ = parser.parse_args(args) + return options + + +def append_files(target_f, options): + # Read source file + with open(options.source_file, 'r') as source_f: + source_contents = source_f.read() + + target_f.write(source_contents) + if options.files: + for append_f in options.files: + with open(append_f, 'r') as src: + target_f.write(src.read()) + if options.lines: + for line in options.lines: + target_f.write(line) + target_f.write("\n") + + +def main(args): + sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, + os.pardir, os.pardir, os.pardir, os.pardir, "build")) + from scripts.util import build_utils # noqa: E402 + + options = parse_args(args) + + if options.files: + depfile_deps = ([options.source_file] + options.files) + else: + depfile_deps = ([options.source_file]) + + with os.fdopen(os.open(options.output, os.O_RDWR | os.O_CREAT, stat.S_IWUSR | stat.S_IRUSR), 'w') as target_f: + append_files(target_f, options) + + build_utils.write_depfile(options.depfile, + options.output, depfile_deps, add_pydeps=False) + + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) diff --git a/services/etc/appender/file_appender.pydeps b/services/etc/appender/file_appender.pydeps new file mode 100755 index 0000000000000000000000000000000000000000..2255c08a9c4c3b6cea238c86cf402da4ef5a1579 --- /dev/null +++ b/services/etc/appender/file_appender.pydeps @@ -0,0 +1,9 @@ +# Generated by running: +# build/print_python_deps.py --root base/startup/init/services/etc/appender --output base/startup/init/services/etc/appender/file_appender.pydeps base/startup/init/services/etc/appender/file_appender.py +../../../../../../build/gn_helpers.py +../../../../../../build/scripts/__init__.py +../../../../../../build/scripts/util/__init__.py +../../../../../../build/scripts/util/build_utils.py +../../../../../../build/scripts/util/md5_check.py +../../../../../../build/scripts/util/pycache.py +file_appender.py diff --git a/services/etc/group b/services/etc/group index 340edb7925757feaaffc0cd452c2adf69722ed19..8fcdd5a9f38bcafb4191662f90407fda2b91ea67 100644 --- a/services/etc/group +++ b/services/etc/group @@ -32,7 +32,7 @@ uiserver:x:1048: servicectrl:x:1050:root,shell,system,samgr,hdf_devmgr,foundation powerctrl:x:1051:root,shell,system,update,power_host,charger,foundation bootctrl:x:1052:root,shell,system -deviceprivate:x:1053:root,shell,system,samgr,hdf_devmgr,deviceinfo,dsoftbus,dms,account,useriam,access_token,device_manager,foundation,dbms,deviceauth,huks_server,dlp_credential,dsserver,edm +deviceprivate:x:1053:root,shell,system,samgr,hdf_devmgr,deviceinfo,dsoftbus,dms,account,useriam,access_token,device_manager,foundation,dbms,deviceauth,huks_server,dlp_credential,dsserver,edm,update hiview:x:1201: hidumper_service:x:1212: shell:x:2000: @@ -46,7 +46,7 @@ ddms:x:3012: access_token:x:3020: blue_host:x:3021: sample_host:x:3022: -usb_host:x:3023: +usb_host:x:3023:shell usbfnMaster_host:x:3024: power_host:x:3025: wifi_host:x:3026: @@ -119,5 +119,7 @@ memmgr:x:1111: ispserver:x:3821: dfs_share:x:3822: appspawn:x:6005: +print:x:3823: security_guard:x:3520: -dsserver:x:3068: \ No newline at end of file +tee:x:6668: +dsserver:x:3068: diff --git a/services/etc/init.cfg b/services/etc/init.cfg index a361657dfbfdbeba53deac364ef5af517545e4b4..8736842b63fcb2d0366be447a7128050c157fd87 100755 --- a/services/etc/init.cfg +++ b/services/etc/init.cfg @@ -169,6 +169,7 @@ "chown system system /sys/class/leds/green/brightness", "chown system system /sys/class/leds/blue/brightness", "chown root radio /proc/cmdline", + "chown update update /dev/block/by-name/misc", "setparam net.tcp.default_init_rwnd 60" ] }, { diff --git a/services/etc/param/ohos.para b/services/etc/param/ohos.para index 493016f26e765751913ab9b6b6271a22fd299c9e..bf08ad0749624edcbe5bdcc51a4eac9461f32e4d 100755 --- a/services/etc/param/ohos.para +++ b/services/etc/param/ohos.para @@ -13,15 +13,13 @@ const.actionable_compatible_property.enabled=false const.postinstall.fstab.prefix=/system -const.secure=1 +const.secure=0 security.perf_harden=1 const.allow.mock.location=0 const.debuggable=1 const.build.characteristics=default const.product.model=ohos const.product.name="OpenHarmony 3.2" -persist.sys.usb.config=hdc -persist.init.bootevent.enable=true const.sandbox=enable const.product.devicetype=default const.software.model=default diff --git a/services/etc/param/ohos.startup.para b/services/etc/param/ohos.startup.para new file mode 100644 index 0000000000000000000000000000000000000000..1a039250c0fe7772aea825df7ab45e1752b1b1bd --- /dev/null +++ b/services/etc/param/ohos.startup.para @@ -0,0 +1,15 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +persist.sys.usb.config=hdc +persist.init.bootevent.enable=true \ No newline at end of file diff --git a/services/etc/param/param_fixer.gni b/services/etc/param/param_fixer.gni index 1f253aac59ef96705373e18c9b81d938beb54298..9b54665ba57dc10c16597ca1ff148543f14bac86 100755 --- a/services/etc/param/param_fixer.gni +++ b/services/etc/param/param_fixer.gni @@ -68,7 +68,6 @@ template("ohos_prebuilt_para") { "license_file", "license_as_sources", ]) - set_sources_assignment_filter([]) sources = [ _fixed_param_file ] outputs = [ "${target_out_dir}/${target_name}/${_output_para_file}" ] module_type = "etc" diff --git a/services/etc/passwd b/services/etc/passwd index fedbb296c7cbef58d751d692f657cc4241567ddd..1346981b1bf395ef83cd2278f5e9a9551a557aa1 100644 --- a/services/etc/passwd +++ b/services/etc/passwd @@ -115,5 +115,7 @@ motion_host:x:3065:3065:::/bin/false memmgr:x:1111:1111:::/bin/false ispserver:x:3821:3821:::/bin/false dfs_share:x:3822:3822:::/bin/false +print:x:3823:3823:::/bin/false security_guard:x:3520:3520:::/bin/false +tee:x:6668:6668:::/bin/false dsserver:x:3068:3068:::/bin/false diff --git a/services/etc_lite/group b/services/etc_lite/group index a1f31930c54d45acd5861f3e5d68450d8f2f628d..f0509267d5e8f478b2a4b0f8b74b76f41a35a39c 100755 --- a/services/etc_lite/group +++ b/services/etc_lite/group @@ -6,3 +6,4 @@ shell:x:2000: faultloggerd:x:1202:root,system watchdog:x:2001:root ueventd:x:2002:root +device_manager:x:3062: diff --git a/services/etc_lite/passwd b/services/etc_lite/passwd index 20d66a5ca35d3521ec51faebcd08923b2d847f95..7a640c28454d8e64974784380a0d5b7529ca0e6c 100755 --- a/services/etc_lite/passwd +++ b/services/etc_lite/passwd @@ -5,3 +5,4 @@ shell:x:2000:2000:::/bin/false faultloggerd:x:1202:1202:::/bin/false watchdog:x:2001:2001:::/bin/false ueventd:x:2002:2002:::/bin/false +device_manager:x:3062:3062:::/bin/false diff --git a/services/init/include/init.h b/services/init/include/init.h index 0a5fe4b3770c64824a07fe35869c126a0d6fb1d4..2268363cbf493f9b934f5355a184495ac5a3a540 100644 --- a/services/init/include/init.h +++ b/services/init/include/init.h @@ -47,6 +47,8 @@ void SystemConfig(void); void SystemRun(void); void SystemExecuteRcs(void); +void ParseInitCfgByPriority(void); +int ParseInitCfg(const char *configFile, void *context); void ReadConfig(void); void SignalInit(void); diff --git a/services/init/include/init_service.h b/services/init/include/init_service.h index 0ac23aeafee47da898c1c1d1f3f17f7af6cb4c3e..9988dcaed7897bfaf27125717b562a1684d6f79f 100644 --- a/services/init/include/init_service.h +++ b/services/init/include/init_service.h @@ -172,7 +172,7 @@ void ReapService(Service *service); void NotifyServiceChange(Service *service, int status); int IsForbidden(const char *fieldStr); int SetImportantValue(Service *curServ, const char *attrName, int value, int flag); -int GetServiceCaps(const cJSON *curArrItem, Service *curServ); +int InitServiceCaps(const cJSON *curArrItem, Service *curServ); int ServiceExec(const Service *service); void CloseServiceFds(Service *service, bool needFree); int UpdaterServiceFds(Service *service, int *fds, size_t fdCount); diff --git a/services/init/include/init_service_socket.h b/services/init/include/init_service_socket.h index f09b6f9b61f9e6f589a77da50dc79403b2d25164..b8ce74e9c1fc0db83f61de0d962c4f8ae5938fc1 100644 --- a/services/init/include/init_service_socket.h +++ b/services/init/include/init_service_socket.h @@ -73,8 +73,8 @@ typedef struct ServiceSocket_ { int CreateServiceSocket(struct Service_ *service); void CloseServiceSocket(struct Service_ *service); -int SocketAddWatcher(ServiceWatcher *watcherHandle, struct Service_ *service, int fd); -void SocketDelWatcher(ServiceWatcher watcherHandle); +int AddSocketWatcher(ServiceWatcher *watcherHandle, struct Service_ *service, int fd); +void RemoveSocketWatcher(ServiceWatcher watcherHandle); #ifdef __cplusplus #if __cplusplus diff --git a/services/init/init_capability.c b/services/init/init_capability.c index 6089e846aaf5a247735ff334c53cc63101f92a1f..acfd22c0bcd932d9760423bf912533c2ea369a12 100644 --- a/services/init/init_capability.c +++ b/services/init/init_capability.c @@ -84,7 +84,7 @@ static unsigned int GetCapByString(const char *capStr) return CAP_LAST_CAP + 1; } -int GetServiceCaps(const cJSON *curArrItem, Service *service) +int InitServiceCaps(const cJSON *curArrItem, Service *service) { INIT_ERROR_CHECK(service != NULL, return SERVICE_FAILURE, "service is null ptr."); INIT_ERROR_CHECK(curArrItem != NULL, return SERVICE_FAILURE, "json is null ptr."); @@ -116,6 +116,8 @@ int GetServiceCaps(const cJSON *curArrItem, Service *service) break; } caps = GetCapByString(capStr); + } else { + caps = CAP_LAST_CAP + 1; } if ((caps > CAP_LAST_CAP) && (caps != (unsigned int)FULL_CAP)) { INIT_LOGE("service=%s not support caps = %s caps %d", service->name, capStr, caps); diff --git a/services/init/init_common_cmds.c b/services/init/init_common_cmds.c index 39b6f26df449138b0758f0e0aee61e29182f6214..0b8717e86b5b6b45b80f5f7e9618cd6f83a501b9 100644 --- a/services/init/init_common_cmds.c +++ b/services/init/init_common_cmds.c @@ -68,7 +68,7 @@ static char *AddOneArg(const char *param, size_t paramLen) begin = strchr(begin + 1, '$'); } size_t allocSize = paramLen + (PARAM_VALUE_LEN_MAX * valueCount) + 1; - char *arg = calloc(sizeof(char), allocSize); + char *arg = calloc(allocSize, sizeof(char)); INIT_CHECK(arg != NULL, return NULL); int ret = GetParamValue(param, paramLen, arg, allocSize); INIT_ERROR_CHECK(ret == 0, free(arg); @@ -104,6 +104,7 @@ char *BuildStringFromCmdArg(const struct CmdArgs *ctx, int startIndex) const struct CmdArgs *GetCmdArg(const char *cmdContent, const char *delim, int argsCount) { INIT_CHECK_RETURN_VALUE(cmdContent != NULL, NULL); + INIT_CHECK_RETURN_VALUE(delim != NULL, NULL); INIT_WARNING_CHECK(argsCount <= SPACES_CNT_IN_CMD_MAX, argsCount = SPACES_CNT_IN_CMD_MAX, "Too much arguments for command, max number is %d", SPACES_CNT_IN_CMD_MAX); struct CmdArgs *ctx = (struct CmdArgs *)calloc(1, sizeof(struct CmdArgs) + sizeof(char *) * (argsCount + 1)); @@ -427,7 +428,7 @@ static void DoMount(const struct CmdArgs *ctx) INIT_ERROR_CHECK(fileSysType != NULL, return, "Failed to get fileSysType."); index++; - char *source = (ctx->argc > index) ? ctx->argv[index] : NULL; + char *source = (ctx->argc > index) ? ctx->argv[index] : NULL; INIT_ERROR_CHECK(source != NULL, return, "Failed to get source."); index++; @@ -714,7 +715,7 @@ int GetCmdLinesFromJson(const cJSON *root, CmdLines **cmdLines) return 0; } -long long InitDiffTime(INIT_TIMING_STAT *stat) +long long InitDiffTime(INIT_TIMING_STAT *stat) { long long diff = (long long)((stat->endTime.tv_sec - stat->startTime.tv_sec) * 1000000); // 1000000 1000ms if (stat->endTime.tv_nsec > stat->startTime.tv_nsec) { diff --git a/services/init/init_common_service.c b/services/init/init_common_service.c index bf7892597431730650789de53d9c9c9e93ea3d73..96be092274341c3ebb725daa49ce52ed7b488404 100644 --- a/services/init/init_common_service.c +++ b/services/init/init_common_service.c @@ -470,7 +470,7 @@ static void CheckServiceSocket(Service *service) INIT_LOGE("Invalid socket %s for service", service->name); tmpSock = tmpSock->next; } - SocketAddWatcher(&tmpSock->watcher, service, tmpSock->sockFd); + AddSocketWatcher(&tmpSock->watcher, service, tmpSock->sockFd); tmpSock = tmpSock->next; } return; @@ -556,8 +556,8 @@ void ServiceReap(Service *service) int UpdaterServiceFds(Service *service, int *fds, size_t fdCount) { - if (service == NULL) { - INIT_LOGE("Invalid service info"); + if (service == NULL || fds == NULL) { + INIT_LOGE("Invalid service info or fds"); return -1; } diff --git a/services/init/init_config.c b/services/init/init_config.c index bc1dcd699d55c8536656e4a5bad9a026d288fd84..a0fc3de5fc16e413a58501c010b80768d4cfb74d 100644 --- a/services/init/init_config.c +++ b/services/init/init_config.c @@ -35,15 +35,6 @@ int ParseInitCfg(const char *configFile, void *context) { UNUSED(context); INIT_LOGV("Parse init configs from %s", configFile); - static const char *excludeCfg[] = { - "/system/etc/init/weston.cfg" - }; - for (int i = 0; i < (int)ARRAY_LENGTH(excludeCfg); i++) { - if (strcmp(configFile, excludeCfg[i]) == 0) { - INIT_LOGE("ParseInitCfg %s not support", configFile); - return 0; - } - } char *fileBuf = ReadFileToBuf(configFile); INIT_ERROR_CHECK(fileBuf != NULL, return -1, "Failed to read file content %s", configFile); @@ -59,8 +50,8 @@ int ParseInitCfg(const char *configFile, void *context) static void ParseAllImports(const cJSON *root) { - char *tmpParamValue = calloc(sizeof(char), PARAM_VALUE_LEN_MAX + 1); - INIT_ERROR_CHECK(tmpParamValue != 0, return, "Failed to alloc memory for param"); + char *tmpParamValue = calloc(PARAM_VALUE_LEN_MAX + 1, sizeof(char)); + INIT_ERROR_CHECK(tmpParamValue != NULL, return, "Failed to alloc memory for param"); cJSON *importAttr = cJSON_GetObjectItemCaseSensitive(root, "import"); if (!cJSON_IsArray(importAttr)) { @@ -103,8 +94,7 @@ void ReadConfig(void) ReadFileInDir(OTHER_CHARGE_PATH, ".cfg", ParseInitCfg, NULL); } else if (InUpdaterMode() == 0) { ParseInitCfg(INIT_CONFIGURATION_FILE, NULL); - ReadFileInDir(OTHER_CFG_PATH, ".cfg", ParseInitCfg, NULL); - ReadFileInDir("/vendor/etc/init", ".cfg", ParseInitCfg, NULL); + ParseInitCfgByPriority(); } else { ReadFileInDir("/etc", ".cfg", ParseInitCfg, NULL); } diff --git a/services/init/init_service_manager.c b/services/init/init_service_manager.c index 26c14991cd4529099c95136351be93dc356d2cec..9f8ce4f9dd4651bc7dacdc13fb643e7551bdc56b 100755 --- a/services/init/init_service_manager.c +++ b/services/init/init_service_manager.c @@ -247,6 +247,9 @@ static int GetGid(cJSON *json, gid_t *gid, Service *curServ) *gid = DecodeGid(str); } else if (cJSON_IsNumber(json)) { *gid = (gid_t)cJSON_GetNumberValue(json); + } else { + INIT_LOGW("Service %s with invalid gid configuration", curServ->name); + *gid = -1; // Invalid gid, set as -1 } INIT_ERROR_CHECK(*gid != (gid_t)(-1), return SERVICE_FAILURE, "Failed to get gid for %s", curServ->name); return SERVICE_SUCCESS; @@ -320,7 +323,7 @@ static int ParseSocketFamily(cJSON *json, ServiceSocket *sockopt) char *stringValue = GetStringValue(json, "family", &strLen); INIT_ERROR_CHECK((stringValue != NULL) && (strLen > 0), return SERVICE_FAILURE, "Failed to get string for family"); - if (strncmp(stringValue, "AF_UNIX", strLen) == 0) { + if (strcmp(stringValue, "AF_UNIX") == 0) { sockopt->family = AF_UNIX; } else if (strncmp(stringValue, "AF_NETLINK", strLen) == 0) { sockopt->family = AF_NETLINK; @@ -851,7 +854,7 @@ int ParseOneService(const cJSON *curItem, Service *service) ParseOneServiceArgs(curItem, service); ret = GetServiceSandbox(curItem, service); INIT_ERROR_CHECK(ret == 0, return SERVICE_FAILURE, "Failed to get sandbox for service %s", service->name); - ret = GetServiceCaps(curItem, service); + ret = InitServiceCaps(curItem, service); INIT_ERROR_CHECK(ret == 0, return SERVICE_FAILURE, "Failed to get caps for service %s", service->name); ret = GetServiceOnDemand(curItem, service); INIT_ERROR_CHECK(ret == 0, return SERVICE_FAILURE, "Failed to get ondemand flag for service %s", service->name); diff --git a/services/init/init_service_socket.c b/services/init/init_service_socket.c index dc304e6d752fd797a68abaa3c50abf85a4a0e6a0..6bf810a4eb57af08a28b590188b2dfa2df915967 100644 --- a/services/init/init_service_socket.c +++ b/services/init/init_service_socket.c @@ -177,13 +177,13 @@ static void ProcessWatchEvent_(const WatcherHandle watcherHandle, int fd, uint32 return; } INIT_LOGI("Socket information detected, fd:%d service name:%s", fd, service->name); - SocketDelWatcher(watcherHandle); + RemoveSocketWatcher(watcherHandle); if (ServiceStart(service) != SERVICE_SUCCESS) { INIT_LOGE("Service %s start failed!", service->name); } } -int SocketAddWatcher(ServiceWatcher *watcherHandle, Service *service, int fd) +int AddSocketWatcher(ServiceWatcher *watcherHandle, Service *service, int fd) { WatcherHandle handle; LE_WatchInfo info = {}; @@ -197,7 +197,7 @@ int SocketAddWatcher(ServiceWatcher *watcherHandle, Service *service, int fd) return ret; } -void SocketDelWatcher(ServiceWatcher watcherHandle) +void RemoveSocketWatcher(ServiceWatcher watcherHandle) { LE_RemoveWatcher(LE_GetDefaultLoop(), (WatcherHandle)watcherHandle); } @@ -219,7 +219,7 @@ int CreateServiceSocket(Service *service) INIT_CHECK_RETURN_VALUE(ret == 0, -1); } if (strcmp(service->name, "ueventd") != 0) { - ret = SocketAddWatcher(&tmpSock->watcher, service, tmpSock->sockFd); + ret = AddSocketWatcher(&tmpSock->watcher, service, tmpSock->sockFd); INIT_CHECK_RETURN_VALUE(ret == 0, -1); } } @@ -237,7 +237,7 @@ void CloseServiceSocket(Service *service) ServiceSocket *sockopt = service->socketCfg; while (sockopt != NULL) { if (sockopt->watcher != NULL) { - SocketDelWatcher(sockopt->watcher); + RemoveSocketWatcher(sockopt->watcher); } if (sockopt->sockFd >= 0) { close(sockopt->sockFd); diff --git a/services/init/lite/BUILD.gn b/services/init/lite/BUILD.gn index 9f0d0216c0a274fe36d556d94743b3de054c0522..77f69f3e975df6bce90c899c8429ca88ae5ada10 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/lite/init.c b/services/init/lite/init.c index 2719496b93476d237e8f33815bdb0b132cf30796..cc285a01099a363e769b3ff588c52e23980bb8fb 100644 --- a/services/init/lite/init.c +++ b/services/init/lite/init.c @@ -50,6 +50,12 @@ void SystemPrepare(void) { } +void ParseInitCfgByPriority(void) +{ + ReadFileInDir(OTHER_CFG_PATH, ".cfg", ParseInitCfg, NULL); + ReadFileInDir("/vendor/etc/init", ".cfg", ParseInitCfg, NULL); +} + void SystemConfig(void) { InitServiceSpace(); diff --git a/services/init/lite/init_jobs.c b/services/init/lite/init_jobs.c index 544f3b72654419e9da128dab18769798936db72f..820c4c34ba8a604a834cc86f2ccdffed3a1752e5 100644 --- a/services/init/lite/init_jobs.c +++ b/services/init/lite/init_jobs.c @@ -52,7 +52,7 @@ static int GetJobName(const cJSON *jobItem, Job *resJob) return 0; } - if (memcpy_s(resJob->name, MAX_JOB_NAME_LEN, jobNameStr, strlen(jobNameStr)) != EOK) { + if (strcpy_s(resJob->name, MAX_JOB_NAME_LEN, jobNameStr) != EOK) { INIT_LOGE("Get job name \"%s\" failed", jobNameStr); return 0; } diff --git a/services/init/standard/BUILD.gn b/services/init/standard/BUILD.gn index 32113ec2fe80a611c5d7afed95d4153426dfcde6..c8b5200d7f5389975b321de2d606e74a5f05902d 100644 --- a/services/init/standard/BUILD.gn +++ b/services/init/standard/BUILD.gn @@ -69,11 +69,7 @@ ohos_executable("init") { "//base/startup/init/services/sandbox:sandbox", "//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", @@ -130,8 +126,9 @@ ohos_executable("init") { if (!enable_ramdisk) { defines += [ "DISABLE_INIT_TWO_STAGES" ] } - if (support_jsapi) { + if (defined(global_parts_info.developtools_profiler)) { defines += [ "SUPPORT_PROFILER_HIDEBUG" ] + external_deps = [ "profiler:libhidebug_init" ] } if (asan_detector) { defines += [ "ASAN_DETECTOR" ] diff --git a/services/init/standard/init.c b/services/init/standard/init.c index 19e0cae3976d13e5256ab9e7ef5efcd129fb30d4..d3d9d467d8d2402f793f0cf429cc62c63554623e 100755 --- a/services/init/standard/init.c +++ b/services/init/standard/init.c @@ -94,6 +94,10 @@ static int FdHolderSockInit(void) void SystemInit(void) { SignalInit(); + + // Set up a session keyring that all processes will have access to. + KeyCtrlGetKeyringId(KEY_SPEC_SESSION_KEYRING, 1); + // umask call always succeeds and return the previous mask value which is not needed here (void)umask(DEFAULT_UMASK_INIT); MakeDirRecursive("/dev/unix/socket", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); @@ -199,9 +203,6 @@ static void StartInitSecondStage(void) // It will panic if close stdio before execv("/bin/sh", NULL) CloseStdio(); - // Set up a session keyring that all processes will have access to. - KeyCtrlGetKeyringId(KEY_SPEC_SESSION_KEYRING, 1); - #ifndef DISABLE_INIT_TWO_STAGES INIT_LOGI("Start init second stage."); SwitchRoot("/usr"); @@ -251,7 +252,7 @@ HOOK_MGR *GetBootStageHookMgr() return bootStageHookMgr; } -INIT_TIMING_STAT g_bootJob = {0}; +INIT_TIMING_STAT g_bootJob = {{0}, {0}}; static void RecordInitBootEvent(const char *initBootEvent) { @@ -370,6 +371,19 @@ INIT_STATIC void TriggerServices(int startMode) } } +void ParseInitCfgByPriority(void) +{ + CfgFiles *files = GetCfgFiles("etc/init"); + for (int i = 0; files && i < MAX_CFG_POLICY_DIRS_CNT; i++) { + if (files->paths[i]) { + if (ReadFileInDir(files->paths[i], ".cfg", ParseInitCfg, NULL) < 0) { + break; + } + } + } + FreeCfgFiles(files); +} + void SystemConfig(void) { INIT_TIMING_STAT timingStat; diff --git a/services/init/standard/init_cmds.c b/services/init/standard/init_cmds.c index be2d2fc54ead41e36b5121e1c9da71616ca3b7a9..6086f1b78f6af8412b4a0dcece5ad7766b51361d 100755 --- a/services/init/standard/init_cmds.c +++ b/services/init/standard/init_cmds.c @@ -44,6 +44,10 @@ #include "securec.h" #include "fscrypt_utils.h" +#ifdef SUPPORT_PROFILER_HIDEBUG +#include +#endif + #define FSCRYPT_POLICY_BUF_SIZE (60) #define DECIMAL 10 #define OCTAL 8 @@ -526,30 +530,7 @@ const struct CmdTable *GetCmdTable(int *number) void OpenHidebug(const char *name) { #ifdef SUPPORT_PROFILER_HIDEBUG -#ifdef __aarch64__ - const char *debugSoPath = "/system/lib64/libhidebug.so"; -#else - const char *debugSoPath = "/system/lib/libhidebug.so"; -#endif - do { - if (access(debugSoPath, F_OK) != 0) { - break; - } - void* handle = dlopen(debugSoPath, RTLD_LAZY); - if (handle == NULL) { - INIT_LOGE("Failed to dlopen libhidebug.so, %s\n", dlerror()); - break; - } - bool (* initParam)(); - initParam = (bool (*)())dlsym(handle, "InitEnvironmentParam"); - if (initParam == NULL) { - INIT_LOGE("Failed to dlsym InitEnvironmentParam, %s\n", dlerror()); - dlclose(handle); - break; - } - (*initParam)(name); - dlclose(handle); - } while (0); + InitEnvironmentParam(name); #endif } diff --git a/services/init/standard/init_signal_handler.c b/services/init/standard/init_signal_handler.c index a71f638ff026affca2c50f53a0180d4b11d721c0..3e8fe9bcca56a647689ba69f3ccb9f68c53408c8 100644 --- a/services/init/standard/init_signal_handler.c +++ b/services/init/standard/init_signal_handler.c @@ -39,12 +39,14 @@ INIT_STATIC void ProcessSignal(const struct signalfd_siginfo *siginfo) Service* service = GetServiceByPid(sigPID); // check child process exit status if (WIFSIGNALED(procStat)) { - INIT_LOGE("Child process %s(pid %d) exit with code : %d", + INIT_LOGE("Child process %s(pid %d) exit with signal : %d", service == NULL ? "Unknown" : service->name, sigPID, WTERMSIG(procStat)); - } - if (WIFEXITED(procStat)) { + } else if (WIFEXITED(procStat)) { INIT_LOGE("Child process %s(pid %d) exit with code : %d", service == NULL ? "Unknown" : service->name, sigPID, WEXITSTATUS(procStat)); + } else { + INIT_LOGE("Child process %s(pid %d) exit with invalid status : %d", + service == NULL ? "Unknown" : service->name, sigPID, procStat); } CmdServiceProcessDelClient(sigPID); INIT_LOGI("SigHandler, SIGCHLD received, Service:%s pid:%d uid:%d status:%d.", diff --git a/services/modules/reboot/reboot.c b/services/modules/reboot/reboot.c index 49939c4f71e8302d146029d60dd2afe39669101f..874b4369a47e7d07130de94d0126e43a86aefb00 100644 --- a/services/modules/reboot/reboot.c +++ b/services/modules/reboot/reboot.c @@ -115,7 +115,8 @@ static int DoRebootOther(int id, const char *name, int argc, const char **argv) const char *cmd = strstr(argv[0], "reboot,"); PLUGIN_CHECK(cmd != NULL, return -1, "Invalid parameter argc %s", argv[0]); PLUGIN_LOGI("DoRebootOther argv %s", argv[0]); - return syscall(__NR_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, cmd + strlen("reboot,")); + return syscall(__NR_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, + LINUX_REBOOT_CMD_RESTART2, cmd + strlen("reboot,")); } static void RebootAdpInit(void) diff --git a/services/modules/seccomp/seccomp_policy.c b/services/modules/seccomp/seccomp_policy.c index 6c57fb3687d4fe43a6ab210e04cbb3975ded16de..59bdae75266ab7baba7ef680ca2dfeb950018785 100644 --- a/services/modules/seccomp/seccomp_policy.c +++ b/services/modules/seccomp/seccomp_policy.c @@ -26,6 +26,7 @@ #include #include #include +#include #ifndef SECCOMP_SET_MODE_FILTER #define SECCOMP_SET_MODE_FILTER (1) @@ -33,12 +34,21 @@ #ifdef __aarch64__ #define FILTER_LIB_PATH_FORMAT "/system/lib64/lib%s_filter.z.so" +#define FILTER_LIB_PATH_HEAD "/system/lib64/lib" #else #define FILTER_LIB_PATH_FORMAT "/system/lib/lib%s_filter.z.so" +#define FILTER_LIB_PATH_HEAD "/system/lib/lib" #endif #define FILTER_NAME_FORMAT "g_%sSeccompFilter" #define FILTER_SIZE_STRING "Size" +typedef enum { + SECCOMP_SUCCESS, + INPUT_ERROR, + RETURN_NULL, + RETURN_ERROR +} SeccompErrorCode; + static bool IsSupportFilterFlag(unsigned int filterFlag) { errno = 0; @@ -53,6 +63,10 @@ static bool IsSupportFilterFlag(unsigned int filterFlag) static bool InstallSeccompPolicy(const struct sock_filter* filter, size_t filterSize, unsigned int filterFlag) { + if (filter == NULL) { + return false; + } + unsigned int flag = 0; struct sock_fprog prog = { (unsigned short)filterSize, @@ -75,43 +89,114 @@ static bool InstallSeccompPolicy(const struct sock_filter* filter, size_t filter return true; } -bool SetSeccompPolicyWithName(const char *filterName) +static char *GetFilterFileByName(const char *filterName) { - char filterLibPath[512] = {0}; - char filterVaribleName[512] = {0}; - struct sock_filter *filterPtr = NULL; - size_t *filterSize = NULL; + size_t maxFilterNameLen = PATH_MAX - strlen(FILTER_LIB_PATH_FORMAT) + strlen("%s") - 1; + if (filterName == NULL || strlen(filterName) > maxFilterNameLen) { + return NULL; + } + + char filterLibPath[PATH_MAX] = {0}; int rc = snprintf_s(filterLibPath, sizeof(filterLibPath), \ - strlen(filterName) + strlen(FILTER_LIB_PATH_FORMAT) - strlen("%s"), \ - FILTER_LIB_PATH_FORMAT, filterName); - PLUGIN_CHECK(rc != -1, return false, "snprintf_s filterLibPath failed"); + strlen(filterName) + strlen(FILTER_LIB_PATH_FORMAT) - strlen("%s"), \ + FILTER_LIB_PATH_FORMAT, filterName); + if (rc == -1) { + return NULL; + } + + return realpath(filterLibPath, NULL); +} + +static int GetSeccompPolicy(const char *filterName, int **handler, + char *filterLibRealPath, struct sock_fprog *prog) +{ + if (filterName == NULL || filterLibRealPath == NULL || \ + handler == NULL || prog == NULL) { + return INPUT_ERROR; + } - rc = snprintf_s(filterVaribleName, sizeof(filterVaribleName), \ + if (strncmp(filterLibRealPath, FILTER_LIB_PATH_HEAD, strlen(FILTER_LIB_PATH_HEAD))) { + return INPUT_ERROR; + } + + char filterVaribleName[PATH_MAX] = {0}; + struct sock_filter *filter = NULL; + size_t *filterSize = NULL; + void *policyHanlder = NULL; + int ret = SECCOMP_SUCCESS; + do { + int rc = snprintf_s(filterVaribleName, sizeof(filterVaribleName), \ strlen(filterName) + strlen(FILTER_NAME_FORMAT) - strlen("%s"), \ FILTER_NAME_FORMAT, filterName); - PLUGIN_CHECK(rc != -1, return false, "snprintf_s faiVribleName failed"); - const char *filterLibRealPath = realpath(filterLibPath, NULL); - PLUGIN_CHECK(filterLibRealPath != NULL, return false, "format filter lib real path failed"); + if (rc == -1) { + ret = RETURN_ERROR; + break; + } + + policyHanlder = dlopen(filterLibRealPath, RTLD_LAZY); + if (policyHanlder == NULL) { + ret = RETURN_NULL; + break; + } + + filter = (struct sock_filter *)dlsym(policyHanlder, filterVaribleName); + if (filter == NULL) { + ret = RETURN_NULL; + break; + } + + rc = strcat_s(filterVaribleName, strlen(filterVaribleName) + \ + strlen(FILTER_SIZE_STRING) + 1, FILTER_SIZE_STRING); + if (rc != 0) { + ret = RETURN_ERROR; + break; + } + + filterSize = (size_t *)dlsym(policyHanlder, filterVaribleName); + if (filterSize == NULL) { + ret = RETURN_NULL; + break; + } + } while (0); + + *handler = (int *)policyHanlder; + prog->filter = filter; + if (filterSize != NULL) { + prog->len = (unsigned short)(*filterSize); + } + + return ret; +} - void *handler = dlopen(filterLibRealPath, RTLD_LAZY); - PLUGIN_CHECK(handler != NULL, return false, "dlopen %s failed", filterLibRealPath); +bool SetSeccompPolicyWithName(const char *filterName) +{ + if (filterName == NULL) { + return false; + } - filterPtr = (struct sock_filter *)dlsym(handler, filterVaribleName); - PLUGIN_CHECK(filterPtr != NULL, dlclose(handler); - return false, "dlsym %s failed", filterVaribleName); + void *handler = NULL; + char *filterLibRealPath = NULL; + struct sock_fprog prog; + bool ret = false; - rc = strcat_s(filterVaribleName, strlen(filterVaribleName) + strlen(FILTER_SIZE_STRING) + 1, FILTER_SIZE_STRING); - PLUGIN_CHECK(rc == 0, dlclose(handler); - return false, "strcat_s filterVaribleName failed"); + filterLibRealPath = GetFilterFileByName(filterName); + PLUGIN_CHECK(filterLibRealPath != NULL, return false, "get filter file name faield"); - filterSize = (size_t *)dlsym(handler, filterVaribleName); - PLUGIN_CHECK(filterSize != NULL, dlclose(handler); - return false, "dlsym %s failed", filterVaribleName); + int retCode = GetSeccompPolicy(filterName, (int **)&handler, filterLibRealPath, &prog); + if (retCode == SECCOMP_SUCCESS) { + ret = InstallSeccompPolicy(prog.filter, prog.len, SECCOMP_FILTER_FLAG_LOG); + } else { + PLUGIN_LOGE("GetSeccompPolicy failed return is %d", retCode); + } - bool ret = InstallSeccompPolicy(filterPtr, *filterSize, SECCOMP_FILTER_FLAG_LOG); + if (handler != NULL) { + dlclose(handler); + } - dlclose(handler); + if (filterLibRealPath != NULL) { + free(filterLibRealPath); + } return ret; } diff --git a/services/modules/seccomp/seccomp_policy/system_arm.seccomp.policy b/services/modules/seccomp/seccomp_policy/system_arm.seccomp.policy index 3b70f6d00f631b41a1c94e2d9dc23766bcddfa0f..1b06803e7ca65364674b1f293e5d2b9e1ee3c535 100644 --- a/services/modules/seccomp/seccomp_policy/system_arm.seccomp.policy +++ b/services/modules/seccomp/seccomp_policy/system_arm.seccomp.policy @@ -214,6 +214,10 @@ getsockopt sendmsg recvmsg semget +shmat +shmdt +shmget +shmctl add_key keyctl inotify_add_watch diff --git a/services/modules/seccomp/seccomp_policy/system_arm64.seccomp.policy b/services/modules/seccomp/seccomp_policy/system_arm64.seccomp.policy index 65a04d0e5712ebfc2f3a20d7044a629759aacfbc..ed32068a7722390b60847bb2eb785b1bd643c0bb 100644 --- a/services/modules/seccomp/seccomp_policy/system_arm64.seccomp.policy +++ b/services/modules/seccomp/seccomp_policy/system_arm64.seccomp.policy @@ -195,6 +195,10 @@ getegid gettid sysinfo semget +shmget +shmctl +shmat +shmdt socket socketpair bind diff --git a/services/modules/selinux/selinux_adp.c b/services/modules/selinux/selinux_adp.c index e62fc96724d530646e3a8275b8461dcfef358ad1..aa446a30a575ba0ce5d640ec0cdf63a24758d217 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 f32bf01adbebd4c7e80757a8067711adfc86c520..c2a36bbcbd36c8524186153327187cdb179a6796 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/adapter/param_dac.c b/services/param/adapter/param_dac.c index b3e354e1637009de003dfee7e4eff854b4549511..5d311a04aa886781645f5c11f629d47f7833c383 100644 --- a/services/param/adapter/param_dac.c +++ b/services/param/adapter/param_dac.c @@ -270,7 +270,9 @@ static int DacCheckParamPermission(const ParamSecurityLabel *srcLabel, const cha PARAM_LOGW("Param '%s' label gid:%d uid:%d mode 0%o", name, srcLabel->cred.gid, srcLabel->cred.uid, localMode); PARAM_LOGW("Cfg label %d gid:%d uid:%d mode 0%o ", labelIndex, node->gid, node->uid, node->mode); #ifndef __MUSL__ +#ifndef STARTUP_INIT_TEST ret = DAC_RESULT_PERMISSION; +#endif #endif } return ret; diff --git a/services/param/adapter/param_persistadp.c b/services/param/adapter/param_persistadp.c index 1b2f36562bc1f6d025fd780bd1a5e22468b679d7..ad26c31782f63e06e3332004f5f8bd31c199d058 100644 --- a/services/param/adapter/param_persistadp.c +++ b/services/param/adapter/param_persistadp.c @@ -32,23 +32,10 @@ static int LoadOnePersistParam_(const uint32_t *context, const char *name, const return WriteParam(name, value, &dataIndex, 0); } -static int LoadPersistParam() +static void LoadPersistParam_(const char *fileName, char *buffer, uint32_t buffSize) { - CheckAndCreateDir(PARAM_PERSIST_SAVE_PATH); - int updaterMode = InUpdaterMode(); - char *tmpPath = (updaterMode == 0) ? PARAM_PERSIST_SAVE_TMP_PATH : "/param/tmp_persist_parameters"; - FILE *fp = fopen(tmpPath, "r"); - if (fp == NULL) { - tmpPath = (updaterMode == 0) ? PARAM_PERSIST_SAVE_PATH : "/param/persist_parameters"; - fp = fopen(tmpPath, "r"); - PARAM_LOGI("Load persist param, from file %s", tmpPath); - } - PARAM_CHECK(fp != NULL, return -1, "No valid persist parameter file %s", PARAM_PERSIST_SAVE_PATH); - - const int buffSize = PARAM_NAME_LEN_MAX + PARAM_CONST_VALUE_LEN_MAX + 10; // 10 max len - char *buffer = malloc(buffSize); - PARAM_CHECK(buffer != NULL, (void)fclose(fp); - return -1, "Failed to alloc"); + FILE *fp = fopen(fileName, "r"); + PARAM_CHECK(fp != NULL, return, "No valid persist parameter file %s", fileName); uint32_t paramNum = 0; while (fgets(buffer, buffSize, fp) != NULL) { @@ -58,8 +45,22 @@ static int LoadPersistParam() paramNum++; } (void)fclose(fp); + PARAM_LOGI("LoadPersistParam from file %s paramNum %d", fileName, paramNum); +} + +static int LoadPersistParam(void) +{ + CheckAndCreateDir(PARAM_PERSIST_SAVE_PATH); + const uint32_t buffSize = PARAM_NAME_LEN_MAX + PARAM_CONST_VALUE_LEN_MAX + 10; // 10 max len + char *buffer = malloc(buffSize); + PARAM_CHECK(buffer != NULL, return -1, "Failed to alloc"); + + int updaterMode = InUpdaterMode(); + char *tmpPath = (updaterMode == 0) ? PARAM_PERSIST_SAVE_PATH : "/param/persist_parameters"; + LoadPersistParam_(tmpPath, buffer, buffSize); + tmpPath = (updaterMode == 0) ? PARAM_PERSIST_SAVE_TMP_PATH : "/param/tmp_persist_parameters"; + LoadPersistParam_(tmpPath, buffer, buffSize); free(buffer); - PARAM_LOGI("LoadPersistParam from file %s paramNum %d", tmpPath, paramNum); return 0; } diff --git a/services/param/base/BUILD.gn b/services/param/base/BUILD.gn index b1aadaae600c9dbd92d53f76ca73fa4bc777f2d8..f13774d14d4047b633e003a8528a2dad92de7512 100644 --- a/services/param/base/BUILD.gn +++ b/services/param/base/BUILD.gn @@ -69,9 +69,13 @@ if (defined(ohos_lite)) { "PARAMWORKSPACE_NEED_MUTEX", ] } + if (defined(config_ohos_startup_init_lite_memory_size)) { + defines += + [ "PARAM_WORKSPACE_MAX=${config_ohos_startup_init_lite_memory_size}" ] + } } } else { - if (use_musl) { + if (!startup_init_with_param_base) { inherited_configs = [ "//build/config/compiler:afdo", "//build/config/compiler:afdo_optimize_size", @@ -109,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" ] @@ -170,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/services/param/base/param_comm.c b/services/param/base/param_comm.c index fdc03e74a8d9ddbbc5028343c8c2b4e8910fb89e..1a31432caa87c3adc681b0005b48b41803c6ea48 100644 --- a/services/param/base/param_comm.c +++ b/services/param/base/param_comm.c @@ -266,7 +266,7 @@ static int AddParam(WorkSpace *workSpace, uint8_t type, const char *name, const ATOMIC_STORE_EXPLICIT(&workSpace->area->commitId, ++globalCommitId, memory_order_release); #ifdef PARAM_SUPPORT_SELINUX WorkSpace *space = GetWorkSpace(WORKSPACE_NAME_DAC); - if (space != workSpace) { // dac commit is global commit + if (space != NULL && space != workSpace) { // dac commit is global commit globalCommitId = ATOMIC_LOAD_EXPLICIT(&space->area->commitId, memory_order_relaxed); ATOMIC_STORE_EXPLICIT(&space->area->commitId, ++globalCommitId, memory_order_release); } @@ -299,7 +299,7 @@ static int UpdateParam(const WorkSpace *workSpace, uint32_t *dataIndex, const ch ATOMIC_STORE_EXPLICIT(&workSpace->area->commitId, ++globalCommitId, memory_order_release); #ifdef PARAM_SUPPORT_SELINUX WorkSpace *space = GetWorkSpace(WORKSPACE_NAME_DAC); - if (space != workSpace) { // dac commit is global commit + if (space != NULL && space != workSpace) { // dac commit is global commit globalCommitId = ATOMIC_LOAD_EXPLICIT(&space->area->commitId, memory_order_relaxed); ATOMIC_STORE_EXPLICIT(&space->area->commitId, ++globalCommitId, memory_order_release); } diff --git a/services/param/include/param_osadp.h b/services/param/include/param_osadp.h index 3fdbfe6aedb25131f128142a417fc369b30e19b3..26b093fa186ae348011fa2af173c20d8d2e9b8f3 100755 --- a/services/param/include/param_osadp.h +++ b/services/param/include/param_osadp.h @@ -59,7 +59,9 @@ extern "C" { #ifdef STARTUP_INIT_TEST #define PARAM_WORKSPACE_MAX (1024 * 50) #else -#define PARAM_WORKSPACE_MAX (1024 * 30) +#ifndef PARAM_WORKSPACE_MAX +#define PARAM_WORKSPACE_MAX (1024 * 5) +#endif #endif #define PARAM_WORKSPACE_SMALL PARAM_WORKSPACE_MAX #define PARAM_WORKSPACE_DEF PARAM_WORKSPACE_MAX diff --git a/services/param/liteos/BUILD.gn b/services/param/liteos/BUILD.gn index ea03c3b9fa679913b8cb7297bb08b8c23ba7a870..e5dbfc2244bc7ba5545450cce11b2f4f2e9b8791 100644 --- a/services/param/liteos/BUILD.gn +++ b/services/param/liteos/BUILD.gn @@ -103,6 +103,10 @@ static_library("param_init_lite") { "PARAM_SUPPORT_CYCLE_CHECK", ] } + if (defined(config_ohos_startup_init_lite_memory_size)) { + defines += + [ "PARAM_WORKSPACE_MAX=${config_ohos_startup_init_lite_memory_size}" ] + } } static_library("param_client_lite") { @@ -148,5 +152,10 @@ static_library("param_client_lite") { include_dirs += [ "$root_out_dir/gen/init" ] defines += [ "PARAM_LOAD_CFG_FROM_CODE" ] } + + if (defined(config_ohos_startup_init_lite_memory_size)) { + defines += + [ "PARAM_WORKSPACE_MAX=${config_ohos_startup_init_lite_memory_size}" ] + } } } diff --git a/services/param/liteos/param_osadp.c b/services/param/liteos/param_osadp.c index 3451c24961774e5ac8cb4d55ceb4ac479c75f10a..c6c59ee44e8bbd278cc4761ac09d9a3909dafdd1 100644 --- a/services/param/liteos/param_osadp.c +++ b/services/param/liteos/param_osadp.c @@ -215,13 +215,26 @@ INIT_LOCAL_API int ParamMutexDelete(ParamMutex *mutex) #endif #ifdef __LITEOS_M__ +__attribute__((weak)) void* GetSysParamMem(uint32_t spaceSize) +{ + return malloc(spaceSize); +} + +__attribute__((weak)) void FreeSysParamMem(void *mem) +{ + if (mem == NULL) { + return; + } + free(mem); +} + INIT_LOCAL_API void *GetSharedMem(const char *fileName, MemHandle *handle, uint32_t spaceSize, int readOnly) { PARAM_CHECK(spaceSize <= PARAM_WORKSPACE_MAX, return NULL, "Invalid spaceSize %u", spaceSize); UNUSED(fileName); UNUSED(handle); UNUSED(readOnly); - return (void *)malloc(spaceSize); + return GetSysParamMem(spaceSize); } INIT_LOCAL_API void FreeSharedMem(const MemHandle *handle, void *mem, uint32_t dataSize) @@ -229,7 +242,7 @@ INIT_LOCAL_API void FreeSharedMem(const MemHandle *handle, void *mem, uint32_t d PARAM_CHECK(mem != NULL && handle != NULL, return, "Invalid mem or handle"); UNUSED(handle); UNUSED(dataSize); - free(mem); + FreeSysParamMem(mem); } INIT_LOCAL_API void paramMutexEnvInit(void) diff --git a/services/param/manager/param_manager.c b/services/param/manager/param_manager.c index bd765eb45ef4b4026449ba918ef7ffca8c626148..dba601abea5f6d7fcb019b3b4008a2cd84105b1d 100644 --- a/services/param/manager/param_manager.c +++ b/services/param/manager/param_manager.c @@ -299,7 +299,8 @@ static int GetServiceCtrlInfoForPowerCtrl(const char *name, const char *value, S } // not found reboot, so reboot by normal valueOffset = strlen(OHOS_SERVICE_CTRL_PREFIX) + strlen("reboot") + 1; - return CreateCtrlInfo(ctrlInfo, "reboot.other", valueOffset, 1, "%s%s.%s", OHOS_SERVICE_CTRL_PREFIX, "reboot", value); + return CreateCtrlInfo(ctrlInfo, "reboot.other", valueOffset, 1, "%s%s.%s", + OHOS_SERVICE_CTRL_PREFIX, "reboot", value); } INIT_LOCAL_API int GetServiceCtrlInfo(const char *name, const char *value, ServiceCtrlInfo **ctrlInfo) diff --git a/services/param/watcher/proxy/watcher_manager.cpp b/services/param/watcher/proxy/watcher_manager.cpp index 68974529d4aeb1de28d8938ab00546425c06c0a5..8a5ba0150a74d1d62d867f17df85d5f1da5dc62a 100644 --- a/services/param/watcher/proxy/watcher_manager.cpp +++ b/services/param/watcher/proxy/watcher_manager.cpp @@ -434,16 +434,16 @@ void WatcherManager::DumpAllGroup(int fd, ParamWatcherProcessor dumpHandle) auto group = it->second; dprintf(fd, "Watch prefix : %s \n", group->GetKeyPrefix().c_str()); dprintf(fd, "Watch group id : %u \n", group->GetGroupId()); - dprintf(fd, "Watch count : %zu \n", group->GetNodeCount()); + dprintf(fd, "Watch count : %u \n", group->GetNodeCount()); group->TraversalNode(dumpHandle); count += group->GetNodeCount(); dprintf(fd, "\n"); } - dprintf(fd, "Watch prefix count : %zu [%zu %zu %zu]\n", watcherGroups_->GetNodeCount(), + dprintf(fd, "Watch prefix count : %u [%zu %zu %zu]\n", watcherGroups_->GetNodeCount(), sizeof(RemoteWatcher), sizeof(WatcherGroup), sizeof(WatcherNode)); - dprintf(fd, "Watch agent count : %zu \n", remoteWatchers_->GetNodeCount()); - dprintf(fd, "Watch count : %zu \n", count); + dprintf(fd, "Watch agent count : %u \n", remoteWatchers_->GetNodeCount()); + dprintf(fd, "Watch count : %u \n", count); } int WatcherManager::Dump(int fd, const std::vector& args) diff --git a/services/param/watcher/proxy/watcher_manager_stub.cpp b/services/param/watcher/proxy/watcher_manager_stub.cpp index 7d2f1e4a694c3e621cf99820da36fae53f1ad299..7cacbee3adda213adc08a406b33e50e81851f8c7 100644 --- a/services/param/watcher/proxy/watcher_manager_stub.cpp +++ b/services/param/watcher/proxy/watcher_manager_stub.cpp @@ -14,6 +14,7 @@ */ #include "watcher_manager_stub.h" +#include "watcher_proxy.h" #include "watcher_utils.h" namespace OHOS { @@ -43,7 +44,8 @@ int32_t WatcherManagerStub::OnRemoteRequest(uint32_t code, auto remote = data.ReadRemoteObject(); // 0 is invalid watcherId uint32_t id = data.ReadUint32(); - uint32_t remoteWatcherId = AddRemoteWatcher(id, iface_cast(remote)); + sptr watcher = new WatcherProxy(remote); + uint32_t remoteWatcherId = AddRemoteWatcher(id, watcher); reply.WriteUint32(remoteWatcherId); break; } diff --git a/test/unittest/deviceinfo/DeviceInfoUnittest.cpp b/test/unittest/deviceinfo/DeviceInfoUnittest.cpp index c643bd4eec329d8494e9c470b0435bdea0e08bd7..fcb041290ba49cfd4937a1dd70725d7f972e7f1e 100644 --- a/test/unittest/deviceinfo/DeviceInfoUnittest.cpp +++ b/test/unittest/deviceinfo/DeviceInfoUnittest.cpp @@ -154,7 +154,6 @@ HWTEST_F(DeviceInfoUnittest, DeviceInfoServiceTest, TestSize.Level1) std::vector args = {}; deviceInfoService->Dump(STDOUT_FILENO, args); deviceInfoService->Dump(-1, args); - delete deviceInfoService; } HWTEST_F(DeviceInfoUnittest, TestInterface, TestSize.Level1) diff --git a/test/unittest/init/group_unittest.cpp b/test/unittest/init/group_unittest.cpp index c90455f35e68501d713266f02ab67ef4e0a12b4f..493d0b7b3dcf3ac4934d48a5d0bc0c1378986c5b 100644 --- a/test/unittest/init/group_unittest.cpp +++ b/test/unittest/init/group_unittest.cpp @@ -362,7 +362,7 @@ HWTEST_F(InitGroupManagerUnitTest, TestProcessWatchEvent, TestSize.Level1) ServiceSocket servercfg = {.next = nullptr, .sockFd = 0}; service->socketCfg = &servercfg; ServiceWatcher watcher; - int ret = SocketAddWatcher(&watcher, service, 0); + int ret = AddSocketWatcher(&watcher, service, 0); ASSERT_EQ(ret, 0); uint32_t event; ((WatcherTask *)watcher)->processEvent((WatcherHandle)watcher, 0, &event, service); diff --git a/test/unittest/innerkits/innerkits_unittest.cpp b/test/unittest/innerkits/innerkits_unittest.cpp index 2fc14d1fa0d3354e5861ed91ab505f91074146a5..2e9a6bd7a79b002ec8c1c065439e44a9eddfc6e6 100644 --- a/test/unittest/innerkits/innerkits_unittest.cpp +++ b/test/unittest/innerkits/innerkits_unittest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -212,7 +212,7 @@ HWTEST_F(InnerkitsUnitTest, GetBlockDevicePath_unittest, TestSize.Level1) EXPECT_EQ(GetBlockDevicePath("/invalid", devicePath, MAX_BUFFER_LEN), -1); unlink(BOOT_CMD_LINE); EXPECT_EQ(GetBlockDevicePath("/invalid", devicePath, MAX_BUFFER_LEN), -1); - EXPECT_NE(GetCurrentSlot(), 0); + GetCurrentSlot(); // restore cmdline PrepareCmdLineData(); } @@ -269,7 +269,7 @@ HWTEST_F(InnerkitsUnitTest, TestSysCap, TestSize.Level1) EXPECT_EQ(ret, true); ret = HasSystemCapability("SystemCapability.ArkUI.ArkUI.Napi"); EXPECT_EQ(ret, true); - char *wrongName = (char *)malloc(SYSCAP_MAX_SIZE); + char *wrongName = reinterpret_cast(malloc(SYSCAP_MAX_SIZE)); ASSERT_NE(wrongName, nullptr); EXPECT_EQ(memset_s(wrongName, SYSCAP_MAX_SIZE, 1, SYSCAP_MAX_SIZE), 0); HasSystemCapability(wrongName); @@ -436,26 +436,10 @@ HWTEST_F(InnerkitsUnitTest, TestHoldFd2, TestSize.Level1) GetFdsFromMsg(&fdCount, &requestPid, msghdr); msghdr.msg_flags = MSG_TRUNC; GetFdsFromMsg(&fdCount, &requestPid, msghdr); - msghdr.msg_flags = 0; - msghdr.msg_control = calloc(1, sizeof(struct cmsghdr) + CMSG_LEN(sizeof(struct ucred))); - EXPECT_NE(msghdr.msg_control, nullptr); - msghdr.msg_controllen = sizeof(struct cmsghdr); - GetFdsFromMsg(&fdCount, &requestPid, msghdr); struct iovec iovec = { .iov_base = buffer, .iov_len = MAX_FD_HOLDER_BUFFER, }; - ((struct cmsghdr *)msghdr.msg_control)->cmsg_level = 1; - GetFdsFromMsg(&fdCount, &requestPid, msghdr); - ((struct cmsghdr *)msghdr.msg_control)->cmsg_level = 0; - GetFdsFromMsg(&fdCount, &requestPid, msghdr); - ((struct cmsghdr *)msghdr.msg_control)->cmsg_level = 1; - ((struct cmsghdr *)msghdr.msg_control)->cmsg_type = 1; - GetFdsFromMsg(&fdCount, &requestPid, msghdr); - ((struct cmsghdr *)msghdr.msg_control)->cmsg_level = 1; - ((struct cmsghdr *)msghdr.msg_control)->cmsg_type = SCM_CREDENTIALS; - ((struct cmsghdr *)msghdr.msg_control)->cmsg_len = CMSG_LEN(sizeof(struct ucred)); - GetFdsFromMsg(&fdCount, &requestPid, msghdr); ReceiveFds(0, iovec, &fdCount, false, &requestPid); fds = ReceiveFds(0, iovec, &fdCount, true, &requestPid); if (fds != nullptr) diff --git a/test/unittest/innerkits/modulemgr_unittest.cpp b/test/unittest/innerkits/modulemgr_unittest.cpp index c5cc13e4253021a055667bf687ffcd956006345e..50b6629415f9393b5694b8c4924567826cd06834 100644 --- a/test/unittest/innerkits/modulemgr_unittest.cpp +++ b/test/unittest/innerkits/modulemgr_unittest.cpp @@ -200,7 +200,6 @@ HWTEST_F(ModuleMgrUnitTest, ModuleScanTest, TestSize.Level1) ASSERT_NE(moduleMgr, nullptr); ModuleMgrGetCnt(nullptr); cnt = ModuleMgrGetCnt(moduleMgr); - ASSERT_GE(cnt, 1); ModuleMgrDestroy(moduleMgr); EXPECT_EQ(InitModuleMgrInstall(nullptr), -1); } diff --git a/ueventd/BUILD.gn b/ueventd/BUILD.gn index e6e0c4fbe58308efb0b05588b07744fe2fa15e3d..64f04616c7d0439226ed42d05746628d01598f8f 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" ] diff --git a/ueventd/ueventd_device_handler.c b/ueventd/ueventd_device_handler.c index d642271620d8627a0bf8e5bba8db3b33e8e80e89..d043f04a741c3aab9ae2d21e2455ffbbe91cd95d 100644 --- a/ueventd/ueventd_device_handler.c +++ b/ueventd/ueventd_device_handler.c @@ -235,7 +235,7 @@ static void BuildDeviceSymbolLinks(char **links, int linkNum, const char *parent INIT_LOGW("Too many links, ignore"); return; } - links[linkNum] = calloc(sizeof(char), DEVICE_FILE_SIZE); + links[linkNum] = calloc(DEVICE_FILE_SIZE, sizeof(char)); if (links[linkNum] == NULL) { INIT_LOGE("Failed to allocate memory for link, err = %d", errno); return; @@ -287,7 +287,7 @@ static char **GetBlockDeviceSymbolLinks(const struct Uevent *uevent) INIT_LOGE("Failed to build sys path for device %s", uevent->syspath); return NULL; } - char **links = calloc(sizeof(char *), BLOCKDEVICE_LINKS); + char **links = calloc(BLOCKDEVICE_LINKS, sizeof(char *)); int linkNum = 0; if (links == NULL) { INIT_LOGE("Failed to allocate memory for links, err = %d", errno); @@ -475,8 +475,7 @@ void HandleOtherDeviceEvent(const struct Uevent *uevent) char deviceNode[DEVICE_FILE_SIZE] = {}; char sysPath[SYSPATH_SIZE] = {}; - if ((uevent->syspath == NULL) || - strncpy_s(sysPath, SYSPATH_SIZE - 1, uevent->syspath, strlen(uevent->syspath)) != EOK) { + if (strncpy_s(sysPath, SYSPATH_SIZE - 1, uevent->syspath, strlen(uevent->syspath)) != EOK) { INIT_LOGE("Failed to copy sys path"); return; }