Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
9a62ede8
S
Startup Init Lite
项目概览
OpenHarmony
/
Startup Init Lite
1 年多 前同步成功
通知
3
Star
37
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Startup Init Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
9a62ede8
编写于
12月 31, 2021
作者:
O
openharmony_ci
提交者:
Gitee
12月 31, 2021
浏览文件
操作
浏览文件
下载
差异文件
!217 fix: add ueventd set device node parameter
Merge pull request !217 from 熊磊/init1230
上级
fc9f339a
59aad7b4
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
140 addition
and
17 deletion
+140
-17
services/BUILD.gn
services/BUILD.gn
+1
-1
ueventd/BUILD.gn
ueventd/BUILD.gn
+15
-11
ueventd/etc/ueventd.config
ueventd/etc/ueventd.config
+1
-1
ueventd/include/ueventd_parameter.h
ueventd/include/ueventd_parameter.h
+21
-0
ueventd/include/ueventd_read_cfg.h
ueventd/include/ueventd_read_cfg.h
+2
-0
ueventd/lite/ueventd_parameter.c
ueventd/lite/ueventd_parameter.c
+22
-0
ueventd/standard/ueventd_parameter.c
ueventd/standard/ueventd_parameter.c
+35
-0
ueventd/ueventd_device_handler.c
ueventd/ueventd_device_handler.c
+15
-0
ueventd/ueventd_read_cfg.c
ueventd/ueventd_read_cfg.c
+27
-3
ueventd/ueventd_socket.c
ueventd/ueventd_socket.c
+1
-1
未找到文件。
services/BUILD.gn
浏览文件 @
9a62ede8
...
...
@@ -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",
]
...
...
ueventd/BUILD.gn
浏览文件 @
9a62ede8
...
...
@@ -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"
...
...
ueventd/etc/ueventd.config
浏览文件 @
9a62ede8
...
...
@@ -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
...
...
ueventd/include/ueventd_parameter.h
0 → 100644
浏览文件 @
9a62ede8
/*
* 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
ueventd/include/ueventd_read_cfg.h
浏览文件 @
9a62ede8
...
...
@@ -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
...
...
ueventd/lite/ueventd_parameter.c
0 → 100644
浏览文件 @
9a62ede8
/*
* 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
;
}
ueventd/standard/ueventd_parameter.c
0 → 100644
浏览文件 @
9a62ede8
/*
* 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
;
}
ueventd/ueventd_device_handler.c
浏览文件 @
9a62ede8
...
...
@@ -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
);
...
...
ueventd/ueventd_read_cfg.c
浏览文件 @
9a62ede8
...
...
@@ -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
))
{
...
...
ueventd/ueventd_socket.c
浏览文件 @
9a62ede8
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录