提交 f048d6d8 编写于 作者: C cheng_jinsong 提交者: Gitee

Merge branch 'master' of gitee.com:openharmony/startup_init_lite into 1116_gid

Signed-off-by: Ncheng_jinsong <chengjinsong2@huawei.com>
...@@ -28,5 +28,13 @@ declare_args() { ...@@ -28,5 +28,13 @@ declare_args() {
enable_ohos_startup_init_lite_use_posix_file_api = false enable_ohos_startup_init_lite_use_posix_file_api = false
config_ohos_startup_init_lite_data_path = "/" 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 # boot_kernel_extended_cmdline for extend cmdline
startup_init_with_param_base = false
if (!use_musl) {
startup_init_with_param_base = true
}
} }
...@@ -33,6 +33,8 @@ if (!defined(ohos_lite)) { ...@@ -33,6 +33,8 @@ if (!defined(ohos_lite)) {
"device_info_stub.cpp", "device_info_stub.cpp",
] ]
shlib_type = "sa"
include_dirs = [ include_dirs = [
"//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include/", "//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include/",
".", ".",
......
...@@ -85,7 +85,7 @@ if (defined(ohos_lite)) { ...@@ -85,7 +85,7 @@ if (defined(ohos_lite)) {
defines += [ "__LINUX__" ] defines += [ "__LINUX__" ]
deps += [ deps += [
"//base/startup/init/services/loopevent:loopevent", "//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", "//base/startup/init/services/param/linux:param_client",
] ]
} }
...@@ -171,6 +171,11 @@ if (defined(ohos_lite)) { ...@@ -171,6 +171,11 @@ if (defined(ohos_lite)) {
sources += [ "syspara/param_wrapper.cpp" ] sources += [ "syspara/param_wrapper.cpp" ]
sources += modulemgr_sources sources += modulemgr_sources
innerapi_tags = [
"chipsetsdk",
"platformsdk",
]
defines = [ defines = [
"INIT_AGENT", "INIT_AGENT",
"_GNU_SOURCE", "_GNU_SOURCE",
...@@ -194,11 +199,7 @@ if (defined(ohos_lite)) { ...@@ -194,11 +199,7 @@ if (defined(ohos_lite)) {
"//third_party/bounds_checking_function:libsec_shared", "//third_party/bounds_checking_function:libsec_shared",
"//third_party/mbedtls:mbedtls_shared", "//third_party/mbedtls:mbedtls_shared",
] ]
if (use_musl == false) { deps += [ "//base/startup/init/services/param/base:param_base" ]
deps += [ "//base/startup/init/services/param/base:parameterbase" ]
} else {
deps += [ "//base/startup/init/services/param/base:parameterbase_ext" ]
}
external_deps = [ external_deps = [
"c_utils:utils", "c_utils:utils",
"hilog_native:libhilog_base", "hilog_native:libhilog_base",
...@@ -224,6 +225,8 @@ if (defined(ohos_lite)) { ...@@ -224,6 +225,8 @@ if (defined(ohos_lite)) {
"service_watcher/service_watcher.c", "service_watcher/service_watcher.c",
] ]
version_script = "libbeget_proxy.versionscript"
include_dirs = include_common include_dirs = include_common
deps = [ deps = [
":libbegetutil", ":libbegetutil",
...@@ -291,11 +294,7 @@ if (defined(ohos_lite)) { ...@@ -291,11 +294,7 @@ if (defined(ohos_lite)) {
"//third_party/bounds_checking_function:libsec_shared", "//third_party/bounds_checking_function:libsec_shared",
"//third_party/mbedtls:mbedtls_shared", "//third_party/mbedtls:mbedtls_shared",
] ]
if (use_musl == false) { deps += [ "//base/startup/init/services/param/base:param_base" ]
deps += [ "//base/startup/init/services/param/base:parameterbase" ]
} else {
deps += [ "//base/startup/init/services/param/base:parameterbase_ext" ]
}
external_deps = [ external_deps = [
"c_utils:utils", "c_utils:utils",
"hilog_native:libhilog_base", "hilog_native:libhilog_base",
......
...@@ -326,7 +326,7 @@ static int GetSlotInfoFromBootctrl(off_t offset, off_t size) ...@@ -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, BEGET_ERROR_CHECK(lseek(fd, offset, SEEK_SET) >= 0, close(fd); return -1,
"Failed to lseek bootctrl device fd, errno %d", errno); "Failed to lseek bootctrl device fd, errno %d", errno);
int slotInfo = 0; 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); "Failed to read current slot from bootctrl, errno %d", errno);
close(fd); close(fd);
return slotInfo; return slotInfo;
......
...@@ -61,6 +61,7 @@ if (defined(ohos_lite)) { ...@@ -61,6 +61,7 @@ if (defined(ohos_lite)) {
install_images = [ install_images = [
"system", "system",
"updater", "updater",
"ramdisk",
] ]
symlink_target_name = [ "libinit_module_engine.so" ] symlink_target_name = [ "libinit_module_engine.so" ]
} }
......
# 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:
*;
};
...@@ -187,11 +187,7 @@ if (defined(ohos_lite)) { ...@@ -187,11 +187,7 @@ if (defined(ohos_lite)) {
"//base/startup/init/services/utils:libinit_utils", "//base/startup/init/services/utils:libinit_utils",
"//third_party/bounds_checking_function:libsec_static", "//third_party/bounds_checking_function:libsec_static",
] ]
if (use_musl == false) { deps += [ "//base/startup/init/services/param/base:param_base" ]
deps += [ "//base/startup/init/services/param/base:parameterbase" ]
} else {
deps += [ "//base/startup/init/services/param/base:parameterbase_ext" ]
}
external_deps = [ external_deps = [
"c_utils:utils", "c_utils:utils",
"hilog_native:libhilog_base", "hilog_native:libhilog_base",
......
...@@ -49,9 +49,9 @@ static int GetSlot(BShellHandle handle, int32_t argc, char *argv[]) ...@@ -49,9 +49,9 @@ static int GetSlot(BShellHandle handle, int32_t argc, char *argv[])
} }
std::cout << "Command: partitionslot getslot" << std::endl; std::cout << "Command: partitionslot getslot" << std::endl;
sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get();
int bootSlots = 0;
int currentSlot = 0;
if (partitionslot != nullptr) { if (partitionslot != nullptr) {
int bootSlots = 0;
int currentSlot = 0;
partitionslot->GetCurrentSlot(currentSlot, bootSlots); partitionslot->GetCurrentSlot(currentSlot, bootSlots);
std::cout << "The number of slots: " << bootSlots << "," << "current slot: " << currentSlot << std::endl; 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[]) ...@@ -70,9 +70,9 @@ static int GetSuffix(BShellHandle handle, int32_t argc, char *argv[])
} }
std::cout << "Command: partitionslot getsuffix" << std::endl; std::cout << "Command: partitionslot getsuffix" << std::endl;
int slot = atoi(argv[1]); int slot = atoi(argv[1]);
std::string suffix = "";
sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get();
if (partitionslot != nullptr) { if (partitionslot != nullptr) {
std::string suffix = "";
partitionslot->GetSlotSuffix(slot, suffix); partitionslot->GetSlotSuffix(slot, suffix);
std::cout << "The slot " << slot << " matches with suffix: " << suffix << std::endl; std::cout << "The slot " << slot << " matches with suffix: " << suffix << std::endl;
} }
......
...@@ -119,9 +119,38 @@ if (defined(ohos_lite)) { ...@@ -119,9 +119,38 @@ if (defined(ohos_lite)) {
] ]
part_name = "init" part_name = "init"
subsystem_name = "startup" subsystem_name = "startup"
extra_paras = []
if (target_cpu == "arm64") { 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" module_install_dir = "etc/param"
} }
...@@ -204,6 +233,7 @@ if (defined(ohos_lite)) { ...@@ -204,6 +233,7 @@ if (defined(ohos_lite)) {
":ohos.para", ":ohos.para",
":ohos.para.dac", ":ohos.para.dac",
":ohos.para.size", ":ohos.para.size",
":ohos.startup.para",
":ohos_const.para", ":ohos_const.para",
":passwd", ":passwd",
":syscap.json", ":syscap.json",
......
# 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
}
}
}
#!/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:]))
# 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
...@@ -32,7 +32,7 @@ uiserver:x:1048: ...@@ -32,7 +32,7 @@ uiserver:x:1048:
servicectrl:x:1050:root,shell,system,samgr,hdf_devmgr,foundation servicectrl:x:1050:root,shell,system,samgr,hdf_devmgr,foundation
powerctrl:x:1051:root,shell,system,update,power_host,charger,foundation powerctrl:x:1051:root,shell,system,update,power_host,charger,foundation
bootctrl:x:1052:root,shell,system 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: hiview:x:1201:
hidumper_service:x:1212: hidumper_service:x:1212:
shell:x:2000: shell:x:2000:
...@@ -46,7 +46,7 @@ ddms:x:3012: ...@@ -46,7 +46,7 @@ ddms:x:3012:
access_token:x:3020: access_token:x:3020:
blue_host:x:3021: blue_host:x:3021:
sample_host:x:3022: sample_host:x:3022:
usb_host:x:3023: usb_host:x:3023:shell
usbfnMaster_host:x:3024: usbfnMaster_host:x:3024:
power_host:x:3025: power_host:x:3025:
wifi_host:x:3026: wifi_host:x:3026:
...@@ -119,5 +119,7 @@ memmgr:x:1111: ...@@ -119,5 +119,7 @@ memmgr:x:1111:
ispserver:x:3821: ispserver:x:3821:
dfs_share:x:3822: dfs_share:x:3822:
appspawn:x:6005: appspawn:x:6005:
print:x:3823:
security_guard:x:3520: security_guard:x:3520:
dsserver:x:3068: tee:x:6668:
\ No newline at end of file dsserver:x:3068:
...@@ -169,6 +169,7 @@ ...@@ -169,6 +169,7 @@
"chown system system /sys/class/leds/green/brightness", "chown system system /sys/class/leds/green/brightness",
"chown system system /sys/class/leds/blue/brightness", "chown system system /sys/class/leds/blue/brightness",
"chown root radio /proc/cmdline", "chown root radio /proc/cmdline",
"chown update update /dev/block/by-name/misc",
"setparam net.tcp.default_init_rwnd 60" "setparam net.tcp.default_init_rwnd 60"
] ]
}, { }, {
......
...@@ -13,15 +13,13 @@ ...@@ -13,15 +13,13 @@
const.actionable_compatible_property.enabled=false const.actionable_compatible_property.enabled=false
const.postinstall.fstab.prefix=/system const.postinstall.fstab.prefix=/system
const.secure=1 const.secure=0
security.perf_harden=1 security.perf_harden=1
const.allow.mock.location=0 const.allow.mock.location=0
const.debuggable=1 const.debuggable=1
const.build.characteristics=default const.build.characteristics=default
const.product.model=ohos const.product.model=ohos
const.product.name="OpenHarmony 3.2" const.product.name="OpenHarmony 3.2"
persist.sys.usb.config=hdc
persist.init.bootevent.enable=true
const.sandbox=enable const.sandbox=enable
const.product.devicetype=default const.product.devicetype=default
const.software.model=default const.software.model=default
......
# 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
...@@ -68,7 +68,6 @@ template("ohos_prebuilt_para") { ...@@ -68,7 +68,6 @@ template("ohos_prebuilt_para") {
"license_file", "license_file",
"license_as_sources", "license_as_sources",
]) ])
set_sources_assignment_filter([])
sources = [ _fixed_param_file ] sources = [ _fixed_param_file ]
outputs = [ "${target_out_dir}/${target_name}/${_output_para_file}" ] outputs = [ "${target_out_dir}/${target_name}/${_output_para_file}" ]
module_type = "etc" module_type = "etc"
......
...@@ -115,5 +115,7 @@ motion_host:x:3065:3065:::/bin/false ...@@ -115,5 +115,7 @@ motion_host:x:3065:3065:::/bin/false
memmgr:x:1111:1111:::/bin/false memmgr:x:1111:1111:::/bin/false
ispserver:x:3821:3821:::/bin/false ispserver:x:3821:3821:::/bin/false
dfs_share:x:3822:3822:::/bin/false dfs_share:x:3822:3822:::/bin/false
print:x:3823:3823:::/bin/false
security_guard:x:3520:3520:::/bin/false security_guard:x:3520:3520:::/bin/false
tee:x:6668:6668:::/bin/false
dsserver:x:3068:3068:::/bin/false dsserver:x:3068:3068:::/bin/false
...@@ -6,3 +6,4 @@ shell:x:2000: ...@@ -6,3 +6,4 @@ shell:x:2000:
faultloggerd:x:1202:root,system faultloggerd:x:1202:root,system
watchdog:x:2001:root watchdog:x:2001:root
ueventd:x:2002:root ueventd:x:2002:root
device_manager:x:3062:
...@@ -5,3 +5,4 @@ shell:x:2000:2000:::/bin/false ...@@ -5,3 +5,4 @@ shell:x:2000:2000:::/bin/false
faultloggerd:x:1202:1202:::/bin/false faultloggerd:x:1202:1202:::/bin/false
watchdog:x:2001:2001:::/bin/false watchdog:x:2001:2001:::/bin/false
ueventd:x:2002:2002:::/bin/false ueventd:x:2002:2002:::/bin/false
device_manager:x:3062:3062:::/bin/false
...@@ -47,6 +47,8 @@ void SystemConfig(void); ...@@ -47,6 +47,8 @@ void SystemConfig(void);
void SystemRun(void); void SystemRun(void);
void SystemExecuteRcs(void); void SystemExecuteRcs(void);
void ParseInitCfgByPriority(void);
int ParseInitCfg(const char *configFile, void *context);
void ReadConfig(void); void ReadConfig(void);
void SignalInit(void); void SignalInit(void);
......
...@@ -172,7 +172,7 @@ void ReapService(Service *service); ...@@ -172,7 +172,7 @@ void ReapService(Service *service);
void NotifyServiceChange(Service *service, int status); void NotifyServiceChange(Service *service, int status);
int IsForbidden(const char *fieldStr); int IsForbidden(const char *fieldStr);
int SetImportantValue(Service *curServ, const char *attrName, int value, int flag); 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); int ServiceExec(const Service *service);
void CloseServiceFds(Service *service, bool needFree); void CloseServiceFds(Service *service, bool needFree);
int UpdaterServiceFds(Service *service, int *fds, size_t fdCount); int UpdaterServiceFds(Service *service, int *fds, size_t fdCount);
......
...@@ -73,8 +73,8 @@ typedef struct ServiceSocket_ { ...@@ -73,8 +73,8 @@ typedef struct ServiceSocket_ {
int CreateServiceSocket(struct Service_ *service); int CreateServiceSocket(struct Service_ *service);
void CloseServiceSocket(struct Service_ *service); void CloseServiceSocket(struct Service_ *service);
int SocketAddWatcher(ServiceWatcher *watcherHandle, struct Service_ *service, int fd); int AddSocketWatcher(ServiceWatcher *watcherHandle, struct Service_ *service, int fd);
void SocketDelWatcher(ServiceWatcher watcherHandle); void RemoveSocketWatcher(ServiceWatcher watcherHandle);
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
......
...@@ -84,7 +84,7 @@ static unsigned int GetCapByString(const char *capStr) ...@@ -84,7 +84,7 @@ static unsigned int GetCapByString(const char *capStr)
return CAP_LAST_CAP + 1; 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(service != NULL, return SERVICE_FAILURE, "service is null ptr.");
INIT_ERROR_CHECK(curArrItem != NULL, return SERVICE_FAILURE, "json 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) ...@@ -116,6 +116,8 @@ int GetServiceCaps(const cJSON *curArrItem, Service *service)
break; break;
} }
caps = GetCapByString(capStr); caps = GetCapByString(capStr);
} else {
caps = CAP_LAST_CAP + 1;
} }
if ((caps > CAP_LAST_CAP) && (caps != (unsigned int)FULL_CAP)) { if ((caps > CAP_LAST_CAP) && (caps != (unsigned int)FULL_CAP)) {
INIT_LOGE("service=%s not support caps = %s caps %d", service->name, capStr, caps); INIT_LOGE("service=%s not support caps = %s caps %d", service->name, capStr, caps);
......
...@@ -68,7 +68,7 @@ static char *AddOneArg(const char *param, size_t paramLen) ...@@ -68,7 +68,7 @@ static char *AddOneArg(const char *param, size_t paramLen)
begin = strchr(begin + 1, '$'); begin = strchr(begin + 1, '$');
} }
size_t allocSize = paramLen + (PARAM_VALUE_LEN_MAX * valueCount) + 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); INIT_CHECK(arg != NULL, return NULL);
int ret = GetParamValue(param, paramLen, arg, allocSize); int ret = GetParamValue(param, paramLen, arg, allocSize);
INIT_ERROR_CHECK(ret == 0, free(arg); INIT_ERROR_CHECK(ret == 0, free(arg);
...@@ -104,6 +104,7 @@ char *BuildStringFromCmdArg(const struct CmdArgs *ctx, int startIndex) ...@@ -104,6 +104,7 @@ char *BuildStringFromCmdArg(const struct CmdArgs *ctx, int startIndex)
const struct CmdArgs *GetCmdArg(const char *cmdContent, const char *delim, int argsCount) const struct CmdArgs *GetCmdArg(const char *cmdContent, const char *delim, int argsCount)
{ {
INIT_CHECK_RETURN_VALUE(cmdContent != NULL, NULL); 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, 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); "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)); 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) ...@@ -427,7 +428,7 @@ static void DoMount(const struct CmdArgs *ctx)
INIT_ERROR_CHECK(fileSysType != NULL, return, "Failed to get fileSysType."); INIT_ERROR_CHECK(fileSysType != NULL, return, "Failed to get fileSysType.");
index++; 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."); INIT_ERROR_CHECK(source != NULL, return, "Failed to get source.");
index++; index++;
...@@ -714,7 +715,7 @@ int GetCmdLinesFromJson(const cJSON *root, CmdLines **cmdLines) ...@@ -714,7 +715,7 @@ int GetCmdLinesFromJson(const cJSON *root, CmdLines **cmdLines)
return 0; 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 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) { if (stat->endTime.tv_nsec > stat->startTime.tv_nsec) {
......
...@@ -470,7 +470,7 @@ static void CheckServiceSocket(Service *service) ...@@ -470,7 +470,7 @@ static void CheckServiceSocket(Service *service)
INIT_LOGE("Invalid socket %s for service", service->name); INIT_LOGE("Invalid socket %s for service", service->name);
tmpSock = tmpSock->next; tmpSock = tmpSock->next;
} }
SocketAddWatcher(&tmpSock->watcher, service, tmpSock->sockFd); AddSocketWatcher(&tmpSock->watcher, service, tmpSock->sockFd);
tmpSock = tmpSock->next; tmpSock = tmpSock->next;
} }
return; return;
...@@ -556,8 +556,8 @@ void ServiceReap(Service *service) ...@@ -556,8 +556,8 @@ void ServiceReap(Service *service)
int UpdaterServiceFds(Service *service, int *fds, size_t fdCount) int UpdaterServiceFds(Service *service, int *fds, size_t fdCount)
{ {
if (service == NULL) { if (service == NULL || fds == NULL) {
INIT_LOGE("Invalid service info"); INIT_LOGE("Invalid service info or fds");
return -1; return -1;
} }
......
...@@ -35,15 +35,6 @@ int ParseInitCfg(const char *configFile, void *context) ...@@ -35,15 +35,6 @@ int ParseInitCfg(const char *configFile, void *context)
{ {
UNUSED(context); UNUSED(context);
INIT_LOGV("Parse init configs from %s", configFile); 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); char *fileBuf = ReadFileToBuf(configFile);
INIT_ERROR_CHECK(fileBuf != NULL, return -1, "Failed to read file content %s", 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) ...@@ -59,8 +50,8 @@ int ParseInitCfg(const char *configFile, void *context)
static void ParseAllImports(const cJSON *root) static void ParseAllImports(const cJSON *root)
{ {
char *tmpParamValue = calloc(sizeof(char), PARAM_VALUE_LEN_MAX + 1); char *tmpParamValue = calloc(PARAM_VALUE_LEN_MAX + 1, sizeof(char));
INIT_ERROR_CHECK(tmpParamValue != 0, return, "Failed to alloc memory for param"); INIT_ERROR_CHECK(tmpParamValue != NULL, return, "Failed to alloc memory for param");
cJSON *importAttr = cJSON_GetObjectItemCaseSensitive(root, "import"); cJSON *importAttr = cJSON_GetObjectItemCaseSensitive(root, "import");
if (!cJSON_IsArray(importAttr)) { if (!cJSON_IsArray(importAttr)) {
...@@ -103,8 +94,7 @@ void ReadConfig(void) ...@@ -103,8 +94,7 @@ void ReadConfig(void)
ReadFileInDir(OTHER_CHARGE_PATH, ".cfg", ParseInitCfg, NULL); ReadFileInDir(OTHER_CHARGE_PATH, ".cfg", ParseInitCfg, NULL);
} else if (InUpdaterMode() == 0) { } else if (InUpdaterMode() == 0) {
ParseInitCfg(INIT_CONFIGURATION_FILE, NULL); ParseInitCfg(INIT_CONFIGURATION_FILE, NULL);
ReadFileInDir(OTHER_CFG_PATH, ".cfg", ParseInitCfg, NULL); ParseInitCfgByPriority();
ReadFileInDir("/vendor/etc/init", ".cfg", ParseInitCfg, NULL);
} else { } else {
ReadFileInDir("/etc", ".cfg", ParseInitCfg, NULL); ReadFileInDir("/etc", ".cfg", ParseInitCfg, NULL);
} }
......
...@@ -247,6 +247,9 @@ static int GetGid(cJSON *json, gid_t *gid, Service *curServ) ...@@ -247,6 +247,9 @@ static int GetGid(cJSON *json, gid_t *gid, Service *curServ)
*gid = DecodeGid(str); *gid = DecodeGid(str);
} else if (cJSON_IsNumber(json)) { } else if (cJSON_IsNumber(json)) {
*gid = (gid_t)cJSON_GetNumberValue(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); INIT_ERROR_CHECK(*gid != (gid_t)(-1), return SERVICE_FAILURE, "Failed to get gid for %s", curServ->name);
return SERVICE_SUCCESS; return SERVICE_SUCCESS;
...@@ -320,7 +323,7 @@ static int ParseSocketFamily(cJSON *json, ServiceSocket *sockopt) ...@@ -320,7 +323,7 @@ static int ParseSocketFamily(cJSON *json, ServiceSocket *sockopt)
char *stringValue = GetStringValue(json, "family", &strLen); char *stringValue = GetStringValue(json, "family", &strLen);
INIT_ERROR_CHECK((stringValue != NULL) && (strLen > 0), return SERVICE_FAILURE, INIT_ERROR_CHECK((stringValue != NULL) && (strLen > 0), return SERVICE_FAILURE,
"Failed to get string for family"); "Failed to get string for family");
if (strncmp(stringValue, "AF_UNIX", strLen) == 0) { if (strcmp(stringValue, "AF_UNIX") == 0) {
sockopt->family = AF_UNIX; sockopt->family = AF_UNIX;
} else if (strncmp(stringValue, "AF_NETLINK", strLen) == 0) { } else if (strncmp(stringValue, "AF_NETLINK", strLen) == 0) {
sockopt->family = AF_NETLINK; sockopt->family = AF_NETLINK;
...@@ -851,7 +854,7 @@ int ParseOneService(const cJSON *curItem, Service *service) ...@@ -851,7 +854,7 @@ int ParseOneService(const cJSON *curItem, Service *service)
ParseOneServiceArgs(curItem, service); ParseOneServiceArgs(curItem, service);
ret = GetServiceSandbox(curItem, service); ret = GetServiceSandbox(curItem, service);
INIT_ERROR_CHECK(ret == 0, return SERVICE_FAILURE, "Failed to get sandbox for service %s", service->name); 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); INIT_ERROR_CHECK(ret == 0, return SERVICE_FAILURE, "Failed to get caps for service %s", service->name);
ret = GetServiceOnDemand(curItem, service); ret = GetServiceOnDemand(curItem, service);
INIT_ERROR_CHECK(ret == 0, return SERVICE_FAILURE, "Failed to get ondemand flag for service %s", service->name); INIT_ERROR_CHECK(ret == 0, return SERVICE_FAILURE, "Failed to get ondemand flag for service %s", service->name);
......
...@@ -177,13 +177,13 @@ static void ProcessWatchEvent_(const WatcherHandle watcherHandle, int fd, uint32 ...@@ -177,13 +177,13 @@ static void ProcessWatchEvent_(const WatcherHandle watcherHandle, int fd, uint32
return; return;
} }
INIT_LOGI("Socket information detected, fd:%d service name:%s", fd, service->name); INIT_LOGI("Socket information detected, fd:%d service name:%s", fd, service->name);
SocketDelWatcher(watcherHandle); RemoveSocketWatcher(watcherHandle);
if (ServiceStart(service) != SERVICE_SUCCESS) { if (ServiceStart(service) != SERVICE_SUCCESS) {
INIT_LOGE("Service %s start failed!", service->name); 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; WatcherHandle handle;
LE_WatchInfo info = {}; LE_WatchInfo info = {};
...@@ -197,7 +197,7 @@ int SocketAddWatcher(ServiceWatcher *watcherHandle, Service *service, int fd) ...@@ -197,7 +197,7 @@ int SocketAddWatcher(ServiceWatcher *watcherHandle, Service *service, int fd)
return ret; return ret;
} }
void SocketDelWatcher(ServiceWatcher watcherHandle) void RemoveSocketWatcher(ServiceWatcher watcherHandle)
{ {
LE_RemoveWatcher(LE_GetDefaultLoop(), (WatcherHandle)watcherHandle); LE_RemoveWatcher(LE_GetDefaultLoop(), (WatcherHandle)watcherHandle);
} }
...@@ -219,7 +219,7 @@ int CreateServiceSocket(Service *service) ...@@ -219,7 +219,7 @@ int CreateServiceSocket(Service *service)
INIT_CHECK_RETURN_VALUE(ret == 0, -1); INIT_CHECK_RETURN_VALUE(ret == 0, -1);
} }
if (strcmp(service->name, "ueventd") != 0) { 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); INIT_CHECK_RETURN_VALUE(ret == 0, -1);
} }
} }
...@@ -237,7 +237,7 @@ void CloseServiceSocket(Service *service) ...@@ -237,7 +237,7 @@ void CloseServiceSocket(Service *service)
ServiceSocket *sockopt = service->socketCfg; ServiceSocket *sockopt = service->socketCfg;
while (sockopt != NULL) { while (sockopt != NULL) {
if (sockopt->watcher != NULL) { if (sockopt->watcher != NULL) {
SocketDelWatcher(sockopt->watcher); RemoveSocketWatcher(sockopt->watcher);
} }
if (sockopt->sockFd >= 0) { if (sockopt->sockFd >= 0) {
close(sockopt->sockFd); close(sockopt->sockFd);
......
...@@ -49,6 +49,7 @@ executable("init") { ...@@ -49,6 +49,7 @@ executable("init") {
include_dirs = [ include_dirs = [
"//base/startup/init/interfaces/innerkits/include", "//base/startup/init/interfaces/innerkits/include",
"//base/startup/init/interfaces/innerkits/fd_holder", "//base/startup/init/interfaces/innerkits/fd_holder",
"//base/startup/init/services/include/param",
"//base/startup/init/services/init/include", "//base/startup/init/services/init/include",
"//third_party/cJSON", "//third_party/cJSON",
"//third_party/bounds_checking_function/include", "//third_party/bounds_checking_function/include",
...@@ -61,7 +62,7 @@ executable("init") { ...@@ -61,7 +62,7 @@ executable("init") {
"//base/startup/init/services/log:init_log", "//base/startup/init/services/log:init_log",
"//base/startup/init/services/loopevent:loopevent", "//base/startup/init/services/loopevent:loopevent",
"//base/startup/init/services/modules/init_hook:inithook", "//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", "//base/startup/init/services/utils:libinit_utils",
"//build/lite/config/component/cJSON:cjson_static", "//build/lite/config/component/cJSON:cjson_static",
"//third_party/bounds_checking_function:libsec_static", "//third_party/bounds_checking_function:libsec_static",
......
...@@ -50,6 +50,12 @@ void SystemPrepare(void) ...@@ -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) void SystemConfig(void)
{ {
InitServiceSpace(); InitServiceSpace();
......
...@@ -52,7 +52,7 @@ static int GetJobName(const cJSON *jobItem, Job *resJob) ...@@ -52,7 +52,7 @@ static int GetJobName(const cJSON *jobItem, Job *resJob)
return 0; 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); INIT_LOGE("Get job name \"%s\" failed", jobNameStr);
return 0; return 0;
} }
......
...@@ -69,11 +69,7 @@ ohos_executable("init") { ...@@ -69,11 +69,7 @@ ohos_executable("init") {
"//base/startup/init/services/sandbox:sandbox", "//base/startup/init/services/sandbox:sandbox",
"//base/startup/init/services/utils:libinit_utils", "//base/startup/init/services/utils:libinit_utils",
] ]
if (use_musl == false) { deps += [ "//base/startup/init/services/param/base:param_base" ]
deps += [ "//base/startup/init/services/param/base:parameterbase" ]
} else {
deps += [ "//base/startup/init/services/param/base:parameterbase_ext" ]
}
deps += [ deps += [
"//base/customization/config_policy/frameworks/config_policy:configpolicy_util_for_init_static", "//base/customization/config_policy/frameworks/config_policy:configpolicy_util_for_init_static",
...@@ -130,8 +126,9 @@ ohos_executable("init") { ...@@ -130,8 +126,9 @@ ohos_executable("init") {
if (!enable_ramdisk) { if (!enable_ramdisk) {
defines += [ "DISABLE_INIT_TWO_STAGES" ] defines += [ "DISABLE_INIT_TWO_STAGES" ]
} }
if (support_jsapi) { if (defined(global_parts_info.developtools_profiler)) {
defines += [ "SUPPORT_PROFILER_HIDEBUG" ] defines += [ "SUPPORT_PROFILER_HIDEBUG" ]
external_deps = [ "profiler:libhidebug_init" ]
} }
if (asan_detector) { if (asan_detector) {
defines += [ "ASAN_DETECTOR" ] defines += [ "ASAN_DETECTOR" ]
......
...@@ -94,6 +94,10 @@ static int FdHolderSockInit(void) ...@@ -94,6 +94,10 @@ static int FdHolderSockInit(void)
void SystemInit(void) void SystemInit(void)
{ {
SignalInit(); 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 // umask call always succeeds and return the previous mask value which is not needed here
(void)umask(DEFAULT_UMASK_INIT); (void)umask(DEFAULT_UMASK_INIT);
MakeDirRecursive("/dev/unix/socket", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); MakeDirRecursive("/dev/unix/socket", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
...@@ -199,9 +203,6 @@ static void StartInitSecondStage(void) ...@@ -199,9 +203,6 @@ static void StartInitSecondStage(void)
// It will panic if close stdio before execv("/bin/sh", NULL) // It will panic if close stdio before execv("/bin/sh", NULL)
CloseStdio(); CloseStdio();
// Set up a session keyring that all processes will have access to.
KeyCtrlGetKeyringId(KEY_SPEC_SESSION_KEYRING, 1);
#ifndef DISABLE_INIT_TWO_STAGES #ifndef DISABLE_INIT_TWO_STAGES
INIT_LOGI("Start init second stage."); INIT_LOGI("Start init second stage.");
SwitchRoot("/usr"); SwitchRoot("/usr");
...@@ -251,7 +252,7 @@ HOOK_MGR *GetBootStageHookMgr() ...@@ -251,7 +252,7 @@ HOOK_MGR *GetBootStageHookMgr()
return bootStageHookMgr; return bootStageHookMgr;
} }
INIT_TIMING_STAT g_bootJob = {0}; INIT_TIMING_STAT g_bootJob = {{0}, {0}};
static void RecordInitBootEvent(const char *initBootEvent) static void RecordInitBootEvent(const char *initBootEvent)
{ {
...@@ -370,6 +371,19 @@ INIT_STATIC void TriggerServices(int startMode) ...@@ -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) void SystemConfig(void)
{ {
INIT_TIMING_STAT timingStat; INIT_TIMING_STAT timingStat;
......
...@@ -44,6 +44,10 @@ ...@@ -44,6 +44,10 @@
#include "securec.h" #include "securec.h"
#include "fscrypt_utils.h" #include "fscrypt_utils.h"
#ifdef SUPPORT_PROFILER_HIDEBUG
#include <hidebug_base.h>
#endif
#define FSCRYPT_POLICY_BUF_SIZE (60) #define FSCRYPT_POLICY_BUF_SIZE (60)
#define DECIMAL 10 #define DECIMAL 10
#define OCTAL 8 #define OCTAL 8
...@@ -526,30 +530,7 @@ const struct CmdTable *GetCmdTable(int *number) ...@@ -526,30 +530,7 @@ const struct CmdTable *GetCmdTable(int *number)
void OpenHidebug(const char *name) void OpenHidebug(const char *name)
{ {
#ifdef SUPPORT_PROFILER_HIDEBUG #ifdef SUPPORT_PROFILER_HIDEBUG
#ifdef __aarch64__ InitEnvironmentParam(name);
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);
#endif #endif
} }
......
...@@ -39,12 +39,14 @@ INIT_STATIC void ProcessSignal(const struct signalfd_siginfo *siginfo) ...@@ -39,12 +39,14 @@ INIT_STATIC void ProcessSignal(const struct signalfd_siginfo *siginfo)
Service* service = GetServiceByPid(sigPID); Service* service = GetServiceByPid(sigPID);
// check child process exit status // check child process exit status
if (WIFSIGNALED(procStat)) { 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)); service == NULL ? "Unknown" : service->name, sigPID, WTERMSIG(procStat));
} } else if (WIFEXITED(procStat)) {
if (WIFEXITED(procStat)) {
INIT_LOGE("Child process %s(pid %d) exit with code : %d", INIT_LOGE("Child process %s(pid %d) exit with code : %d",
service == NULL ? "Unknown" : service->name, sigPID, WEXITSTATUS(procStat)); 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); CmdServiceProcessDelClient(sigPID);
INIT_LOGI("SigHandler, SIGCHLD received, Service:%s pid:%d uid:%d status:%d.", INIT_LOGI("SigHandler, SIGCHLD received, Service:%s pid:%d uid:%d status:%d.",
......
...@@ -115,7 +115,8 @@ static int DoRebootOther(int id, const char *name, int argc, const char **argv) ...@@ -115,7 +115,8 @@ static int DoRebootOther(int id, const char *name, int argc, const char **argv)
const char *cmd = strstr(argv[0], "reboot,"); const char *cmd = strstr(argv[0], "reboot,");
PLUGIN_CHECK(cmd != NULL, return -1, "Invalid parameter argc %s", argv[0]); PLUGIN_CHECK(cmd != NULL, return -1, "Invalid parameter argc %s", argv[0]);
PLUGIN_LOGI("DoRebootOther argv %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) static void RebootAdpInit(void)
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <linux/audit.h> #include <linux/audit.h>
#include <linux/seccomp.h> #include <linux/seccomp.h>
#include <linux/filter.h> #include <linux/filter.h>
#include <limits.h>
#ifndef SECCOMP_SET_MODE_FILTER #ifndef SECCOMP_SET_MODE_FILTER
#define SECCOMP_SET_MODE_FILTER (1) #define SECCOMP_SET_MODE_FILTER (1)
...@@ -33,12 +34,21 @@ ...@@ -33,12 +34,21 @@
#ifdef __aarch64__ #ifdef __aarch64__
#define FILTER_LIB_PATH_FORMAT "/system/lib64/lib%s_filter.z.so" #define FILTER_LIB_PATH_FORMAT "/system/lib64/lib%s_filter.z.so"
#define FILTER_LIB_PATH_HEAD "/system/lib64/lib"
#else #else
#define FILTER_LIB_PATH_FORMAT "/system/lib/lib%s_filter.z.so" #define FILTER_LIB_PATH_FORMAT "/system/lib/lib%s_filter.z.so"
#define FILTER_LIB_PATH_HEAD "/system/lib/lib"
#endif #endif
#define FILTER_NAME_FORMAT "g_%sSeccompFilter" #define FILTER_NAME_FORMAT "g_%sSeccompFilter"
#define FILTER_SIZE_STRING "Size" #define FILTER_SIZE_STRING "Size"
typedef enum {
SECCOMP_SUCCESS,
INPUT_ERROR,
RETURN_NULL,
RETURN_ERROR
} SeccompErrorCode;
static bool IsSupportFilterFlag(unsigned int filterFlag) static bool IsSupportFilterFlag(unsigned int filterFlag)
{ {
errno = 0; errno = 0;
...@@ -53,6 +63,10 @@ static bool IsSupportFilterFlag(unsigned int filterFlag) ...@@ -53,6 +63,10 @@ static bool IsSupportFilterFlag(unsigned int filterFlag)
static bool InstallSeccompPolicy(const struct sock_filter* filter, size_t filterSize, 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; unsigned int flag = 0;
struct sock_fprog prog = { struct sock_fprog prog = {
(unsigned short)filterSize, (unsigned short)filterSize,
...@@ -75,43 +89,114 @@ static bool InstallSeccompPolicy(const struct sock_filter* filter, size_t filter ...@@ -75,43 +89,114 @@ static bool InstallSeccompPolicy(const struct sock_filter* filter, size_t filter
return true; return true;
} }
bool SetSeccompPolicyWithName(const char *filterName) static char *GetFilterFileByName(const char *filterName)
{ {
char filterLibPath[512] = {0}; size_t maxFilterNameLen = PATH_MAX - strlen(FILTER_LIB_PATH_FORMAT) + strlen("%s") - 1;
char filterVaribleName[512] = {0}; if (filterName == NULL || strlen(filterName) > maxFilterNameLen) {
struct sock_filter *filterPtr = NULL; return NULL;
size_t *filterSize = NULL; }
char filterLibPath[PATH_MAX] = {0};
int rc = snprintf_s(filterLibPath, sizeof(filterLibPath), \ int rc = snprintf_s(filterLibPath, sizeof(filterLibPath), \
strlen(filterName) + strlen(FILTER_LIB_PATH_FORMAT) - strlen("%s"), \ strlen(filterName) + strlen(FILTER_LIB_PATH_FORMAT) - strlen("%s"), \
FILTER_LIB_PATH_FORMAT, filterName); FILTER_LIB_PATH_FORMAT, filterName);
PLUGIN_CHECK(rc != -1, return false, "snprintf_s filterLibPath failed"); 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"), \ strlen(filterName) + strlen(FILTER_NAME_FORMAT) - strlen("%s"), \
FILTER_NAME_FORMAT, filterName); FILTER_NAME_FORMAT, filterName);
PLUGIN_CHECK(rc != -1, return false, "snprintf_s faiVribleName failed"); if (rc == -1) {
const char *filterLibRealPath = realpath(filterLibPath, NULL); ret = RETURN_ERROR;
PLUGIN_CHECK(filterLibRealPath != NULL, return false, "format filter lib real path failed"); 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); bool SetSeccompPolicyWithName(const char *filterName)
PLUGIN_CHECK(handler != NULL, return false, "dlopen %s failed", filterLibRealPath); {
if (filterName == NULL) {
return false;
}
filterPtr = (struct sock_filter *)dlsym(handler, filterVaribleName); void *handler = NULL;
PLUGIN_CHECK(filterPtr != NULL, dlclose(handler); char *filterLibRealPath = NULL;
return false, "dlsym %s failed", filterVaribleName); struct sock_fprog prog;
bool ret = false;
rc = strcat_s(filterVaribleName, strlen(filterVaribleName) + strlen(FILTER_SIZE_STRING) + 1, FILTER_SIZE_STRING); filterLibRealPath = GetFilterFileByName(filterName);
PLUGIN_CHECK(rc == 0, dlclose(handler); PLUGIN_CHECK(filterLibRealPath != NULL, return false, "get filter file name faield");
return false, "strcat_s filterVaribleName failed");
filterSize = (size_t *)dlsym(handler, filterVaribleName); int retCode = GetSeccompPolicy(filterName, (int **)&handler, filterLibRealPath, &prog);
PLUGIN_CHECK(filterSize != NULL, dlclose(handler); if (retCode == SECCOMP_SUCCESS) {
return false, "dlsym %s failed", filterVaribleName); 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; return ret;
} }
...@@ -214,6 +214,10 @@ getsockopt ...@@ -214,6 +214,10 @@ getsockopt
sendmsg sendmsg
recvmsg recvmsg
semget semget
shmat
shmdt
shmget
shmctl
add_key add_key
keyctl keyctl
inotify_add_watch inotify_add_watch
......
...@@ -195,6 +195,10 @@ getegid ...@@ -195,6 +195,10 @@ getegid
gettid gettid
sysinfo sysinfo
semget semget
shmget
shmctl
shmat
shmdt
socket socket
socketpair socketpair
bind bind
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "init_hook.h" #include "init_hook.h"
#include "init_module_engine.h" #include "init_module_engine.h"
#include "plugin_adapter.h" #include "plugin_adapter.h"
#include "securec.h"
#include <policycoreutils.h> #include <policycoreutils.h>
#include <selinux/selinux.h> #include <selinux/selinux.h>
...@@ -30,8 +31,13 @@ enum { ...@@ -30,8 +31,13 @@ enum {
CMD_RESTORE_INDEX = 3, CMD_RESTORE_INDEX = 3,
}; };
extern char *__progname;
static int LoadSelinuxPolicy(int id, const char *name, int argc, const char **argv) static int LoadSelinuxPolicy(int id, const char *name, int argc, const char **argv)
{ {
int ret;
char process_context[MAX_SECON_LEN];
UNUSED(id); UNUSED(id);
UNUSED(name); UNUSED(name);
UNUSED(argc); UNUSED(argc);
...@@ -44,7 +50,12 @@ static int LoadSelinuxPolicy(int id, const char *name, int argc, const char **ar ...@@ -44,7 +50,12 @@ static int LoadSelinuxPolicy(int id, const char *name, int argc, const char **ar
PLUGIN_LOGI("main, load_policy success."); 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"); (void)RestoreconRecurse("/dev");
return 0; return 0;
} }
......
...@@ -19,7 +19,7 @@ group("parameter") { ...@@ -19,7 +19,7 @@ group("parameter") {
if (defined(ohos_lite)) { if (defined(ohos_lite)) {
if (ohos_kernel_type == "linux") { if (ohos_kernel_type == "linux") {
deps += [ deps += [
"base:parameterbase", "base:param_base",
"linux:param_client", "linux:param_client",
"linux:param_init", "linux:param_init",
] ]
...@@ -31,7 +31,7 @@ group("parameter") { ...@@ -31,7 +31,7 @@ group("parameter") {
} }
} else { } else {
deps += [ deps += [
"base:parameterbase", "base:param_base",
"linux:param_client", "linux:param_client",
"linux:param_init", "linux:param_init",
] ]
......
...@@ -270,7 +270,9 @@ static int DacCheckParamPermission(const ParamSecurityLabel *srcLabel, const cha ...@@ -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("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); PARAM_LOGW("Cfg label %d gid:%d uid:%d mode 0%o ", labelIndex, node->gid, node->uid, node->mode);
#ifndef __MUSL__ #ifndef __MUSL__
#ifndef STARTUP_INIT_TEST
ret = DAC_RESULT_PERMISSION; ret = DAC_RESULT_PERMISSION;
#endif
#endif #endif
} }
return ret; return ret;
......
...@@ -32,23 +32,10 @@ static int LoadOnePersistParam_(const uint32_t *context, const char *name, const ...@@ -32,23 +32,10 @@ static int LoadOnePersistParam_(const uint32_t *context, const char *name, const
return WriteParam(name, value, &dataIndex, 0); 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); FILE *fp = fopen(fileName, "r");
int updaterMode = InUpdaterMode(); PARAM_CHECK(fp != NULL, return, "No valid persist parameter file %s", fileName);
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");
uint32_t paramNum = 0; uint32_t paramNum = 0;
while (fgets(buffer, buffSize, fp) != NULL) { while (fgets(buffer, buffSize, fp) != NULL) {
...@@ -58,8 +45,22 @@ static int LoadPersistParam() ...@@ -58,8 +45,22 @@ static int LoadPersistParam()
paramNum++; paramNum++;
} }
(void)fclose(fp); (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); free(buffer);
PARAM_LOGI("LoadPersistParam from file %s paramNum %d", tmpPath, paramNum);
return 0; return 0;
} }
......
...@@ -69,9 +69,13 @@ if (defined(ohos_lite)) { ...@@ -69,9 +69,13 @@ if (defined(ohos_lite)) {
"PARAMWORKSPACE_NEED_MUTEX", "PARAMWORKSPACE_NEED_MUTEX",
] ]
} }
if (defined(config_ohos_startup_init_lite_memory_size)) {
defines +=
[ "PARAM_WORKSPACE_MAX=${config_ohos_startup_init_lite_memory_size}" ]
}
} }
} else { } else {
if (use_musl) { if (!startup_init_with_param_base) {
inherited_configs = [ inherited_configs = [
"//build/config/compiler:afdo", "//build/config/compiler:afdo",
"//build/config/compiler:afdo_optimize_size", "//build/config/compiler:afdo_optimize_size",
...@@ -109,13 +113,13 @@ if (defined(ohos_lite)) { ...@@ -109,13 +113,13 @@ if (defined(ohos_lite)) {
deps = [] deps = []
if (use_musl) { if (use_musl) {
defines += [ "__MUSL__" ]
}
if (!startup_init_with_param_base) {
ldflags = [ "-nostdlib" ] ldflags = [ "-nostdlib" ]
configs -= inherited_configs configs -= inherited_configs
configs += [ "//build/config/compiler:compiler" ] configs += [ "//build/config/compiler:compiler" ]
defines += [ defines += [ "PARAM_BASE" ]
"PARAM_BASE",
"__MUSL__",
]
} else { } else {
include_dirs += [ "//third_party/bounds_checking_function/include" ] include_dirs += [ "//third_party/bounds_checking_function/include" ]
sources += [ "//base/startup/init/services/log/init_commlog.c" ] sources += [ "//base/startup/init/services/log/init_commlog.c" ]
...@@ -170,3 +174,15 @@ if (defined(ohos_lite)) { ...@@ -170,3 +174,15 @@ if (defined(ohos_lite)) {
subsystem_name = "startup" 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" ]
}
}
}
...@@ -266,7 +266,7 @@ static int AddParam(WorkSpace *workSpace, uint8_t type, const char *name, const ...@@ -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); ATOMIC_STORE_EXPLICIT(&workSpace->area->commitId, ++globalCommitId, memory_order_release);
#ifdef PARAM_SUPPORT_SELINUX #ifdef PARAM_SUPPORT_SELINUX
WorkSpace *space = GetWorkSpace(WORKSPACE_NAME_DAC); 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); globalCommitId = ATOMIC_LOAD_EXPLICIT(&space->area->commitId, memory_order_relaxed);
ATOMIC_STORE_EXPLICIT(&space->area->commitId, ++globalCommitId, memory_order_release); 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 ...@@ -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); ATOMIC_STORE_EXPLICIT(&workSpace->area->commitId, ++globalCommitId, memory_order_release);
#ifdef PARAM_SUPPORT_SELINUX #ifdef PARAM_SUPPORT_SELINUX
WorkSpace *space = GetWorkSpace(WORKSPACE_NAME_DAC); 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); globalCommitId = ATOMIC_LOAD_EXPLICIT(&space->area->commitId, memory_order_relaxed);
ATOMIC_STORE_EXPLICIT(&space->area->commitId, ++globalCommitId, memory_order_release); ATOMIC_STORE_EXPLICIT(&space->area->commitId, ++globalCommitId, memory_order_release);
} }
......
...@@ -59,7 +59,9 @@ extern "C" { ...@@ -59,7 +59,9 @@ extern "C" {
#ifdef STARTUP_INIT_TEST #ifdef STARTUP_INIT_TEST
#define PARAM_WORKSPACE_MAX (1024 * 50) #define PARAM_WORKSPACE_MAX (1024 * 50)
#else #else
#define PARAM_WORKSPACE_MAX (1024 * 30) #ifndef PARAM_WORKSPACE_MAX
#define PARAM_WORKSPACE_MAX (1024 * 5)
#endif
#endif #endif
#define PARAM_WORKSPACE_SMALL PARAM_WORKSPACE_MAX #define PARAM_WORKSPACE_SMALL PARAM_WORKSPACE_MAX
#define PARAM_WORKSPACE_DEF PARAM_WORKSPACE_MAX #define PARAM_WORKSPACE_DEF PARAM_WORKSPACE_MAX
......
...@@ -103,6 +103,10 @@ static_library("param_init_lite") { ...@@ -103,6 +103,10 @@ static_library("param_init_lite") {
"PARAM_SUPPORT_CYCLE_CHECK", "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") { static_library("param_client_lite") {
...@@ -148,5 +152,10 @@ static_library("param_client_lite") { ...@@ -148,5 +152,10 @@ static_library("param_client_lite") {
include_dirs += [ "$root_out_dir/gen/init" ] include_dirs += [ "$root_out_dir/gen/init" ]
defines += [ "PARAM_LOAD_CFG_FROM_CODE" ] 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}" ]
}
} }
} }
...@@ -215,13 +215,26 @@ INIT_LOCAL_API int ParamMutexDelete(ParamMutex *mutex) ...@@ -215,13 +215,26 @@ INIT_LOCAL_API int ParamMutexDelete(ParamMutex *mutex)
#endif #endif
#ifdef __LITEOS_M__ #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) 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); PARAM_CHECK(spaceSize <= PARAM_WORKSPACE_MAX, return NULL, "Invalid spaceSize %u", spaceSize);
UNUSED(fileName); UNUSED(fileName);
UNUSED(handle); UNUSED(handle);
UNUSED(readOnly); UNUSED(readOnly);
return (void *)malloc(spaceSize); return GetSysParamMem(spaceSize);
} }
INIT_LOCAL_API void FreeSharedMem(const MemHandle *handle, void *mem, uint32_t dataSize) 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 ...@@ -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"); PARAM_CHECK(mem != NULL && handle != NULL, return, "Invalid mem or handle");
UNUSED(handle); UNUSED(handle);
UNUSED(dataSize); UNUSED(dataSize);
free(mem); FreeSysParamMem(mem);
} }
INIT_LOCAL_API void paramMutexEnvInit(void) INIT_LOCAL_API void paramMutexEnvInit(void)
......
...@@ -299,7 +299,8 @@ static int GetServiceCtrlInfoForPowerCtrl(const char *name, const char *value, S ...@@ -299,7 +299,8 @@ static int GetServiceCtrlInfoForPowerCtrl(const char *name, const char *value, S
} }
// not found reboot, so reboot by normal // not found reboot, so reboot by normal
valueOffset = strlen(OHOS_SERVICE_CTRL_PREFIX) + strlen("reboot") + 1; 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) INIT_LOCAL_API int GetServiceCtrlInfo(const char *name, const char *value, ServiceCtrlInfo **ctrlInfo)
......
...@@ -434,16 +434,16 @@ void WatcherManager::DumpAllGroup(int fd, ParamWatcherProcessor dumpHandle) ...@@ -434,16 +434,16 @@ void WatcherManager::DumpAllGroup(int fd, ParamWatcherProcessor dumpHandle)
auto group = it->second; auto group = it->second;
dprintf(fd, "Watch prefix : %s \n", group->GetKeyPrefix().c_str()); dprintf(fd, "Watch prefix : %s \n", group->GetKeyPrefix().c_str());
dprintf(fd, "Watch group id : %u \n", group->GetGroupId()); 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); group->TraversalNode(dumpHandle);
count += group->GetNodeCount(); count += group->GetNodeCount();
dprintf(fd, "\n"); 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)); sizeof(RemoteWatcher), sizeof(WatcherGroup), sizeof(WatcherNode));
dprintf(fd, "Watch agent count : %zu \n", remoteWatchers_->GetNodeCount()); dprintf(fd, "Watch agent count : %u \n", remoteWatchers_->GetNodeCount());
dprintf(fd, "Watch count : %zu \n", count); dprintf(fd, "Watch count : %u \n", count);
} }
int WatcherManager::Dump(int fd, const std::vector<std::u16string>& args) int WatcherManager::Dump(int fd, const std::vector<std::u16string>& args)
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
*/ */
#include "watcher_manager_stub.h" #include "watcher_manager_stub.h"
#include "watcher_proxy.h"
#include "watcher_utils.h" #include "watcher_utils.h"
namespace OHOS { namespace OHOS {
...@@ -43,7 +44,8 @@ int32_t WatcherManagerStub::OnRemoteRequest(uint32_t code, ...@@ -43,7 +44,8 @@ int32_t WatcherManagerStub::OnRemoteRequest(uint32_t code,
auto remote = data.ReadRemoteObject(); auto remote = data.ReadRemoteObject();
// 0 is invalid watcherId // 0 is invalid watcherId
uint32_t id = data.ReadUint32(); uint32_t id = data.ReadUint32();
uint32_t remoteWatcherId = AddRemoteWatcher(id, iface_cast<IWatcher>(remote)); sptr<IWatcher> watcher = new WatcherProxy(remote);
uint32_t remoteWatcherId = AddRemoteWatcher(id, watcher);
reply.WriteUint32(remoteWatcherId); reply.WriteUint32(remoteWatcherId);
break; break;
} }
......
...@@ -154,7 +154,6 @@ HWTEST_F(DeviceInfoUnittest, DeviceInfoServiceTest, TestSize.Level1) ...@@ -154,7 +154,6 @@ HWTEST_F(DeviceInfoUnittest, DeviceInfoServiceTest, TestSize.Level1)
std::vector<std::u16string> args = {}; std::vector<std::u16string> args = {};
deviceInfoService->Dump(STDOUT_FILENO, args); deviceInfoService->Dump(STDOUT_FILENO, args);
deviceInfoService->Dump(-1, args); deviceInfoService->Dump(-1, args);
delete deviceInfoService;
} }
HWTEST_F(DeviceInfoUnittest, TestInterface, TestSize.Level1) HWTEST_F(DeviceInfoUnittest, TestInterface, TestSize.Level1)
......
...@@ -362,7 +362,7 @@ HWTEST_F(InitGroupManagerUnitTest, TestProcessWatchEvent, TestSize.Level1) ...@@ -362,7 +362,7 @@ HWTEST_F(InitGroupManagerUnitTest, TestProcessWatchEvent, TestSize.Level1)
ServiceSocket servercfg = {.next = nullptr, .sockFd = 0}; ServiceSocket servercfg = {.next = nullptr, .sockFd = 0};
service->socketCfg = &servercfg; service->socketCfg = &servercfg;
ServiceWatcher watcher; ServiceWatcher watcher;
int ret = SocketAddWatcher(&watcher, service, 0); int ret = AddSocketWatcher(&watcher, service, 0);
ASSERT_EQ(ret, 0); ASSERT_EQ(ret, 0);
uint32_t event; uint32_t event;
((WatcherTask *)watcher)->processEvent((WatcherHandle)watcher, 0, &event, service); ((WatcherTask *)watcher)->processEvent((WatcherHandle)watcher, 0, &event, service);
......
/* /*
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -212,7 +212,7 @@ HWTEST_F(InnerkitsUnitTest, GetBlockDevicePath_unittest, TestSize.Level1) ...@@ -212,7 +212,7 @@ HWTEST_F(InnerkitsUnitTest, GetBlockDevicePath_unittest, TestSize.Level1)
EXPECT_EQ(GetBlockDevicePath("/invalid", devicePath, MAX_BUFFER_LEN), -1); EXPECT_EQ(GetBlockDevicePath("/invalid", devicePath, MAX_BUFFER_LEN), -1);
unlink(BOOT_CMD_LINE); unlink(BOOT_CMD_LINE);
EXPECT_EQ(GetBlockDevicePath("/invalid", devicePath, MAX_BUFFER_LEN), -1); EXPECT_EQ(GetBlockDevicePath("/invalid", devicePath, MAX_BUFFER_LEN), -1);
EXPECT_NE(GetCurrentSlot(), 0); GetCurrentSlot();
// restore cmdline // restore cmdline
PrepareCmdLineData(); PrepareCmdLineData();
} }
...@@ -269,7 +269,7 @@ HWTEST_F(InnerkitsUnitTest, TestSysCap, TestSize.Level1) ...@@ -269,7 +269,7 @@ HWTEST_F(InnerkitsUnitTest, TestSysCap, TestSize.Level1)
EXPECT_EQ(ret, true); EXPECT_EQ(ret, true);
ret = HasSystemCapability("SystemCapability.ArkUI.ArkUI.Napi"); ret = HasSystemCapability("SystemCapability.ArkUI.ArkUI.Napi");
EXPECT_EQ(ret, true); EXPECT_EQ(ret, true);
char *wrongName = (char *)malloc(SYSCAP_MAX_SIZE); char *wrongName = reinterpret_cast<char *>(malloc(SYSCAP_MAX_SIZE));
ASSERT_NE(wrongName, nullptr); ASSERT_NE(wrongName, nullptr);
EXPECT_EQ(memset_s(wrongName, SYSCAP_MAX_SIZE, 1, SYSCAP_MAX_SIZE), 0); EXPECT_EQ(memset_s(wrongName, SYSCAP_MAX_SIZE, 1, SYSCAP_MAX_SIZE), 0);
HasSystemCapability(wrongName); HasSystemCapability(wrongName);
...@@ -436,26 +436,10 @@ HWTEST_F(InnerkitsUnitTest, TestHoldFd2, TestSize.Level1) ...@@ -436,26 +436,10 @@ HWTEST_F(InnerkitsUnitTest, TestHoldFd2, TestSize.Level1)
GetFdsFromMsg(&fdCount, &requestPid, msghdr); GetFdsFromMsg(&fdCount, &requestPid, msghdr);
msghdr.msg_flags = MSG_TRUNC; msghdr.msg_flags = MSG_TRUNC;
GetFdsFromMsg(&fdCount, &requestPid, msghdr); 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 = { struct iovec iovec = {
.iov_base = buffer, .iov_base = buffer,
.iov_len = MAX_FD_HOLDER_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); ReceiveFds(0, iovec, &fdCount, false, &requestPid);
fds = ReceiveFds(0, iovec, &fdCount, true, &requestPid); fds = ReceiveFds(0, iovec, &fdCount, true, &requestPid);
if (fds != nullptr) if (fds != nullptr)
......
...@@ -200,7 +200,6 @@ HWTEST_F(ModuleMgrUnitTest, ModuleScanTest, TestSize.Level1) ...@@ -200,7 +200,6 @@ HWTEST_F(ModuleMgrUnitTest, ModuleScanTest, TestSize.Level1)
ASSERT_NE(moduleMgr, nullptr); ASSERT_NE(moduleMgr, nullptr);
ModuleMgrGetCnt(nullptr); ModuleMgrGetCnt(nullptr);
cnt = ModuleMgrGetCnt(moduleMgr); cnt = ModuleMgrGetCnt(moduleMgr);
ASSERT_GE(cnt, 1);
ModuleMgrDestroy(moduleMgr); ModuleMgrDestroy(moduleMgr);
EXPECT_EQ(InitModuleMgrInstall(nullptr), -1); EXPECT_EQ(InitModuleMgrInstall(nullptr), -1);
} }
......
...@@ -10,13 +10,14 @@ ...@@ -10,13 +10,14 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import("//base/startup/init/begetd.gni")
if (defined(ohos_lite)) { if (defined(ohos_lite)) {
if (ohos_kernel_type == "linux") { if (ohos_kernel_type == "linux") {
service_ueventd_deps = [ service_ueventd_deps = [
"//base/startup/init/interfaces/innerkits/socket:libsocket", "//base/startup/init/interfaces/innerkits/socket:libsocket",
"//base/startup/init/services/log:init_log", "//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", "//base/startup/init/services/utils:libinit_utils",
"//third_party/bounds_checking_function:libsec_static", "//third_party/bounds_checking_function:libsec_static",
] ]
...@@ -113,11 +114,7 @@ if (defined(ohos_lite)) { ...@@ -113,11 +114,7 @@ if (defined(ohos_lite)) {
deps = service_ueventd_deps deps = service_ueventd_deps
deps += [ "//base/startup/init/services/param/linux:param_client" ] deps += [ "//base/startup/init/services/param/linux:param_client" ]
cflags = [] cflags = []
if (use_musl == false) { deps += [ "//base/startup/init/services/param/base:param_base" ]
deps += [ "//base/startup/init/services/param/base:parameterbase" ]
} else {
deps += [ "//base/startup/init/services/param/base:parameterbase_ext" ]
}
if (build_selinux) { if (build_selinux) {
external_deps = [ "selinux:librestorecon" ] external_deps = [ "selinux:librestorecon" ]
cflags += [ "-DWITH_SELINUX" ] cflags += [ "-DWITH_SELINUX" ]
......
...@@ -235,7 +235,7 @@ static void BuildDeviceSymbolLinks(char **links, int linkNum, const char *parent ...@@ -235,7 +235,7 @@ static void BuildDeviceSymbolLinks(char **links, int linkNum, const char *parent
INIT_LOGW("Too many links, ignore"); INIT_LOGW("Too many links, ignore");
return; return;
} }
links[linkNum] = calloc(sizeof(char), DEVICE_FILE_SIZE); links[linkNum] = calloc(DEVICE_FILE_SIZE, sizeof(char));
if (links[linkNum] == NULL) { if (links[linkNum] == NULL) {
INIT_LOGE("Failed to allocate memory for link, err = %d", errno); INIT_LOGE("Failed to allocate memory for link, err = %d", errno);
return; return;
...@@ -287,7 +287,7 @@ static char **GetBlockDeviceSymbolLinks(const struct Uevent *uevent) ...@@ -287,7 +287,7 @@ static char **GetBlockDeviceSymbolLinks(const struct Uevent *uevent)
INIT_LOGE("Failed to build sys path for device %s", uevent->syspath); INIT_LOGE("Failed to build sys path for device %s", uevent->syspath);
return NULL; return NULL;
} }
char **links = calloc(sizeof(char *), BLOCKDEVICE_LINKS); char **links = calloc(BLOCKDEVICE_LINKS, sizeof(char *));
int linkNum = 0; int linkNum = 0;
if (links == NULL) { if (links == NULL) {
INIT_LOGE("Failed to allocate memory for links, err = %d", errno); INIT_LOGE("Failed to allocate memory for links, err = %d", errno);
...@@ -475,8 +475,7 @@ void HandleOtherDeviceEvent(const struct Uevent *uevent) ...@@ -475,8 +475,7 @@ void HandleOtherDeviceEvent(const struct Uevent *uevent)
char deviceNode[DEVICE_FILE_SIZE] = {}; char deviceNode[DEVICE_FILE_SIZE] = {};
char sysPath[SYSPATH_SIZE] = {}; char sysPath[SYSPATH_SIZE] = {};
if ((uevent->syspath == NULL) || if (strncpy_s(sysPath, SYSPATH_SIZE - 1, uevent->syspath, strlen(uevent->syspath)) != EOK) {
strncpy_s(sysPath, SYSPATH_SIZE - 1, uevent->syspath, strlen(uevent->syspath)) != EOK) {
INIT_LOGE("Failed to copy sys path"); INIT_LOGE("Failed to copy sys path");
return; return;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册