diff --git a/begetd.gni b/begetd.gni new file mode 100644 index 0000000000000000000000000000000000000000..aac68661118b3f8cad1819d4a16ab3b581816e93 --- /dev/null +++ b/begetd.gni @@ -0,0 +1,16 @@ +# 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. + +declare_args() { + param_feature_watcher = true +} diff --git a/services/BUILD.gn b/services/BUILD.gn index 44d84c4edc08908219b9ba4572fc13b7f3943ab5..f16362a71047816e0eab90c55b22c51e9a7554d0 100755 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -92,6 +92,7 @@ if (defined(ohos_lite)) { } } } else { + import("//base/startup/init_lite/begetd.gni") import("//build/ohos.gni") ohos_executable("init") { @@ -179,11 +180,15 @@ if (defined(ohos_lite)) { "//base/startup/init_lite/interfaces/innerkits/socket:libsocket", "//base/startup/init_lite/services/param:param_client", "//base/startup/init_lite/services/param:param_service", - "//base/startup/init_lite/services/param:param_watcher", - "//base/startup/init_lite/services/param:param_watcher.rc", - "//base/startup/init_lite/services/param:param_watcheragent", - "//base/startup/init_lite/services/param/watcher/sa_profile:param_watcher_profile", ] + if (param_feature_watcher) { + deps += [ + "//base/startup/init_lite/services/param/watcher:param_watcher", + "//base/startup/init_lite/services/param/watcher:param_watcher.rc", + "//base/startup/init_lite/services/param/watcher:param_watcheragent", + "//base/startup/init_lite/services/param/watcher/sa_profile:param_watcher_profile", + ] + } } # init etc files group diff --git a/services/param/BUILD.gn b/services/param/BUILD.gn index 0a6e0c338ba7840b0bb571b92dd8f3e861c12943..d3cc33c29e975a395be16bb7f8721e1b9569fc5d 100755 --- a/services/param/BUILD.gn +++ b/services/param/BUILD.gn @@ -17,16 +17,6 @@ declare_args() { param_test = "false" } -ohos_prebuilt_etc("param_watcher.rc") { - if (use_musl) { - source = "watcher/etc/param_watcher.cfg" - } else { - source = "watcher/etc/param_watcher.rc" - } - relative_install_dir = "init" - part_name = "init" -} - ohos_static_library("param_service") { sources = [ "//base/startup/init_lite/services/utils/init_utils.c", @@ -121,88 +111,3 @@ ohos_shared_library("param_client") { ] part_name = "init" } - -ohos_shared_library("param_watcheragent") { - sources = [ - "watcher/agent/watcher.cpp", - "watcher/agent/watcher_manager_kits.cpp", - "watcher/agent/watcher_manager_proxy.cpp", - "watcher/agent/watcher_stub.cpp", - ] - - include_dirs = [ - "include", - "//base/startup/init_lite/services/include/param", - "//base/startup/init_lite/services/param/watcher/include", - "//base/startup/init_lite/services/param/watcher/agent", - "//base/startup/init_lite/services/include", - "//base/startup/init_lite/services/log", - "//base/update/updateservice/interfaces/innerkits/include", - ] - - defines = [ "INIT_AGENT" ] - - deps = [ - "//base/startup/init_lite/services/log:agent_log", - "//base/startup/init_lite/services/param:param_client", - "//third_party/bounds_checking_function:libsec_static", - "//utils/native/base:utils", - ] - - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr_standard:samgr_proxy", - ] - - part_name = "init" -} - -ohos_shared_library("param_watcher") { - sources = [ - "//base/startup/init_lite/services/utils/list.c", - "watcher/proxy/watcher_manager.cpp", - "watcher/proxy/watcher_manager_stub.cpp", - "watcher/proxy/watcher_proxy.cpp", - ] - - include_dirs = [ - "include", - "//base/startup/init_lite/services/include/param", - "//base/startup/init_lite/services/param/watcher/proxy", - "//base/startup/init_lite/services/param/watcher/include", - "//base/startup/init_lite/services/include", - "//base/startup/init_lite/services/log", - "//third_party/libuv/include", - "//third_party/cJSON", - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include", - "//foundation/distributedschedule/safwk/services/safwk/include", - "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk", - "//foundation/distributedschedule/samgr/adapter/interfaces/innerkits/include", - "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include", - ] - - defines = [ - "INIT_AGENT", - "ENABLE_HILOG", - ] - - deps = [ - "//base/startup/init_lite/services/log:agent_log", - "//base/startup/init_lite/services/param:param_client", - "//third_party/bounds_checking_function:libsec_static", - "//utils/native/base:utils", - ] - - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr_standard:samgr_proxy", - ] - install_images = [ "system" ] - part_name = "init" -} diff --git a/services/param/watcher/BUILD.gn b/services/param/watcher/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..52b1fe9e158bb0efc611d8d5cb2e05bb8a89acbc --- /dev/null +++ b/services/param/watcher/BUILD.gn @@ -0,0 +1,108 @@ +# 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/ohos.gni") + +ohos_prebuilt_etc("param_watcher.rc") { + if (use_musl) { + source = "etc/param_watcher.cfg" + } else { + source = "etc/param_watcher.rc" + } + relative_install_dir = "init" + part_name = "init" +} + +ohos_shared_library("param_watcheragent") { + sources = [ + "agent/watcher.cpp", + "agent/watcher_manager_kits.cpp", + "agent/watcher_manager_proxy.cpp", + "agent/watcher_stub.cpp", + ] + + include_dirs = [ + "//base/startup/init_lite/services/param/include", + "//base/startup/init_lite/services/include/param", + "//base/startup/init_lite/services/param/watcher/include", + "//base/startup/init_lite/services/param/watcher/agent", + "//base/startup/init_lite/services/include", + "//base/startup/init_lite/services/log", + "//base/update/updateservice/interfaces/innerkits/include", + ] + + defines = [ "INIT_AGENT" ] + + deps = [ + "//base/startup/init_lite/services/log:agent_log", + "//base/startup/init_lite/services/param:param_client", + "//third_party/bounds_checking_function:libsec_static", + "//utils/native/base:utils", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] + + part_name = "init" +} + +ohos_shared_library("param_watcher") { + sources = [ + "//base/startup/init_lite/services/utils/list.c", + "proxy/watcher_manager.cpp", + "proxy/watcher_manager_stub.cpp", + "proxy/watcher_proxy.cpp", + ] + + include_dirs = [ + "//base/startup/init_lite/services/param/include", + "//base/startup/init_lite/services/include/param", + "//base/startup/init_lite/services/param/watcher/proxy", + "//base/startup/init_lite/services/param/watcher/include", + "//base/startup/init_lite/services/include", + "//base/startup/init_lite/services/log", + "//third_party/libuv/include", + "//third_party/cJSON", + "//utils/native/base/include", + "//utils/system/safwk/native/include", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include", + "//foundation/distributedschedule/safwk/services/safwk/include", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk", + "//foundation/distributedschedule/samgr/adapter/interfaces/innerkits/include", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include", + ] + + defines = [ + "INIT_AGENT", + "ENABLE_HILOG", + ] + + deps = [ + "//base/startup/init_lite/services/log:agent_log", + "//base/startup/init_lite/services/param:param_client", + "//third_party/bounds_checking_function:libsec_static", + "//utils/native/base:utils", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] + install_images = [ "system" ] + part_name = "init" +} diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index d456c342e83d537d3f2e00904b656780bbeb6b4e..f4878cd31f57c742ce9ae4bc4bb33fb2d450eaaf 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -422,7 +422,7 @@ ohos_fuzztest("SystemWatchParameterFuzzTest") { deps = [ "//base/startup/init_lite/services/log:agent_log", "//base/startup/init_lite/services/param:param_client", - "//base/startup/init_lite/services/param:param_watcheragent", + "//base/startup/init_lite/services/param/watcher:param_watcheragent", "//third_party/bounds_checking_function:libsec_static", "//utils/native/base:utils", ] diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index fac7f2f6f161258418047bf7f816a08d392fa9d9..f2414521a296f8e60ab8d72baec04580d9c9d8dc 100755 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -10,6 +10,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import("//base/startup/init_lite/begetd.gni") import("//build/test.gni") config("utest_config") { @@ -71,13 +72,6 @@ ohos_unittest("init_ut") { "//base/startup/init_lite/services/param/trigger/trigger_checker.c", "//base/startup/init_lite/services/param/trigger/trigger_manager.c", "//base/startup/init_lite/services/param/trigger/trigger_processor.c", - "//base/startup/init_lite/services/param/watcher/agent/watcher.cpp", - "//base/startup/init_lite/services/param/watcher/agent/watcher_manager_kits.cpp", - "//base/startup/init_lite/services/param/watcher/agent/watcher_manager_proxy.cpp", - "//base/startup/init_lite/services/param/watcher/agent/watcher_stub.cpp", - "//base/startup/init_lite/services/param/watcher/proxy/watcher_manager.cpp", - "//base/startup/init_lite/services/param/watcher/proxy/watcher_manager_stub.cpp", - "//base/startup/init_lite/services/param/watcher/proxy/watcher_proxy.cpp", "//base/startup/init_lite/services/utils/init_utils.c", "//base/startup/init_lite/services/utils/list.c", "//base/startup/init_lite/ueventd/ueventd.c", @@ -87,6 +81,20 @@ ohos_unittest("init_ut") { "//base/startup/init_lite/ueventd/ueventd_socket.c", ] + if (param_feature_watcher) { + sources += [ + "//base/startup/init_lite/services/param/watcher/agent/watcher.cpp", + "//base/startup/init_lite/services/param/watcher/agent/watcher_manager_kits.cpp", + "//base/startup/init_lite/services/param/watcher/agent/watcher_manager_proxy.cpp", + "//base/startup/init_lite/services/param/watcher/agent/watcher_stub.cpp", + "//base/startup/init_lite/services/param/watcher/proxy/watcher_manager.cpp", + "//base/startup/init_lite/services/param/watcher/proxy/watcher_manager_stub.cpp", + "//base/startup/init_lite/services/param/watcher/proxy/watcher_proxy.cpp", + "param/watcher_agent_unittest.cpp", + "param/watcher_proxy_unittest.cpp", + ] + } + sources += [ "init/cmds_unittest.cpp", "init/init_reboot_unittest.cpp", @@ -100,8 +108,6 @@ ohos_unittest("init_ut") { "param/param_unittest.cpp", "param/selinux_unittest.cpp", "param/trigger_unittest.cpp", - "param/watcher_agent_unittest.cpp", - "param/watcher_proxy_unittest.cpp", "ueventd/ueventd_config_unittest.cpp", ] @@ -152,12 +158,15 @@ ohos_unittest("init_ut") { "PARAM_SUPPORT_DAC", ] - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr_standard:samgr_proxy", - ] + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + if (param_feature_watcher) { + external_deps += [ + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] + } cflags_cc = [ "-fexceptions" ] } diff --git a/ueventd/ueventd.c b/ueventd/ueventd.c index f3379f7f3ad9a272b6a608c7e5c2e196e6e7922d..17e20c92868ade86dc5b67e55670327adeb997eb 100755 --- a/ueventd/ueventd.c +++ b/ueventd/ueventd.c @@ -121,6 +121,7 @@ static void HandleUevent(const struct Uevent *uevent) static void HandleUeventRequired(const struct Uevent *uevent, char **devices, int num) { + const char *deviceName; INIT_ERROR_CHECK(devices != NULL && num > 0, return, "Fault paramters"); if (uevent->action == ACTION_ADD) { ChangeSysAttributePermissions(uevent->syspath); @@ -130,9 +131,16 @@ static void HandleUeventRequired(const struct Uevent *uevent, char **devices, in if (type == SUBSYSTEM_BLOCK) { for (int i = 0; i < num; i++) { if (uevent->partitionName == NULL) { - break; - } - if (strstr(devices[i], uevent->partitionName) != NULL) { + INIT_LOGI("Match with %s for %s", devices[i], uevent->syspath); + deviceName = strstr(devices[i], "/dev/block"); + if (deviceName != NULL) { + deviceName += sizeof("/dev/block") - 1; + if (strstr(uevent->syspath, deviceName) != NULL) { + HandleBlockDeviceEvent(uevent); + break; + } + } + } else if (strstr(devices[i], uevent->partitionName) != NULL) { INIT_LOGI("Handle block device partitionName %s", uevent->partitionName); HandleBlockDeviceEvent(uevent); break;