提交 9a62ede8 编写于 作者: O openharmony_ci 提交者: Gitee

!217 fix: add ueventd set device node parameter

Merge pull request !217 from 熊磊/init1230
......@@ -128,7 +128,7 @@ if (defined(ohos_lite)) {
"//base/startup/init_lite/interfaces/innerkits:libfsmanager_static",
"//base/startup/init_lite/services/log:init_log",
"//base/startup/init_lite/services/param:param_service",
"//base/startup/init_lite/ueventd:libueventd_static",
"//base/startup/init_lite/ueventd:libueventd_ramdisk_static",
"//third_party/bounds_checking_function:libsec_static",
"//third_party/cJSON:cjson_static",
]
......
......@@ -17,6 +17,7 @@ if (defined(ohos_lite)) {
sources = [
"//base/startup/init_lite/services/utils/init_utils.c",
"//base/startup/init_lite/services/utils/list.c",
"//base/startup/init_lite/ueventd/lite/ueventd_parameter.c",
"//base/startup/init_lite/ueventd/ueventd.c",
"//base/startup/init_lite/ueventd/ueventd_device_handler.c",
"//base/startup/init_lite/ueventd/ueventd_firmware_handler.c",
......@@ -67,6 +68,7 @@ if (defined(ohos_lite)) {
"//base/startup/init_lite/ueventd/ueventd_read_cfg.c",
"//base/startup/init_lite/ueventd/ueventd_socket.c",
]
service_ueventd_include = [
"//third_party/bounds_checking_function/include",
"//base/startup/init_lite/services/log",
......@@ -74,38 +76,40 @@ if (defined(ohos_lite)) {
"//base/startup/init_lite/services/utils",
"//base/startup/init_lite/ueventd/include",
]
service_ueventd_deps = [
"//base/startup/init_lite/services/log:init_log",
"//base/startup/init_lite/services/utils:libinit_utils",
"//third_party/bounds_checking_function:libsec_static",
]
group("startup_ueventd") {
deps = [
"//base/startup/init_lite/ueventd:libueventd_static",
"//base/startup/init_lite/ueventd:libueventd_ramdisk_static",
"//base/startup/init_lite/ueventd:ueventd",
"//base/startup/init_lite/ueventd:ueventd.config",
]
}
ohos_static_library("libueventd_static") {
ohos_static_library("libueventd_ramdisk_static") {
sources = service_ueventd_sources
include_dirs = service_ueventd_include
deps = service_ueventd_deps
defines = [ "__RAMDISK__" ]
}
ohos_executable("ueventd") {
sources = [ "//base/startup/init_lite/ueventd/ueventd_main.c" ]
include_dirs = [
"//base/startup/init_lite/ueventd/include",
"//base/startup/init_lite/services/log",
"//base/startup/init_lite/services/include",
sources = service_ueventd_sources
sources += [
"//base/startup/init_lite/ueventd/standard/ueventd_parameter.c",
"//base/startup/init_lite/ueventd/ueventd_main.c",
]
deps = [ "//base/startup/init_lite/ueventd:libueventd_static" ]
include_dirs = service_ueventd_include
include_dirs += [ "//base/startup/init_lite/services/include/param" ]
deps = service_ueventd_deps
deps += [ "//base/startup/init_lite/services/param:param_client" ]
install_images = [
"system",
"updater",
"ramdisk",
]
install_enable = true
part_name = "init"
......
......@@ -12,7 +12,7 @@
# limitations under the License.
[device]
# <device name> <mode> <uid> <gid>
# <device name> <mode> <uid> <gid> <parameter>
/dev/binder 0666 0 0
/dev/input/event0 0660 0 0
/dev/input/event1 0660 0 1004
......
/*
* 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.
*/
#ifndef BASE_STARTUP_INITLITE_UEVENTD_PARAMETER_H
#define BASE_STARTUP_INITLITE_UEVENTD_PARAMETER_H
int SetUeventDeviceParameter(const char *devNode, const char *paramValue);
#endif
......@@ -29,6 +29,7 @@ struct DeviceUdevConf {
mode_t mode;
uid_t uid;
gid_t gid;
const char *parameter;
struct ListNode list;
};
......@@ -53,6 +54,7 @@ void ParseUeventdConfigFile(const char *file);
void GetDeviceNodePermissions(const char *devNode, uid_t *uid, gid_t *gid, mode_t *mode);
void ChangeSysAttributePermissions(const char *sysPath);
int ParseUeventConfig(char *buffer);
struct DeviceUdevConf *GetDeviceUdevConfByDevNode(const char *devNode);
#ifdef __cplusplus
}
#endif
......
/*
* 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.
*/
// lite release not support set parameter.
int SetUeventDeviceParameter(const char *devNode, const char *paramValue)
{
(void)(devNode);
(void)(paramValue);
return 0;
}
/*
* 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.
*/
#include "sys_param.h"
#include "ueventd_read_cfg.h"
#include "ueventd_utils.h"
#define INIT_LOG_TAG "ueventd"
#include "init_log.h"
int SetUeventDeviceParameter(const char *devNode, const char *paramValue)
{
if (INVALIDSTRING(devNode) || INVALIDSTRING(paramValue)) {
return -1;
}
struct DeviceUdevConf *config = GetDeviceUdevConfByDevNode(devNode);
if ((config != NULL) && (config->parameter != NULL)) {
if (SystemSetParameter(config->parameter, paramValue) != 0) {
INIT_LOGE("[uevent][error] set device parameter %s failed", config->parameter);
return -1;
}
}
return 0;
}
......@@ -26,6 +26,9 @@
#include "init_utils.h"
#include "list.h"
#include "ueventd.h"
#ifndef __RAMDISK__
#include "ueventd_parameter.h"
#endif
#include "ueventd_read_cfg.h"
#include "ueventd_utils.h"
#include "securec.h"
......@@ -302,10 +305,22 @@ static void HandleDeviceNode(const struct Uevent *uevent, const char *deviceNode
if (action == ACTION_ADD) {
if (CreateDeviceNode(uevent, deviceNode, symLinks, isBlock) < 0) {
INIT_LOGE("Create device \" %s \" failed", deviceNode);
} else {
#ifndef __RAMDISK__
if (SetUeventDeviceParameter(deviceNode, "added") != 0) {
INIT_LOGE("Set device parameter added failed");
}
#endif
}
} else if (action == ACTION_REMOVE) {
if (RemoveDeviceNode(deviceNode, symLinks) < 0) {
INIT_LOGE("Remove device \" %s \" failed", deviceNode);
} else {
#ifndef __RAMDISK__
if (SetUeventDeviceParameter(deviceNode, "removed") != 0) {
INIT_LOGE("Set device parameter removed failed");
}
#endif
}
} else if (action == ACTION_CHANGE) {
INIT_LOGI("Device %s changed", uevent->syspath);
......
......@@ -44,6 +44,7 @@
#define DEVICE_CONFIG_MODE_NUM 1
#define DEVICE_CONFIG_UID_NUM 2
#define DEVICE_CONFIG_GID_NUM 3
#define DEVICE_CONFIG_PARAM_NUM 4
typedef enum SECTION {
SECTION_INVALID = -1,
......@@ -78,12 +79,12 @@ static int ParseDeviceConfig(char *p)
INIT_LOGD("Parse device config info: %s", p);
char **items = NULL;
int count = -1;
// format: <device node> <mode> <uid> <gid>
const int expectedCount = 4;
// format: <device node> <mode> <uid> <gid> <parameter>
const int expectedCount = 5;
INIT_CHECK_ONLY_ELOG(!INVALIDSTRING(p), "Invalid argument");
items = SplitStringExt(p, " ", &count, expectedCount);
if (count != expectedCount) {
if ((count != expectedCount) && (count != expectedCount - 1)) {
INIT_LOGE("Ignore invalid item: %s", p);
FreeStringVector(items, count);
return 0;
......@@ -102,6 +103,11 @@ static int ParseDeviceConfig(char *p)
"Invalid mode in config file for device node %s. use default mode", config->name);
config->uid = (uid_t)DecodeUid(items[DEVICE_CONFIG_UID_NUM]);
config->gid = (gid_t)DecodeUid(items[DEVICE_CONFIG_GID_NUM]);
if (count == expectedCount) {
config->parameter = strdup(items[DEVICE_CONFIG_PARAM_NUM]); // device parameter
} else {
config->parameter = NULL;
}
ListAddTail(&g_devices, &config->list);
FreeStringVector(items, count);
return 0;
......@@ -335,6 +341,24 @@ bool IsMatch(const char *target, const char *pattern)
return (*p == '\0') ? true : false;
}
struct DeviceUdevConf *GetDeviceUdevConfByDevNode(const char *devNode)
{
if (INVALIDSTRING(devNode)) {
return NULL;
}
struct ListNode *node = NULL;
if (!ListEmpty(g_devices)) {
ForEachListEntry(&g_devices, node) {
struct DeviceUdevConf *config = ListEntry(node, struct DeviceUdevConf, list);
if (IsMatch(devNode, config->name)) {
return config;
}
}
}
return NULL;
}
void GetDeviceNodePermissions(const char *devNode, uid_t *uid, gid_t *gid, mode_t *mode)
{
if (INVALIDSTRING(devNode)) {
......
......@@ -38,7 +38,7 @@ int UeventdSocketInit(void)
int buffSize = UEVENT_SOCKET_BUFF_SIZE;
int on = 1;
if (memset_s(&addr, sizeof(addr), 0, sizeof(addr) != EOK)) {
if (memset_s(&addr, sizeof(addr), 0, sizeof(addr)) != EOK) {
INIT_LOGE("Faild to clear socket address");
return -1;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册