diff --git a/interfaces/innerkits/fs_manager/fstab_mount.c b/interfaces/innerkits/fs_manager/fstab_mount.c index 86aca2475f308a6e484752ad8521d92ad24cedb7..078c1817d1f2603c68951dde3e825e4fbabf180c 100755 --- a/interfaces/innerkits/fs_manager/fstab_mount.c +++ b/interfaces/innerkits/fs_manager/fstab_mount.c @@ -69,12 +69,6 @@ __attribute__((weak)) bool NeedDoAllResize(const unsigned int fsManagerFlags) return true; } -__attribute__((weak)) char *GetExtraFsckOption(void) -{ - BEGET_LOGW("get extra fsck option: static"); - return NULL; -} - static const SUPPORTED_FILE_SYSTEM supportedFileSystems[] = { { "ext4", 0 }, { "f2fs", 1 }, @@ -345,22 +339,16 @@ static int DoResizeF2fs(FstabItem *item, const unsigned long long size) return ExecCommand(argc, argv); } -#define MAX_FSCK_PARAM_NUM 5 static int DoFsckF2fs(const char* device) { char *file = "/system/bin/fsck.f2fs"; BEGET_ERROR_CHECK(access(file, F_OK) == 0, return -1, "fsck.f2fs is not exists."); - char *argv[MAX_FSCK_PARAM_NUM] = {NULL}; - int argc = 0; - - argv[argc++] = file; - argv[argc++] = "-p1"; - char *extraOpt = GetExtraFsckOption(); - if (extraOpt) { - argv[argc++] = extraOpt; - } - argv[argc++] = (char *)device; + char *cmd[] = { + file, "-p1", (char *)device, NULL + }; + int argc = ARRAY_LENGTH(cmd); + char **argv = (char **)cmd; InitTimerControl(true); int ret = ExecCommand(argc, argv); InitTimerControl(false); @@ -413,7 +401,7 @@ static int Mount(const char *source, const char *target, const char *fsType, unsigned long flags, const char *data) { struct stat st = {}; - int rc = 0; + int rc = -1; bool isTrue = source == NULL || target == NULL || fsType == NULL; BEGET_ERROR_CHECK(!isTrue, return -1, "Invalid argument for mount."); @@ -427,8 +415,7 @@ static int Mount(const char *source, const char *target, const char *fsType, BEGET_ERROR_CHECK(errno == EEXIST, return -1, "Failed to create dir \" %s \", err = %d", target, errno); } errno = 0; - if (mount(source, target, fsType, flags, data) != 0) { - rc = errno; + if ((rc = mount(source, target, fsType, flags, data)) != 0) { BEGET_WARNING_CHECK(errno != EBUSY, rc = 0, "Mount %s to %s busy, ignore", source, target); } return rc; diff --git a/interfaces/innerkits/syspara/param_comm.c b/interfaces/innerkits/syspara/param_comm.c index 017708a69bba7492d52b44972d01951db85ae896..8591bc8d5d7cfffac4c761fee3ad45ba5ed94537 100644 --- a/interfaces/innerkits/syspara/param_comm.c +++ b/interfaces/innerkits/syspara/param_comm.c @@ -77,7 +77,7 @@ INIT_LOCAL_API int GetParameter_(const char *key, const char *def, char *value, if (def == NULL) { return GetSystemError(ret); } - if (strlen(def) >= len) { + if (strlen(def) > len) { return EC_INVALID; } ret = strcpy_s(value, len, def); @@ -118,6 +118,41 @@ INIT_LOCAL_API const char *GetProperty(const char *key, const char **paramHolder return *paramHolder; } +#ifndef OHOS_LITE +INIT_LOCAL_API const char *GetPropertyAtomic(const char *key, const char **paramHolder) +{ + BEGET_CHECK(paramHolder != NULL, return NULL); + const char *_Atomic *atomicParam = (const char *_Atomic *)paramHolder; + const char *cached = atomic_load(atomicParam); + if (cached != NULL) { + return cached; + } + + uint32_t len = 0; + int ret = SystemGetParameter(key, NULL, &len); + if (ret == 0 && len > 0) { + char *res = (char *)calloc(1, len + 1); + BEGET_CHECK(res != NULL, return NULL); + + ret = SystemGetParameter(key, res, &len); + if (ret != 0) { + free(res); + return NULL; + } + + if (g_propertyGetProcessor != NULL) { + res = g_propertyGetProcessor(key, res); + } + + const char *expected = NULL; + if (!atomic_compare_exchange_strong(atomicParam, &expected, res)) { + free(res); + } + } + return atomic_load(atomicParam); +} +#endif + INIT_LOCAL_API PropertyValueProcessor SetPropertyGetProcessor(PropertyValueProcessor processor) { PropertyValueProcessor prev = g_propertyGetProcessor; diff --git a/interfaces/innerkits/syspara/param_comm.h b/interfaces/innerkits/syspara/param_comm.h index 2a7b033bf5385cfcc4e22226fe45f08ba3899bbe..305bf78dc8c3c64002c39eaa974c2d3ba9a732e9 100755 --- a/interfaces/innerkits/syspara/param_comm.h +++ b/interfaces/innerkits/syspara/param_comm.h @@ -16,6 +16,7 @@ #ifndef INIT_PARAM_COMM_H #define INIT_PARAM_COMM_H #include +#include #include "beget_ext.h" #ifdef __cplusplus @@ -35,6 +36,9 @@ extern "C" { typedef char *(*PropertyValueProcessor)(const char *key, char *value); INIT_LOCAL_API const char *GetProperty(const char *key, const char **paramHolder); +#ifndef OHOS_LITE +INIT_LOCAL_API const char *GetPropertyAtomic(const char *key, const char **paramHolder); +#endif INIT_LOCAL_API PropertyValueProcessor SetPropertyGetProcessor(PropertyValueProcessor processor); INIT_LOCAL_API int GetParameter_(const char *key, const char *def, char *value, uint32_t len); diff --git a/interfaces/innerkits/syspara/parameter.c b/interfaces/innerkits/syspara/parameter.c index d4d8da6f1b7fe6bf0d8a5c22f887590f9f33dbbb..e6108cf4a4d26dce240a320ccb5fbf53f4184c2f 100644 --- a/interfaces/innerkits/syspara/parameter.c +++ b/interfaces/innerkits/syspara/parameter.c @@ -17,6 +17,7 @@ #include #include +#include #include "param_comm.h" #include "init_param.h" @@ -108,7 +109,15 @@ int SaveParameters(void) const char *GetDeviceType(void) { static const char *productType = NULL; - const char *deviceType = GetProperty("const.product.devicetype", &productType); + const char *deviceType = NULL; +#ifndef OHOS_LITE + deviceType = GetPropertyAtomic("const.product.devicetype", &productType); + if (deviceType != NULL) { + return deviceType; + } + return GetPropertyAtomic("const.build.characteristics", &productType); +#endif + deviceType = GetProperty("const.product.devicetype", &productType); if (deviceType != NULL) { return deviceType; } diff --git a/remount/include/remount_overlay.h b/remount/include/remount_overlay.h index fedf4a2291e4277f88b1decfc236840f18b770fe..fa77c568b19f7301209c72a92283d801a88c43ed 100644 --- a/remount/include/remount_overlay.h +++ b/remount/include/remount_overlay.h @@ -24,7 +24,7 @@ extern "C" { #endif #endif -int RemountRofsOverlay(); +int RemountRofsOverlay(void); #ifdef __cplusplus #if __cplusplus diff --git a/remount/remount_overlay.c b/remount/remount_overlay.c index ea02c5dbdbf165f98018a7e3f6fe90703953804e..477ded252cc240f33c9d490305b656c72e097c48 100644 --- a/remount/remount_overlay.c +++ b/remount/remount_overlay.c @@ -388,7 +388,7 @@ static void EngFilesOverlay(const char *source, const char *target) dir = NULL; } -int RemountRofsOverlay() +int RemountRofsOverlay(void) { int lastRemountResult = GetRemountResult(); INIT_LOGI("get last remount result is %d.", lastRemountResult); diff --git a/services/etc/appender/file_appender.gni b/services/etc/appender/file_appender.gni index dfed821f0179b7be14257b23d02419cca286d7d3..a588acb7941ec6a8ba7bbd7186063a431b18c49e 100755 --- a/services/etc/appender/file_appender.gni +++ b/services/etc/appender/file_appender.gni @@ -110,7 +110,7 @@ template("ohos_file_appender") { } else { deps = [ ":$_file_appender_target" ] } - set_sources_assignment_filter([]) + #set_sources_assignment_filter([]) sources = [ _appended_file ] outputs = [ "${target_out_dir}/${target_name}/${_final_install_name}" ] module_type = "etc" diff --git a/services/etc/group b/services/etc/group index 9b1ef4a0fb91ec807833b504f4a8f27e3f4d6290..5f00580da576d7bcc0a440d5c43df251b7e02cd7 100644 --- a/services/etc/group +++ b/services/etc/group @@ -53,7 +53,7 @@ ddms:x:3012: access_token:x:3020: blue_host:x:3021: sample_host:x:3022: -usb_host:x:3023:print,cups,audio +usb_host:x:3023: usbfn_host:x:3024: power_host:x:3025: wifi_host:x:3026: @@ -62,14 +62,18 @@ access_control_level_manager:x:3101: audio_host:x:3127: camera_host:x:3028: input_user_host:x:3029: +display_gralloc_host:x:3030: codec_host:x:3031: riladapter_host:x:3032: sensor_host:x:3033: vibrator_host:x:3034: light_host:x:3035: composer_host:x:3036: +disp_gralloc_host:x:3037: dcamera_host:x:3038: daudio_host:x:3059: +hwc_host:x:3039: +gralloc_host:x:3040: allocator_host:x:3041: nfc_host:x:3042: a2dp_host:x:3043: @@ -100,9 +104,8 @@ dlp_permission:x:3019: dms:x:5522: foundation:x:5523: quickfixserver:x:5524: -cast_engine_service:x:5526: -sharing_service:x:5527: powermgr:x:5528: +sharing_service:x:5529: samgr:x:5555: update:x:6666: charger:x:6667: @@ -163,13 +166,12 @@ hdf_ext_devmgr:x:3085: intell_voice_host:x:3100: user_data_r:x:2008: drmserver:x:1077: -clearplay_host:x:3078: wiseplay_host:x:3079: i18n:x:3013: testserver:x:3500: media_db_rw:x:3008: -app_domain_verify:x:3111: compiler_service:x:5300: +app_domain_verify:x:3111: sandbox_manager:x:3076: app_fwk_update:x:3350: sysselection:x:1080: diff --git a/services/etc/param/ohos.para.size b/services/etc/param/ohos.para.size index 73c004e6f38e734847845624a4807c90f1619d2e..dd89bf9f6a94a1b8681f2dcb2c60d55cad75fc1b 100755 --- a/services/etc/param/ohos.para.size +++ b/services/etc/param/ohos.para.size @@ -15,40 +15,27 @@ default_param=4096 hilog_param=40960 const_product_param=4096 startup_param=40960 -persist_param=40960 +persist_param=2097152 const_param=40960 -persist_sys_param=10240 -devinfo_public_param=40960 +persist_sys_param=2097152 +devinfo_public_param=2097152 sys_param=4096 -bootevent_param=4096 -startup_init_param=81920 +bootevent_param=2097152 +startup_init_param=2097152 +aptouch_daemon_param=40960 startup_appspawn_param=3145728 hiviewdfx_profiler_param=4096 -ohos_boot_param = 8192 +ohos_boot_param = 2097152 bluetooth_param = 8192 hiviewdfx_hiview_param = 40960 develop_private_param = 128000 telephony_param = 20480 -const_telephony_param = 4096 -vendor_camera_param=6144 -edm_writable_param = 20480 -arkui_param = 2048 -wireless_hid_accessory_manager_param = 8192 -debug_param = 4096 -sys_usb_param = 4096 -i18n_param = 4096 -media_library_param = 4096 -samgr_perf_param = 4096 -samgr_writable_param = 10240 -ffrt_param = 4096 -developtools_hdc_auth_param = 4096 -time_param = 2048 -arkcompiler_param = 2048 -useriam_fwkready_param = 2048 -custom_param = 4096 -persist_audio_param = 4096 -update_updater_param = 4096 -bms_param = 20480 +const_telephony_param = 6144 +persist_odm_ril_param=16060 +ro_odm_ril_param=20240 +ril_card_param=20480 +ril_card_const_param=2048 +persist_ril_param=40960 #for ril temp ril_gsm_param=20480 @@ -73,4 +60,26 @@ ro_patchversion_param=20480 ro_runmode_param=20480 sys_shutdown_requested_param=20480 const_telephony_slotCount_param=20480 -persist_sys_debug_on_param=20480 \ No newline at end of file +persist_sys_debug_on_param=20480 +vendor_camera_param=6144 +edm_writable_param = 20480 +arkui_param = 2048 +wireless_hid_accessory_manager_param = 8192 +debug_param = 4096 +sys_usb_param = 4096 +i18n_param = 4096 +samgr_perf_param = 4096 +samgr_writable_param = 10240 +ffrt_param = 4096 +media_library_param = 4096 +vendor_bms_prop = 4096 +developtools_hdc_auth_param = 4096 +time_param = 2048 +security_writable_param=2048 +arkcompiler_param = 2048 +useriam_fwkready_param = 2048 +persist_update_param=8192 +custom_param = 4096 +persist_audio_param = 4096 +update_updater_param = 4096 +bms_param = 20480 \ No newline at end of file diff --git a/services/etc/param/ohos_const/ohos.para b/services/etc/param/ohos_const/ohos.para index e133342245d43190014fe7e83d5e1342ccac2ea4..6896912d3773731efc43d75334693f3d93a29102 100755 --- a/services/etc/param/ohos_const/ohos.para +++ b/services/etc/param/ohos_const/ohos.para @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. const.ohos.version.security_patch=2025/08/01 -const.ohos.releasetype=Beta1 +const.ohos.releasetype=Beta2 const.ohos.apiversion=20 const.ohos.apiminorversion=0 const.ohos.apipatchversion=0 diff --git a/services/etc/param/param_fixer.gni b/services/etc/param/param_fixer.gni new file mode 100644 index 0000000000000000000000000000000000000000..9b54665ba57dc10c16597ca1ff148543f14bac86 --- /dev/null +++ b/services/etc/param/param_fixer.gni @@ -0,0 +1,81 @@ +# 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") + +template("ohos_prebuilt_para") { + assert(defined(invoker.source), "source must be defined for ${target_name}.") + + _fixed_param_target = "${target_name}_param_fixed" + _fixed_param_file = target_gen_dir + "/${target_name}.fixed/" + + get_path_info(invoker.source, "file") + + _output_para_file = get_path_info(invoker.source, "file") + action_with_pydeps(_fixed_param_target) { + deps = [] + script = "//base/startup/init/services/etc/param/param_fixer.py" + depfile = "${target_gen_dir}/${target_name}.d" + args = [ + "--output", + rebase_path(_fixed_param_file, root_build_dir), + "--source-file", + rebase_path(invoker.source, root_build_dir), + "--depfile", + rebase_path(depfile, root_build_dir), + ] + if (defined(invoker.extra_paras)) { + foreach(extra, invoker.extra_paras) { + args += [ + "--extra", + extra, + ] + } + } + inputs = [ invoker.source ] + outputs = [ _fixed_param_file ] + } + + ohos_copy(target_name) { + deps = [ ":$_fixed_param_target" ] + 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", + ]) + sources = [ _fixed_param_file ] + outputs = [ "${target_out_dir}/${target_name}/${_output_para_file}" ] + module_type = "etc" + install_enable = true + module_source_dir = "${target_out_dir}/${target_name}" + module_install_name = _output_para_file + if (defined(invoker.install_enable)) { + install_enable = invoker.install_enable + } + } +} diff --git a/services/etc/param/param_fixer.py b/services/etc/param/param_fixer.py new file mode 100644 index 0000000000000000000000000000000000000000..f74fb7c528d627266cfd50d5e910d7a4387eae78 --- /dev/null +++ b/services/etc/param/param_fixer.py @@ -0,0 +1,91 @@ +#!/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 json +import stat + +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 + + +def parse_args(args): + 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('--extra', action="append", type="string", dest="extra", help='extra params') + + options, _ = parser.parse_args(args) + return options + + +def parse_params(line, contents): + line = line.strip() + pos = line.find('=') + if pos <= 0: + return + name = line[:pos] + value = line[pos + 1:] + name = name.strip() + value = value.strip() + contents[name] = value + + +def parse_extra_params(extras, contents): + for extra in extras: + extra = extra.strip() + parse_params(extra, contents) + + +def fix_para_file(options): + contents = {} + + # Read source file + with open(options.source_file, 'r') as f: + lines = f.readlines() + for line in lines: + line = line.strip() + # Strip comments + if line.startswith('#') or not line: + continue + parse_params(line, contents) + + if options.extra: + parse_extra_params(options.extra, contents) + + flags = os.O_WRONLY | os.O_CREAT | os.O_TRUNC + modes = stat.S_IWUSR | stat.S_IRUSR | stat.S_IWGRP | stat.S_IRGRP + with os.fdopen(os.open(options.output, flags, modes), 'w') as f: + for key in contents: + f.write("".join([key, "=", contents[key], '\n'])) + + +def main(args): + options = parse_args(args) + + depfile_deps = ([options.source_file]) + + fix_para_file(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/param/param_fixer.pydeps b/services/etc/param/param_fixer.pydeps new file mode 100644 index 0000000000000000000000000000000000000000..d7bdb5dde1e96798634eb83d840652d65105dffd --- /dev/null +++ b/services/etc/param/param_fixer.pydeps @@ -0,0 +1,9 @@ +# Generated by running: +# build/print_python_deps.py --root base/startup/init_lite/services/etc/param --output base/startup/init_lite/services/etc/param/param_fixer.pydeps base/startup/init_lite/services/etc/param/param_fixer.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 +param_fixer.py diff --git a/services/etc/passwd b/services/etc/passwd index e1d1ef919adfefccb98825d4cce81f912d98f13a..9ef74a33b0368c1dbcb57864514bcf91b68afa76 100644 --- a/services/etc/passwd +++ b/services/etc/passwd @@ -57,14 +57,18 @@ access_control_level_manager:x:3101:3101:::/bin/false audio_host:x:3127:3127:::/bin/false camera_host:x:3028:3028:::/bin/false input_user_host:x:3029:3029:::/bin/false +display_gralloc_host:x:3030:3030:::/bin/false codec_host:x:3031:3031:::/bin/false riladapter_host:x:3032:3032:::/bin/false sensor_host:x:3033:3033:::/bin/false vibrator_host:x:3034:3034:::/bin/false light_host:x:3035:3035:::/bin/false composer_host:x:3036:3036:::/bin/false +disp_gralloc_host:x:3037:3037:::/bin/false dcamera_host:x:3038:3038:::/bin/false daudio_host:x:3059:3059:::/bin/false +hwc_host:x:3039:3039:::/bin/false +gralloc_host:x:3040:3040:::/bin/false allocator_host:x:3041:3041:::/bin/false nfc_host:x:3042:3042:::/bin/false a2dp_host:x:3043:3043:::/bin/false @@ -96,9 +100,8 @@ security_component:x:3050:3050:::/bin/false dms:x:5522:5522:::/bin/false foundation:x:5523:5523:::/bin/false quickfixserver:x:5524:5524:::/bin/false -cast_engine_service:x:5526:5526:::/bin/false -sharing_service:x:5527:5527:::/bin/false powermgr:x:5528:5528:::/bin/false +sharing_service:x:5529:5529:::/bin/false samgr:x:5555:5555:::/bin/false dbms:x:6000:6000:::/bin/false update:x:6666:6666:::/bin/false @@ -157,12 +160,11 @@ el5_filekey_manager:x:3077:3077:::/bin/false hdf_ext_devmgr:x:3085:3085:::/bin/false intell_voice_host:x:3100:3100:::/bin/false drmserver:x:1077:1077:::/bin/false -clearplay_host:x:3078:3078:::/bin/false wiseplay_host:x:3079:3079:::/bin/false i18n:x:3013:3013:::/bin/false testserver:x:3500:3500:::/bin/false -app_domain_verify:x:3111:3111:::/bin/false compiler_service:x:5300:5300:::/bin/false +app_domain_verify:x:3111:3111:::/bin/false sandbox_manager:x:3076:3076:::/bin/false app_fwk_update:x:3350:3350:::/bin/false sysselection:x:1080:1080:::/bin/false diff --git a/services/etc/passwd_appender/passwd_appender.py b/services/etc/passwd_appender/passwd_appender.py index 249da50f67314c28d12c814252527edc0b93f555..e7f76228ed281388a2ed216b2aaecf936d575f6f 100755 --- a/services/etc/passwd_appender/passwd_appender.py +++ b/services/etc/passwd_appender/passwd_appender.py @@ -165,11 +165,8 @@ def append_passwd_files(target_f, options): file_list = options.source_file.split(":") range_list = options.input_ranges.split(":") - for i, file in enumerate(file_list): - if i >= len(range_list): - print("error: %s is error", file) - return - if not load_file(file, range_list[i]): + for file, range_item in zip(file_list, range_list): + if not load_file(file, range_item): # check gid/uid Exception log: raise Exception("Exception, check passwd file error, ", file) print("error: heck passwd file error, file path: ", file) pass diff --git a/services/etc_lite/param/ohos_const/ohos.para b/services/etc_lite/param/ohos_const/ohos.para index c4c8d0a8062696eea1856a46bd276c983d53eeee..08bb40f47659f6500fe5f386077df7e9c6001edc 100755 --- a/services/etc_lite/param/ohos_const/ohos.para +++ b/services/etc_lite/param/ohos_const/ohos.para @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -const.ohos.releasetype=Beta1 +const.ohos.releasetype=Beta2 const.ohos.apiversion=20 const.ohos.apiminorversion=0 const.ohos.apipatchversion=0 diff --git a/services/init/include/init_cmds.h b/services/init/include/init_cmds.h index 474b8aa7bce90bfabd91d3edce42e324f57e3a6c..f8e7523b8f9a0db7db9b2def1324862a05dfaa76 100644 --- a/services/init/include/init_cmds.h +++ b/services/init/include/init_cmds.h @@ -14,6 +14,7 @@ */ #ifndef BASE_STARTUP_INIT_CMDS_H #define BASE_STARTUP_INIT_CMDS_H +#include #include #include #include @@ -109,6 +110,7 @@ void PluginExecCmdByCmdIndex(int index, const char *cmdContent, const ConfigCont const char *PluginGetCmdIndex(const char *cmdStr, int *index); const char *GetPluginCmdNameByIndex(int index); int AddCareContextCmdExecutor(const char *cmdName, CmdExecutor executor); +bool IsOpenDebugInfo(void); #ifdef __cplusplus #if __cplusplus diff --git a/services/init/init_common_cmds.c b/services/init/init_common_cmds.c index f3b475bb7b0dca45ff6c74142db136d774e41935..7cfd0c87fdd69816b9573627bd4da585498047a8 100644 --- a/services/init/init_common_cmds.c +++ b/services/init/init_common_cmds.c @@ -351,12 +351,12 @@ static void DoMkDir(const struct CmdArgs *ctx) INIT_LOGE("DoMkDir invalid arguments."); return; } + INIT_CHECK_ONLY_ELOG(!IsOpenDebugInfo(), "Begin mkdir directory %s", ctx->argv[0]); mode_t mode = DEFAULT_DIR_MODE; if (mkdir(ctx->argv[0], mode) != 0 && errno != EEXIST) { INIT_LOGE("Create directory '%s' failed, err=%d.", ctx->argv[0], errno); return; } - /* * Skip restoring default SELinux security contexts if the the folder already * existed and its under /dev or /data/. These files will be proceed by loadSelinuxPolicy. @@ -364,31 +364,37 @@ static void DoMkDir(const struct CmdArgs *ctx) if ((errno != EEXIST) || ((strncmp(ctx->argv[0], "/dev", strlen("/dev")) != 0) && (strncmp(ctx->argv[0], "/data/", strlen("/data/")) != 0)) || (strncmp(ctx->argv[0], "/data/service/el1", strlen("/data/service/el1")) == 0)) { + INIT_CHECK_ONLY_ELOG(!IsOpenDebugInfo(), "Begin restoreCon directory %s", ctx->argv[0]); PluginExecCmdByName("restoreContentRecurse", ctx->argv[0]); + INIT_CHECK_ONLY_ELOG(!IsOpenDebugInfo(), "Finish restoreCon directory %s", ctx->argv[0]); } if (ctx->argc <= 1) { return; } - + INIT_CHECK_ONLY_ELOG(!IsOpenDebugInfo(), "Begin chmod directory %s", ctx->argv[0]); mode = strtoul(ctx->argv[1], NULL, OCTAL_TYPE); INIT_CHECK_ONLY_ELOG(chmod(ctx->argv[0], mode) == 0, "DoMkDir failed for '%s', err %d.", ctx->argv[0], errno); - + INIT_CHECK_ONLY_ELOG(!IsOpenDebugInfo(), "Finish chmod directory %s", ctx->argv[0]); if (ctx->argc <= ownerPos) { return; } + INIT_CHECK_ONLY_ELOG(!IsOpenDebugInfo(), "Begin SetOwner directory %s", ctx->argv[0]); int ret = SetOwner(ctx->argv[0], ctx->argv[ownerPos], ctx->argv[groupPos]); if (ret != 0) { INIT_LOGE("Failed to change owner %s, err %d.", ctx->argv[0], errno); } + INIT_CHECK_ONLY_ELOG(!IsOpenDebugInfo(), "Begin SetFileCryptPolicy directory %s", ctx->argv[0]); ret = SetFileCryptPolicy(ctx->argv[0]); INIT_CHECK_ONLY_ELOG(ret == 0, "Failed to set file fscrypt, directory: %s", ctx->argv[0]); + INIT_CHECK_ONLY_ELOG(!IsOpenDebugInfo(), "Finish mkdir directory %s", ctx->argv[0]); return; } static void DoChmod(const struct CmdArgs *ctx) { // format: chmod xxxx /xxx/xxx/xxx + INIT_CHECK_ONLY_ELOG(!IsOpenDebugInfo(), "Begin chmod %s", ctx->argv[1]); mode_t mode = strtoul(ctx->argv[0], NULL, OCTAL_TYPE); if (mode == 0) { INIT_LOGE("DoChmod, strtoul failed for %s, er %d.", ctx->argv[1], errno); @@ -398,6 +404,7 @@ static void DoChmod(const struct CmdArgs *ctx) if (chmod(ctx->argv[1], mode) != 0) { INIT_LOGE("Failed to change mode \" %s \" to %04o, err=%d", ctx->argv[1], mode, errno); } + INIT_CHECK_ONLY_ELOG(!IsOpenDebugInfo(), "Begin chmod %s", ctx->argv[1]); } static int GetMountFlag(unsigned long *mountflag, const char *targetStr, const char *source) @@ -586,6 +593,21 @@ static void DoExport(const struct CmdArgs *ctx) return; } +static bool g_openDebugInfo = false; +bool IsOpenDebugInfo(void) +{ + return g_openDebugInfo; +} + +static void VerbosDebugInfo(const struct CmdArgs *ctx) +{ + if (strcmp(ctx->argv[0], "open") == 0) { + g_openDebugInfo = true; + } else { + g_openDebugInfo = false; + } +} + static const struct CmdTable g_cmdTable[] = { { "start ", 0, 1, 0, DoStart }, { "mkdir ", 1, 4, 1, DoMkDir }, @@ -605,7 +627,8 @@ static const struct CmdTable g_cmdTable[] = { { "sleep ", 1, 1, 0, DoSleep }, { "wait ", 1, 2, 1, DoWait }, { "hostname ", 1, 1, 1, DoSetHostname }, - { "domainname ", 1, 1, 1, DoSetDomainname } + { "domainname ", 1, 1, 1, DoSetDomainname }, + { "verbosdebuginfo", 0, 1, 0, VerbosDebugInfo} }; static const struct CmdTable *GetCommCmdTable(int *number) diff --git a/services/init/init_common_service.c b/services/init/init_common_service.c index 83de46a88f940e7356a619dcc6d673279fb7769d..914d7a96ea194470b01f98658f621f6222131c5d 100644 --- a/services/init/init_common_service.c +++ b/services/init/init_common_service.c @@ -686,8 +686,8 @@ int ServiceStart(Service *service, ServiceArgs *pathArgs) if (service->serviceJobs.jobsName[JOB_PRE_START] != NULL) { DoJobNow(service->serviceJobs.jobsName[JOB_PRE_START]); } - struct timespec prefork; - clock_gettime(CLOCK_REALTIME, &prefork); + struct timespec preforkTime; + clock_gettime(CLOCK_REALTIME, &preforkTime); int pid = fork(); if (pid == 0) { RunChildProcess(service, pathArgs); @@ -698,10 +698,11 @@ int ServiceStart(Service *service, ServiceArgs *pathArgs) } struct timespec startedTime; clock_gettime(CLOCK_REALTIME, &startedTime); + INIT_LOGI("ServiceStart started info %s(pid %d uid %d)", service->name, pid, service->servPerm.uID); - INIT_LOGI("starttime:%ld-%ld,preforktime:%ld-%ld,startedtime:%ld-%ld", - startingTime.tv_sec, startingTime.tv_nsec, prefork.tv_sec, - prefork.tv_nsec, startedTime.tv_sec, startedTime.tv_nsec); + INIT_LOGI("starttime:%ld-%ld, prefork:%ld-%ld, startedtime:%ld-%ld", + startingTime.tv_sec, startingTime.tv_nsec, preforkTime.tv_sec, + preforkTime.tv_nsec, startedTime.tv_sec, startedTime.tv_nsec); #ifndef OHOS_LITE if (!IsOnDemandService(service)) { ReportServiceStart(service->name, pid); @@ -772,7 +773,7 @@ int ServiceTerm(Service *service) if (service->fdCount != 0) { CloseServiceFds(service, true); } - + if (IsServiceWithTimerEnabled(service)) { ServiceStopTimer(service); } @@ -844,7 +845,7 @@ static void CheckServiceSocket(Service *service) return; } -static bool IsDebugMode() +static bool IsDebugMode(void) { char secureValue[PARAM_VALUE_LEN_MAX] = {0}; unsigned int secureLen = PARAM_VALUE_LEN_MAX; diff --git a/services/init/init_config.c b/services/init/init_config.c index 7e55861ce160360440c217e322f72d4593a7f64d..05d15a9d16b51e0a2aa6f0e34a1135d77d4b8af6 100644 --- a/services/init/init_config.c +++ b/services/init/init_config.c @@ -18,7 +18,6 @@ #include "init_service_manager.h" #include "init_utils.h" #include "init_param.h" -#include "init_group_manager.h" static void ParseAllImports(const cJSON *root); @@ -108,7 +107,7 @@ void ReadConfig(void) SystemReadParam("ohos.boot.mode", buffer, &len); INIT_LOGI("ohos.boot.mode %s", buffer); int maintenance = InRepairMode(); - if ((strcmp(buffer, "charger_mode") == 0) || (GetBootModeFromMisc() == GROUP_CHARGE)) { + if (strcmp(buffer, "charger_mode") == 0) { ParseInitCfg(INIT_CONFIGURATION_FILE, NULL); ReadFileInDir(OTHER_CHARGE_PATH, ".cfg", ParseInitCfg, NULL); ParseCfgByPriority(INIT_CFG_FIEL_PATH); diff --git a/services/init/standard/init.c b/services/init/standard/init.c index c147bcc83857353c2a1979e3d3d79e1367d26364..80896049303a9fdfed402607b7dedb33b6956690 100755 --- a/services/init/standard/init.c +++ b/services/init/standard/init.c @@ -266,7 +266,7 @@ int ParseCfgByPriority(const char *filePath) return -1; } CfgFiles *files = GetCfgFiles(filePath); - if (files == NULL) { + if (files == NULL || files->paths[0] == NULL) { INIT_LOGE("get etc/init cfg failed"); return -1; } diff --git a/services/loopevent/BUILD.gn b/services/loopevent/BUILD.gn index b2f2671100194682c17f1440ee4eb1c68e68b589..196b92a68ee6279491a0a5108526ef8ca753de70 100644 --- a/services/loopevent/BUILD.gn +++ b/services/loopevent/BUILD.gn @@ -46,7 +46,6 @@ config("exported_header_files") { if (defined(ohos_lite)) { static_library("loopevent") { sources = common_sources - cflags = [ "-fPIC" ] include_dirs = common_include external_deps = [ "bounds_checking_function:libsec_shared" ] defines = [ "_GNU_SOURCE" ] diff --git a/services/loopevent/loop/le_epoll.c b/services/loopevent/loop/le_epoll.c index 282f0f7ec32372fe6137b322e5932502b8099569..29e692165502e064b984cde1e8c0e4bbbc02e811 100644 --- a/services/loopevent/loop/le_epoll.c +++ b/services/loopevent/loop/le_epoll.c @@ -104,6 +104,7 @@ static LE_STATUS RunLoop_(const EventLoop *loop) return LE_FAILURE; } + int pid = getpid(); while (1) { LE_RunIdle((LoopHandle)&(epoll->loop)); @@ -121,7 +122,7 @@ static LE_STATUS RunLoop_(const EventLoop *loop) } int number = epoll_wait(epoll->epollFd, epoll->waitEvents, loop->maxevents, timeout); - if (number > 1) { + if (number > 1 && pid != 1) { LE_LOGI("RunLoop_ epoll_wait with number %d", number); } for (int index = 0; index < number; index++) { @@ -132,14 +133,17 @@ static LE_STATUS RunLoop_(const EventLoop *loop) ProcessEvent(loop, epoll->waitEvents[index].data.fd, EVENT_WRITE); } if (epoll->waitEvents[index].events & (EPOLLERR | EPOLLHUP)) { - LE_LOGW("RunLoop_ fd:%d, error:%d", epoll->waitEvents[index].data.fd, errno); + LE_LOGV("RunLoop_ fd:%d, error:%d", epoll->waitEvents[index].data.fd, errno); ProcessEvent(loop, epoll->waitEvents[index].data.fd, EVENT_ERROR); } } - if (number > 1) { + + if (number > 1 && pid != 1) { LE_LOGI("RunLoop_ epoll_wait finish"); } - CheckTimeoutOfTimer((EventLoop *)loop, GetCurrentTimespec(0)); + if (GetCurrentTimespec(0) >= minTimePeriod) { + CheckTimeoutOfTimer((EventLoop *)loop, GetCurrentTimespec(0)); + } if (loop->stop) { break; diff --git a/services/loopevent/socket/le_socket.c b/services/loopevent/socket/le_socket.c index 1f307783c4f3fe04dc96b2e2adb5d763ba60e11a..91ec4792612a9fcacf714684910d62ab6fec03ac 100644 --- a/services/loopevent/socket/le_socket.c +++ b/services/loopevent/socket/le_socket.c @@ -130,8 +130,8 @@ static int CreateTcpServerSocket_(const char *server, int maxClient) LE_CHECK(listenfd > 0, return listenfd, "Failed to create socket"); int ret = SetSocketTimeout(listenfd); - LE_CHECK(ret == 0, return ret, "Failed to set socket timeout"); - + LE_CHECK(ret == 0, close(listenfd); + return ret, "Failed to set socket timeout"); struct sockaddr_in serverAddr; GetSockaddrFromServer_(server, &serverAddr); ret = bind(listenfd, (struct sockaddr *)&serverAddr, sizeof(serverAddr)); @@ -156,7 +156,8 @@ static int CreateTcpSocket_(const char *server) LE_CHECK(ret == 0, return ret, "Failed to set socket option"); ret = SetSocketTimeout(fd); - LE_CHECK(ret == 0, return ret, "Failed to set socket timeout"); + LE_CHECK(ret == 0, close(fd); + return ret, "Failed to set socket timeout"); struct sockaddr_in serverAddr; GetSockaddrFromServer_(server, &serverAddr); @@ -231,12 +232,12 @@ int AcceptSocket(int fd, int flags) } INIT_LOCAL_API -int listenSocket(int fd, int flags, const char *server) +int listenSocket(int fd, uint32_t flags, const char *server) { - unsigned int type = (unsigned int)flags & 0x0000ff00; + unsigned int type = flags & 0x0000ff00; LE_LOGV("listenSocket flags %x type %x server %s", flags, type, server); SetNoBlock(fd); - if (!LE_TEST_FLAGS((unsigned int)flags, TASK_SERVER)) { + if (!LE_TEST_FLAGS(flags, TASK_SERVER)) { return 0; } if (type == TASK_TCP) { diff --git a/services/loopevent/socket/le_socket.h b/services/loopevent/socket/le_socket.h index f28532a3addf24b4c8d4238e36f70b728b76a5f8..13b26d700de952b7c86e1a10a7c3e6bc3956959d 100644 --- a/services/loopevent/socket/le_socket.h +++ b/services/loopevent/socket/le_socket.h @@ -32,7 +32,7 @@ int CreateSocket(int flags, const char *server); INIT_LOCAL_API int AcceptSocket(int fd, int flags); INIT_LOCAL_API -int listenSocket(int fd, int flags, const char *server); +int listenSocket(int fd, uint32_t flags, const char *server); #ifdef __cplusplus #if __cplusplus diff --git a/services/loopevent/task/le_streamtask.c b/services/loopevent/task/le_streamtask.c index b1184e15404b2660ba94b7c60af20e179a2cc079..d3d983a2a61cb87ac89e944817d2bcea7465ab08 100644 --- a/services/loopevent/task/le_streamtask.c +++ b/services/loopevent/task/le_streamtask.c @@ -30,6 +30,10 @@ static LE_STATUS HandleSendMsg_(const LoopHandle loopHandle, LE_Buffer *buffer = GetFirstBuffer(stream); while (buffer) { int ret = write(GetSocketFd(taskHandle), buffer->data, buffer->dataSize); + if (strstr(((const char *)buffer->data + 12), "bootevent.boot.completed") != NULL) { + LE_LOGI("begin to send boot.completed to param_watcher, fd:%d, size:%u", + GetSocketFd(taskHandle), buffer->dataSize); + } if (ret < 0 || (size_t)ret < buffer->dataSize) { LE_LOGE("HandleSendMsg_ fd:%d send data size %d %d, err:%d", GetSocketFd(taskHandle), buffer->dataSize, ret, errno); @@ -113,7 +117,7 @@ static LE_STATUS HandleStreamEvent_(const LoopHandle loopHandle, const TaskHandl static LE_STATUS HandleClientEvent_(const LoopHandle loopHandle, const TaskHandle handle, uint32_t oper) { StreamClientTask *client = (StreamClientTask *)handle; - LE_LOGI("HandleClientEvent_ fd:%d oper 0x%x", GetSocketFd(handle), oper); + LE_LOGV("HandleClientEvent_ fd:%d oper 0x%x", GetSocketFd(handle), oper); LE_STATUS status = LE_SUCCESS; if (LE_TEST_FLAGS(oper, EVENT_WRITE)) { diff --git a/services/modules/crashhandler/crash_handler.c b/services/modules/crashhandler/crash_handler.c index 5c2627a02f529c87d6c76b0da4fef2305c04b964..965ad2ce66873363ccbe857734c606f579cd2e7e 100644 --- a/services/modules/crashhandler/crash_handler.c +++ b/services/modules/crashhandler/crash_handler.c @@ -35,9 +35,11 @@ #include "securec.h" #include "init_cmds.h" #include "init_log.h" +#include "init_service.h" +#include "hookmgr.h" +#include "bootstage.h" #include "crash_handler.h" -#define SLEEP_DURATION 2 static const SignalInfo g_platformSignals[] = { { SIGABRT, "SIGABRT" }, { SIGBUS, "SIGBUS" }, @@ -51,11 +53,26 @@ static const SignalInfo g_platformSignals[] = { { SIGTRAP, "SIGTRAP" }, }; +static void DoCriticalInit(void) +{ +#ifndef OHOS_LITE + Service service = { + .pid = 1, + .name = "init", + }; + + BEGET_LOGI("ServiceReap init begin"); + HookMgrExecute(GetBootStageHookMgr(), INIT_SERVICE_REAP, (void *)&service, NULL); + BEGET_LOGI("ServiceReap init end!"); +#endif +} + static void SignalHandler(int sig, siginfo_t *si, void *context) { int32_t pid = getpid(); if (pid == 1) { - sleep(SLEEP_DURATION); + sleep(1); + DoCriticalInit(); ExecReboot("panic"); } else { exit(-1); diff --git a/services/modules/trace/init_trace.c b/services/modules/trace/init_trace.c index 1b35e2d7a00c4f979f407b386e8ece55388830d3..d6fcc6a622d6c6942c94817ed5039454accd8c05 100644 --- a/services/modules/trace/init_trace.c +++ b/services/modules/trace/init_trace.c @@ -304,7 +304,7 @@ static void CheckKernelType(bool *isLinux) { struct utsname uts; if (uname(&uts) == -1) { - PLUGIN_LOGE("Kernel type get failed,errno:%{public}d", errno); + PLUGIN_LOGE("Kernel type get failed,errno:d", errno); return; } diff --git a/services/modules/udid/udid_comm.c b/services/modules/udid/udid_comm.c index d06f41a931f93ccb2190de008ab24ee7e0eb6720..809f2b9e9eb12b6211286fb5660c4c53340ed250 100644 --- a/services/modules/udid/udid_comm.c +++ b/services/modules/udid/udid_comm.c @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "udid.h" #ifdef OHOS_LITE @@ -21,15 +22,13 @@ #include "param_comm.h" #include "securec.h" #include "sysparam_errno.h" -#include -#include INIT_LOCAL_API const char *GetSerial_(void) { #ifdef OHOS_LITE return HalGetSerial(); #else - static _Atomic (char *)ohosSerial = NULL; + static char *ohosSerial = NULL; if (ohosSerial != NULL) { return ohosSerial; } @@ -44,7 +43,7 @@ INIT_LOCAL_API const char *GetSerial_(void) free(value); return ohosSerial; } - atomic_store_explicit(&ohosSerial, value, memory_order_release); + ohosSerial = value; return ohosSerial; #endif } diff --git a/services/param/adapter/param_persistadp.c b/services/param/adapter/param_persistadp.c index 979a63d3e95218eecc151670b9a7ac60630dce46..7dba4798c8ccaecc8c0d0a9f95e4fc833841d34f 100644 --- a/services/param/adapter/param_persistadp.c +++ b/services/param/adapter/param_persistadp.c @@ -21,7 +21,7 @@ #include "param_manager.h" #include "param_persist.h" #include "param_utils.h" -#if !(defined __LITEOFS_A__ || defined __LITEOS_M__) +#if !(defined __LITEOS_A__ || defined __LITEOS_M__) #include "trigger_manager.h" #endif @@ -60,7 +60,7 @@ static int LoadOnePersistParam_(const uint32_t *context, const char *name, const result = WriteParam(name, value, &dataIndex, mode); } } while (0); -#if !(defined __LITEOFS_A__ || defined __LITEOS_M__) +#if !(defined __LITEOS_A__ || defined __LITEOS_M__) if (result == 0) { PostParamTrigger(EVENT_TRIGGER_PARAM_WATCH, name, value); } diff --git a/services/param/base/param_base.c b/services/param/base/param_base.c index c3399107eaa110dc611f7d40bfb773243bc2bc4a..c65e052243ad48fcee3866554778428985825c4c 100644 --- a/services/param/base/param_base.c +++ b/services/param/base/param_base.c @@ -526,7 +526,7 @@ STATIC_INLINE int SelinuxCheckParamPermission(const ParamLabelIndex *labelIndex, } if (ret != 0) { ret = SELINUX_RESULT_FORBIDED; - PARAM_LOGE("Selinux check name %s in %s [%d %d %d] failed", + PARAM_LOGW("Selinux check name %s in %s [%d %d %d] failed", name, GetSelinuxContent(name), srcLabel->cred.pid, srcLabel->cred.uid, srcLabel->cred.gid); } return ret; diff --git a/services/param/base/param_trie.c b/services/param/base/param_trie.c index 99dd6328c8f7aaba0c99ad3dcb0e0a32971b0203..6d7628fbbfc37ec6971895861620f81619387239 100644 --- a/services/param/base/param_trie.c +++ b/services/param/base/param_trie.c @@ -272,12 +272,13 @@ INIT_LOCAL_API uint32_t AddParamNode(WorkSpace *workSpace, uint8_t type, const char *key, uint32_t keyLen, const char *value, uint32_t valueLen, int mode) { PARAM_CHECK(key != NULL && value != NULL, return OFFSET_ERR, "Invalid param"); + PARAM_CHECK(valueLen < PARAM_CONST_VALUE_LEN_MAX, return OFFSET_ERR, "Invalid valueLen"); PARAM_CHECK(CheckWorkSpace(workSpace) == 0, return OFFSET_ERR, "Invalid workSpace %s", key); uint32_t realLen = sizeof(ParamNode) + 1 + 1; // for const parameter, alloc memory on demand - if ((valueLen > PARAM_VALUE_LEN_MAX) || IS_READY_ONLY(key)) { - realLen += keyLen + valueLen; + if (valueLen > PARAM_VALUE_LEN_MAX) { // Only read-only parameters' valueLen is bigger than 96 + realLen += keyLen + PARAM_CONST_VALUE_LEN_MAX; } else { realLen += keyLen + GetParamMaxLen(type); } diff --git a/services/param/include/param_manager.h b/services/param/include/param_manager.h index e2aeeb931a2d09417c70f2e4c307e0d29556b979..8d07852e50c40ea105d1cd3283b42d821b052bfc 100644 --- a/services/param/include/param_manager.h +++ b/services/param/include/param_manager.h @@ -57,7 +57,7 @@ extern "C" { #define PARAM_NEED_CHECK_IN_SERVICE 0x2 #define PARAM_CTRL_SERVICE 0x1 #ifndef OHOS_LITE -#define PERSIST_PARAM_FIXED_FLAGS "/data/service/el1/startup/persist_param_fixed" +#define PERSIST_PARAM_FIXED_FLAGS "/data/service/el1/public/startup/persist_param_fixed" #else #define PERSIST_PARAM_FIXED_FLAGS "/storage/data/system/param/persist_param_fixed" #endif diff --git a/services/param/linux/param_service.c b/services/param/linux/param_service.c index 9332af772e72c2c43a30d465faf82b8715e0889c..392606c34bc1e5c1e111b71d59ca6e8919ca8aff 100755 --- a/services/param/linux/param_service.c +++ b/services/param/linux/param_service.c @@ -316,14 +316,14 @@ static int HandleParamWatcherAdd(const ParamTaskPtr worker, const ParamMessage * PARAM_LOGE("Failed to add trigger for %s", msg->key); return SendResponseMsg(worker, msg, -1); } - PARAM_LOGI("HandleParamWatcherAdd name %s watcher: %d", msg->key, msg->id.watcherId); + PARAM_LOGI("HandleParamWatcherAdd name %s watcher: %u", msg->key, msg->id.watcherId); return SendResponseMsg(worker, msg, 0); } static int HandleParamWatcherDel(const ParamTaskPtr worker, const ParamMessage *msg) { PARAM_CHECK(msg != NULL, return -1, "Invalid message"); - PARAM_LOGV("HandleParamWatcherDel name %s watcher: %d", msg->key, msg->id.watcherId); + PARAM_LOGV("HandleParamWatcherDel name %s watcher: %u", msg->key, msg->id.watcherId); DelWatchTrigger(TRIGGER_PARAM_WATCH, (const void *)&msg->id.watcherId); return SendResponseMsg(worker, msg, 0); } diff --git a/services/param/liteos/param_persistadp.c b/services/param/liteos/param_persistadp.c index d1f3d8b146eec48088652941327754259185f067..dbeb4ca3b007497bf566260b1dd3a0cea308ca61 100644 --- a/services/param/liteos/param_persistadp.c +++ b/services/param/liteos/param_persistadp.c @@ -28,6 +28,8 @@ static ParamMutex g_saveMutex = {}; static int LoadOnePersistParam_(const uint32_t *context, const char *name, const char *value) { UNUSED(context); + PARAM_CHECK(name != NULL, return -1, "param is invalid"); + PARAM_CHECK(value != NULL, return -1, "value is invalid"); if (strncmp(name, "persist", strlen("persist")) != 0) { PARAM_LOGE("%s is not persist param, do not load", name); return 0; @@ -43,7 +45,7 @@ static int LoadOnePersistParam_(const uint32_t *context, const char *name, const return WriteParam(name, value, &dataIndex, mode); } - if ((strcmp(persetValue, value) != 0)) { + if (strcmp(persetValue, value) != 0) { PARAM_LOGI("%s value is different, preset value is:%s, persist value is:%s", name, persetValue, value); mode |= LOAD_PARAM_PERSIST; return WriteParam(name, value, &dataIndex, mode); diff --git a/services/param/manager/param_manager.c b/services/param/manager/param_manager.c index 31ed67ea0816a16a73b14a2d586a45d85159b98f..10e7061e5e550997d9946c59af9be8e5da3eb424 100644 --- a/services/param/manager/param_manager.c +++ b/services/param/manager/param_manager.c @@ -456,11 +456,17 @@ static int UpdateParam(const WorkSpace *workSpace, uint32_t *dataIndex, const ch uint32_t valueLen = strlen(value); uint32_t commitId = ATOMIC_LOAD_EXPLICIT(&entry->commitId, MEMORY_ORDER_RELAXED); ATOMIC_STORE_EXPLICIT(&entry->commitId, commitId | PARAM_FLAGS_MODIFY, MEMORY_ORDER_RELAXED); - if ((((uint32_t)mode & LOAD_PARAM_UPDATE_CONST) == LOAD_PARAM_UPDATE_CONST) && - (entry->valueLength < PARAM_CONST_VALUE_LEN_MAX && valueLen < PARAM_CONST_VALUE_LEN_MAX)) { - int ret = PARAM_MEMCPY(entry->data + entry->keyLength + 1, PARAM_CONST_VALUE_LEN_MAX, value, valueLen + 1); - PARAM_CHECK(ret == 0, return PARAM_CODE_INVALID_VALUE, "Failed to copy value"); - entry->valueLength = valueLen; + if (((unsigned int)mode & LOAD_PARAM_UPDATE_CONST) == LOAD_PARAM_UPDATE_CONST) { + if (entry->valueLength < PARAM_VALUE_LEN_MAX && valueLen >= PARAM_VALUE_LEN_MAX) { + PARAM_LOGE("value len valid, current param value len is %d < 96, new value len %d >= 96.", + entry->valueLength, valueLen); + return PARAM_CODE_INVALID_VALUE; + } + if (entry->valueLength < PARAM_CONST_VALUE_LEN_MAX && valueLen < PARAM_CONST_VALUE_LEN_MAX) { + int ret = PARAM_MEMCPY(entry->data + entry->keyLength + 1, PARAM_CONST_VALUE_LEN_MAX, value, valueLen + 1); + PARAM_CHECK(ret == 0, return PARAM_CODE_INVALID_VALUE, "Failed to copy value"); + entry->valueLength = valueLen; + } } else if (entry->valueLength < PARAM_VALUE_LEN_MAX && valueLen < PARAM_VALUE_LEN_MAX) { int ret = PARAM_MEMCPY(entry->data + entry->keyLength + 1, PARAM_VALUE_LEN_MAX, value, valueLen + 1); PARAM_CHECK(ret == 0, return PARAM_CODE_INVALID_VALUE, "Failed to copy value"); @@ -694,7 +700,7 @@ static int CheckParamPermission_(WorkSpace **workspace, ParamTrieNode **node, labelIndex.selinuxLabelIndex = labelIndex.workspace->spaceIndex; int ret = paramSpace->checkParamPermission(&labelIndex, srcLabel, name, mode); - PARAM_CHECK(ret == 0, return ret, + PARAM_WARNING_CHECK(ret == 0, return ret, "deny access %s label %u %u", name, labelIndex.dacLabelIndex, labelIndex.selinuxLabelIndex); *workspace = labelIndex.workspace; return ret; @@ -746,7 +752,7 @@ int SystemReadParam(const char *name, char *value, uint32_t *len) WorkSpace *workspace = NULL; int ret = CheckParamPermission_(&workspace, &node, GetParamSecurityLabel(), name, DAC_READ); if (ret != 0) { - PARAM_LOGE("SystemReadParam failed! name is:%s, err:%d!", name, ret); + PARAM_LOGW("SystemReadParam failed! name is:%s, err:%d!", name, ret); return ret; } #ifdef PARAM_SUPPORT_SELINUX diff --git a/services/param/trigger/trigger_checker.c b/services/param/trigger/trigger_checker.c index 42e7c2d0bfe9b5fda2f4548347288c4ee65c5bec..6b6f365738e02979158f7babdcada6836626b9b4 100644 --- a/services/param/trigger/trigger_checker.c +++ b/services/param/trigger/trigger_checker.c @@ -185,9 +185,7 @@ static int ComputeSubCondition(const LogicCalculator *calculator, LogicData *dat strlen(calculator->conditionName) + 1, calculator->conditionContent, SUPPORT_DATA_BUFFER_MAX); PARAM_CHECK(ret == 0, return -1, "Failed parse content value"); // check name - if ((calculator->inputName != NULL) && (strcmp(calculator->conditionName, calculator->inputName) == 0)) { - return CompareValue(calculator->conditionContent, calculator->inputContent); - } else if (strlen(calculator->conditionName) > 0) { + if (strlen(calculator->conditionName) > 0) { uint32_t len = SUPPORT_DATA_BUFFER_MAX; ret = SystemReadParam(calculator->conditionName, calculator->readContent, &len); if (ret != 0) { diff --git a/services/param/watcher/proxy/watcher_manager.cpp b/services/param/watcher/proxy/watcher_manager.cpp index dbddbd8ba4dba681c5cccb8f04df78078e78023d..8b849f8ef264925df498c3a02c11fca0a48443d0 100644 --- a/services/param/watcher/proxy/watcher_manager.cpp +++ b/services/param/watcher/proxy/watcher_manager.cpp @@ -34,6 +34,7 @@ REGISTER_SYSTEM_ABILITY_BY_ID(WatcherManager, PARAM_WATCHER_DISTRIBUTED_SERVICE_ const static int32_t INVALID_SOCKET = -1; const static int32_t ERR_FAIL = -1; const static int32_t PUBLIC_APP_BEGIN_UID = 10000; +constexpr int32_t RECV_BUFFER_MAX = 20 * 1024; WatcherManager::~WatcherManager() { Clear(); @@ -239,7 +240,7 @@ void WatcherGroup::ProcessParameterChange( if (remoteWatcher == nullptr) { return; } - if (strcmp("startup.service.ctl.*", GetKeyPrefix().c_str())!= 0) { + if (strcmp("startup.service.ctl.*", GetKeyPrefix().c_str()) != 0) { WATCHER_LOGI("ProcessParameterChange key '%s' pid: %d", GetKeyPrefix().c_str(), remoteWatcher->GetAgentId()); } @@ -341,13 +342,13 @@ void WatcherManager::SendLocalChange(const std::string &keyPrefix, uint32_t remo void WatcherManager::RunLoop() { - const int32_t RECV_BUFFER_MAX = 5 * 1024; std::vector buffer(RECV_BUFFER_MAX, 0); bool retry = false; ssize_t recvLen = 0; while (!stop_) { int fd = GetServerFd(retry); if (stop_) { + WATCHER_LOGE("loop is stop, reset"); break; } if (fd >= 0) { @@ -355,9 +356,10 @@ void WatcherManager::RunLoop() } if (recvLen <= 0) { if (errno == EAGAIN) { // timeout + WATCHER_LOGE("nothing to read, retry"); continue; } - PARAM_LOGE("Failed to recv msg from server errno %d", errno); + WATCHER_LOGE("Failed to recv msg from server errno %d", errno); retry = true; // re connect continue; } @@ -365,10 +367,12 @@ void WatcherManager::RunLoop() uint32_t dataLen = static_cast(recvLen); while (curr < dataLen) { if (sizeof(ParamMessage) >= dataLen - curr) { + WATCHER_LOGE("ParamMessage len is invalid, datalen %u curr %u", dataLen, curr); break; } ParamMessage *msg = (ParamMessage *)(buffer.data() + curr); if (msg->msgSize == 0 || (msg->msgSize > dataLen - curr)) { + WATCHER_LOGE("msgSize %u is invalid, datalen %u curr %u", msg->msgSize, dataLen, curr); break; } ProcessWatcherMessage(msg); @@ -379,7 +383,7 @@ void WatcherManager::RunLoop() close(serverFd_); serverFd_ = INVALID_SOCKET; } - WATCHER_LOGV("Exit runLoop serverFd %d", serverFd_); + WATCHER_LOGE("Exit runLoop serverFd %d", serverFd_); } void WatcherManager::StartLoop() diff --git a/services/sandbox/sandbox.c b/services/sandbox/sandbox.c index ea980270b805be3afbff867008a227e723be0e15..d0d976448aa9bdb323c1bdfec6303a76df91caaa 100755 --- a/services/sandbox/sandbox.c +++ b/services/sandbox/sandbox.c @@ -452,6 +452,8 @@ static int BindMount(const char *source, const char *target, unsigned long flags BEGET_WARNING_CHECK((tmpflags & MS_BIND) != 0, tmpflags |= MS_BIND, "Not configure mount bind, must configure mount bind flag."); + BEGET_WARNING_CHECK((tmpflags & MS_REC) != 0, tmpflags |= MS_REC, + "Not configure mount rec, must configure mount rec flag."); // do mount if (mount(source, target, NULL, tmpflags, NULL) != 0) { diff --git a/services/utils/init_utils.c b/services/utils/init_utils.c index 35b01b7367384ab244e254f11ca17e519868efeb..e5cb2ceff999c45b5a2438195ccc877de63ccd16 100644 --- a/services/utils/init_utils.c +++ b/services/utils/init_utils.c @@ -409,11 +409,9 @@ void WaitForFile(const char *source, unsigned int maxSecond) INIT_LOGE("stat file err: %d", errno); break; } - usleep(waitTime); (void)clock_gettime(CLOCK_MONOTONIC, &cmdTimer.endTime); duration = InitDiffTime(&cmdTimer); - if (duration >= maxDuration) { INIT_LOGE("wait for file:%s failed after %d second.", source, maxSecond); break; @@ -906,7 +904,7 @@ void *OH_ExtendableStrDictGet(void **strDict, int dictSize, const char *target, { const char *pos; str_compare cmp = strcmp; - if ((strDict == NULL) || dictSize < 0 || ((size_t)dictSize < sizeof(const char *)) || + if ((strDict == NULL) || (dictSize < 0) || ((size_t)dictSize < sizeof(const char *)) || (target == NULL) || (target[0] == '\0')) { return NULL; } diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 7d9ac4bb529990d744d8b90048f4fb590436cdc8..9b8fa3a211b84602bf7a3da106261ae77668dc1b 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -3086,6 +3086,56 @@ ohos_fuzztest("OnStopFuzzTest") { } } +ohos_fuzztest("ProcessWatcherMessageFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/startup/init/test/fuzztest/processwatchermessage_fuzzer" + + sources = [ + "//base/startup/init/services/param/linux/param_message.c", + "//base/startup/init/services/param/watcher/proxy/watcher_manager.cpp", + ] + include_dirs = [ + "//base/startup/init/interfaces/innerkits/include", + "//base/startup/init/test/fuzztest/utils/include", + "//base/startup/init/services/param/watcher/proxy", + "//base/startup/init/services/param/watcher/include", + "//base/startup/init/services/param/include", + "//base/startup/init/interfaces/innerkits/include/param", + "//base/startup/init/services/param/linux", + "//base/startup/init/services/loopevent/include", + "//base/startup/init/services/param/watcher/agent", + ] + + deps = [ + "//base/startup/init/interfaces/innerkits:libbegetutil", + "//base/startup/init/interfaces/innerkits/:param_watcher_stub", + "//base/startup/init/services/log:agent_log", + ] + external_deps = [ + "bounds_checking_function:libsec_static", + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_single", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + if (init_paramwatcher_hicollie_enable) { + external_deps += [ "hicollie:libhicollie" ] + } + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources += [ "processwatchermessage_fuzzer/processwatchermessage_fuzzer.cpp" ] + defines = [ "STARTUP_INIT_TEST" ] + if (init_paramwatcher_hicollie_enable) { + defines += [ "HICOLLIE_ENABLE" ] + } +} + ohos_fuzztest("GetBuildVersionFuzzTest") { module_out_path = module_output_path fuzz_config_file = "//base/startup/init/test/fuzztest/getbuildversion_fuzzer" @@ -4177,6 +4227,7 @@ group("fuzztest") { ":ParseFstabPerLineFuzzTest", ":ParseUeventConfigFuzzTest", ":ParseUeventdConfigFileFuzzTest", + ":ProcessWatcherMessageFuzzTest", ":ReadFileInDirFuzzTest", ":ReadFileToBufFuzzTest", ":ReadFstabFromFileFuzzTest", diff --git a/test/fuzztest/addparamentry_fuzzer/addparamentry_fuzzer.cpp b/test/fuzztest/addparamentry_fuzzer/addparamentry_fuzzer.cpp index 700afbbb37e858f8c6c907029a582e37b34dc70a..9a9400ef5a251afe5f7e461f887a6eba5aae9055 100644 --- a/test/fuzztest/addparamentry_fuzzer/addparamentry_fuzzer.cpp +++ b/test/fuzztest/addparamentry_fuzzer/addparamentry_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 diff --git a/test/fuzztest/addparamentry_fuzzer/addparamentry_fuzzer.h b/test/fuzztest/addparamentry_fuzzer/addparamentry_fuzzer.h index 72d69b470c74eac4ac96ff9f2ff4f56b4f700e8e..69b165b366611b151ff5e29075cf58c1e3e07c14 100644 --- a/test/fuzztest/addparamentry_fuzzer/addparamentry_fuzzer.h +++ b/test/fuzztest/addparamentry_fuzzer/addparamentry_fuzzer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 diff --git a/test/fuzztest/addparamentry_fuzzer/corpus/init b/test/fuzztest/addparamentry_fuzzer/corpus/init index 8eb5a7d6eb6b7d71f0c70c244e5768d62bee6ac5..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 100644 --- a/test/fuzztest/addparamentry_fuzzer/corpus/init +++ b/test/fuzztest/addparamentry_fuzzer/corpus/init @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 diff --git a/test/fuzztest/addparamentry_fuzzer/project.xml b/test/fuzztest/addparamentry_fuzzer/project.xml index 949d03efd7477905377ac79f3b0bb374c8ac2e9a..b39473f2f6776874287a2de22477705b1b60385c 100644 --- a/test/fuzztest/addparamentry_fuzzer/project.xml +++ b/test/fuzztest/addparamentry_fuzzer/project.xml @@ -1,5 +1,5 @@ - + + + + 100 + + 30 + + 3072 + + \ No newline at end of file diff --git a/test/unittest/fs_manager/erofs/erofs_remount_unittest.cpp b/test/unittest/fs_manager/erofs/erofs_remount_unittest.cpp index 6b5c6018b4a741ed0afdd225d2104e09e5d92734..a20171155ab0aba0142b488ceaad80989c11ca5d 100644 --- a/test/unittest/fs_manager/erofs/erofs_remount_unittest.cpp +++ b/test/unittest/fs_manager/erofs/erofs_remount_unittest.cpp @@ -43,12 +43,11 @@ public: HWTEST_F(ErofsRemountUnitTest, Init_GetRemountResult_001, TestSize.Level0) { - rmdir(REMOUNT_RESULT_PATH); RemountOverlay(); + CheckAndCreateDir(REMOUNT_RESULT_PATH); SetRemountResultFlag(); int ret = GetRemountResult(); EXPECT_EQ(ret, 0); - rmdir(REMOUNT_RESULT_PATH); } HWTEST_F(ErofsRemountUnitTest, Init_Modem2Exchange_001, TestSize.Level0) diff --git a/test/unittest/param/param_stub.cpp b/test/unittest/param/param_stub.cpp index 0f654d112a095c33087d5b1d48edd24f0492750b..738a6f2df45ede52e6ae6c30f2664ddb10cfe894 100644 --- a/test/unittest/param/param_stub.cpp +++ b/test/unittest/param/param_stub.cpp @@ -397,11 +397,10 @@ static void PrepareAreaSizeFile(void) "startup_param=20480\n" "persist_param=2048\n" "const_param=20480\n" - "test_watch=102400\n" - "test_write=102400\n" + "test_watch=153600\n" // 1024 * 150 + "test_write=153600\n" // 1024 * 150 "const_param***=20480\n" - "persist_sys_param=2048\n" - "test_write=102400\n"; + "persist_sys_param=2048\n"; CreateTestFile(PARAM_AREA_SIZE_CFG, ohosParamSize); } diff --git a/test/unittest/syspara/syspara_unittest.cpp b/test/unittest/syspara/syspara_unittest.cpp index aef246ede8f5168ad11efc168d3cef25a9ab36a4..9cc6b76dd2999a39ee7ce267fe6c2fc91b443db9 100644 --- a/test/unittest/syspara/syspara_unittest.cpp +++ b/test/unittest/syspara/syspara_unittest.cpp @@ -486,5 +486,59 @@ HWTEST_F(SysparaUnitTest, parameterTest0019, TestSize.Level0) ret = SystemUpdateConstParam(key2, value2); EXPECT_EQ(ret, PARAM_CODE_INVALID_NAME); } + +HWTEST_F(SysparaUnitTest, parameterTest0020, TestSize.Level0) +{ + char key1[] = "const.test.for_update_test1"; + char value1[] = "initSet"; // len < 96 + char value2[] = "initUpdate_abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" \ + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"; // len > 96 + + int ret = SystemWriteParam(key1, value1); + EXPECT_EQ(ret, 0); + ret = SystemUpdateConstParam(key1, value2); + EXPECT_EQ(ret, PARAM_CODE_INVALID_VALUE); +} + +HWTEST_F(SysparaUnitTest, parameterTest0021, TestSize.Level0) +{ + char key1[] = "const.test.for_update_test2"; + char value1[] = "initSet_abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" \ + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"; // len > 96 + char value2[] = "initUpdate_abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" \ + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"; // len > 96 + + int ret = SystemWriteParam(key1, value1); + EXPECT_EQ(ret, 0); + ret = SystemUpdateConstParam(key1, value2); + EXPECT_EQ(ret, 0); +} + +HWTEST_F(SysparaUnitTest, parameterTest0022, TestSize.Level0) +{ + char key1[] = "const.test.for_update_test3"; + char value1[] = "initSet_abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" \ + "abcdefghijklmnopqrstuvwxyzabcdefghi"; // len = 96 + char value2[] = "initUpdate_abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" \ + "abcdefghijklmnopqrstuvwxyzabcdef"; // len = 96 + + int ret = SystemWriteParam(key1, value1); + EXPECT_EQ(ret, 0); + ret = SystemUpdateConstParam(key1, value2); + EXPECT_EQ(ret, 0); +} + +HWTEST_F(SysparaUnitTest, parameterTest0023, TestSize.Level0) +{ + char key1[] = "const.test.for_update_test4"; + char value1[] = "initSet_abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" \ + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"; // len > 96 + char value2[] = "initUpdate_abcdefghijkl"; // len < 96 + + int ret = SystemWriteParam(key1, value1); + EXPECT_EQ(ret, 0); + ret = SystemUpdateConstParam(key1, value2); + EXPECT_EQ(ret, 0); +} #endif } // namespace OHOS diff --git a/ueventd/etc/ueventd.config b/ueventd/etc/ueventd.config index 8c284da87427f00dbbc5686df39e521ab153b1c7..ab7a03e2f4395e599be276ab9ad390cdbc04b0ce 100644 --- a/ueventd/etc/ueventd.config +++ b/ueventd/etc/ueventd.config @@ -82,7 +82,6 @@ /dev/btdev* 0660 dsoftbus dsoftbus /dev/block/by-name/misc 0660 update update /dev/block/by-name/bootctrl 0660 update update -/dev/video* 0660 clearplay_host clearplay_host /dev/hidraw* 0666 0 input /dev/sg* 0660 usb_host usb_host /dev/signal_hub 0660 radio radio diff --git a/ueventd/ueventd_device_handler.c b/ueventd/ueventd_device_handler.c index ec63752d658ecee800b3358f3e87fa8df2154d09..c0f6c795bdaf19b8de1703ad13d07e2b1184c582 100644 --- a/ueventd/ueventd_device_handler.c +++ b/ueventd/ueventd_device_handler.c @@ -505,6 +505,29 @@ void HandleBlockDeviceEvent(const struct Uevent *uevent) HandleDeviceNode(uevent, deviceNode, isBlock); } +static int SplitUsbDeviceNode(const struct Uevent *uevent, char *deviceNode) +{ + if (uevent->deviceName != NULL) { + if (snprintf_s(deviceNode, DEVICE_FILE_SIZE, DEVICE_FILE_SIZE - 1, "/dev/%s", uevent->deviceName) == -1) { + INIT_LOGE("Make device file for device [%d : %d]", uevent->major, uevent->minor); + return -1; + } + return 0; + } else { + if (uevent->busNum < 0 || uevent->devNum < 0) { + // usb device should always report bus number and device number. + INIT_LOGE("usb device with invalid bus number or device number"); + return -1; + } + if (snprintf_s(deviceNode, DEVICE_FILE_SIZE, DEVICE_FILE_SIZE - 1, + "/dev/bus/usb/%03d/%03d", uevent->busNum, uevent->devNum) == -1) { + INIT_LOGE("Make usb device node for device [%d : %d]", uevent->busNum, uevent->devNum); + return 0; + } + return 0; + } +} + void HandleOtherDeviceEvent(const struct Uevent *uevent) { if (uevent == NULL || uevent->subsystem == NULL || uevent->syspath == NULL) { @@ -529,27 +552,17 @@ void HandleOtherDeviceEvent(const struct Uevent *uevent) INIT_LOGE("Cannot get device path or device name"); return; } + if (strcmp(devPath, "/dev/input") == 0) { + INIT_LOGI("HandleOtherDeviceEvent, devPath = %s, devName = %s", devPath, devName); + } INIT_LOGV("HandleOtherDeviceEvent, devPath = %s, devName = %s", devPath, devName); // For usb devices, should take care of it specially. // if usb devices report DEVNAME, just create device node. // otherwise, create deviceNode with bus number and device number. if (STRINGEQUAL(uevent->subsystem, "usb")) { - if (uevent->deviceName != NULL) { - if (snprintf_s(deviceNode, DEVICE_FILE_SIZE, DEVICE_FILE_SIZE - 1, "/dev/%s", uevent->deviceName) == -1) { - INIT_LOGE("Make device file for device [%d : %d]", uevent->major, uevent->minor); - return; - } - } else { - if (uevent->busNum < 0 || uevent->devNum < 0) { - // usb device should always report bus number and device number. - INIT_LOGE("usb device with invalid bus number or device number"); - return; - } - if (snprintf_s(deviceNode, DEVICE_FILE_SIZE, DEVICE_FILE_SIZE - 1, - "/dev/bus/usb/%03d/%03d", uevent->busNum, uevent->devNum) == -1) { - INIT_LOGE("Make usb device node for device [%d : %d]", uevent->busNum, uevent->devNum); - } + if (SplitUsbDeviceNode(uevent, deviceNode) != 0) { + return; } } else if (STARTSWITH(uevent->subsystem, "usb")) { // Other usb devies, do not handle it.