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/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/param/ohos.para.size b/services/etc/param/ohos.para.size index bde33ab56459e1d674d7d32b7cc36385f5d9b43e..ac602cdac3e4587d785d5f725383a74c16b2922c 100755 --- a/services/etc/param/ohos.para.size +++ b/services/etc/param/ohos.para.size @@ -74,4 +74,4 @@ ro_patchversion_param=20480 ro_runmode_param=20480 sys_shutdown_requested_param=20480 const_telephony_slotCount_param=20480 -persist_sys_debug_on_param=20480 +persist_sys_debug_on_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 8cb594db35434c02a056030cd612db1393429c11..9722a22d86b570762b50ef550245dacbcd3e1286 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_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 c09bbed27682b92c4282d104927ef80e3c8b8cd3..1d9a48a6808a120734b8f259f6f71fbe056f04e5 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/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/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/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/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/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/unittest/BUILD.gn b/test/unittest/BUILD.gn index 00e7d3bad317868a19446dce6a5ddc71fa983f42..38c71982e4cf09703fb7bda24396d7b96a755b81 100755 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -336,7 +336,8 @@ ohos_unittest("init_unittest") { ] defines += [ "_GNU_SOURCE" ] - if (target_cpu == "arm64" || target_cpu == "x86_64" ) { + if (target_cpu == "arm64" || target_cpu == "x86_64" || + target_cpu == "riscv64") { defines += [ "SUPPORT_64BIT" ] } 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/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 c0f6c795bdaf19b8de1703ad13d07e2b1184c582..906b4018206a2b83a473513cc5a0b1232199505c 100644 --- a/ueventd/ueventd_device_handler.c +++ b/ueventd/ueventd_device_handler.c @@ -353,7 +353,7 @@ static char **GetBlockDeviceSymbolLinks(const struct Uevent *uevent) INIT_LOGV("Find a platform device: %s", parent); parent = FindPlatformDeviceName(parent); if (parent != NULL) { - INIT_WARNING_CHECK(linkNum < BLOCKDEVICE_LINKS - 1, links[linkNum] = NULL; + INIT_WARNING_CHECK(linkNum < BLOCKDEVICE_LINKS - 1, free(bus); links[linkNum] = NULL; return links, "Too many links, ignore"); linkNum = BuildDeviceSymbolLinks(links, linkNum, parent, uevent->partitionName, uevent->deviceName); linkNum++;