Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
3b1104c5
S
Startup Init Lite
项目概览
OpenHarmony
/
Startup Init Lite
9 个月 前同步成功
通知
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看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
3b1104c5
编写于
5月 08, 2021
作者:
Z
zhong_ning
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify for updater
上级
a5ca25cb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
72 addition
and
84 deletion
+72
-84
services/src/init_cmds.c
services/src/init_cmds.c
+13
-10
services/src/uevent.c
services/src/uevent.c
+59
-74
未找到文件。
services/src/init_cmds.c
浏览文件 @
3b1104c5
...
...
@@ -326,38 +326,41 @@ static void DoMount(const char* cmdContent)
#define OPTIONS_SIZE 128u
static
void
DoInsmodInternal
(
const
char
*
fileName
,
char
*
secondPtr
,
char
*
restPtr
,
int
flags
)
{
int
fd
=
-
1
;
char
options
[
OPTIONS_SIZE
]
=
{
0
};
if
(
flags
==
0
)
{
// '-f' option
if
(
restPtr
!=
NULL
&&
secondPtr
!=
NULL
)
{
// Reset arugments, combine then all.
if
(
snprintf_s
(
options
,
sizeof
(
options
),
OPTIONS_SIZE
-
1
,
"%s %s"
,
secondPtr
,
restPtr
)
==
-
1
)
{
goto
out
;
return
;
}
}
else
if
(
secondPtr
!=
NULL
)
{
if
(
strncpy_s
(
options
,
OPTIONS_SIZE
-
1
,
secondPtr
,
strlen
(
secondPtr
))
!=
0
)
{
goto
out
;
return
;
}
}
}
else
{
// Only restPtr is option
if
(
restPtr
!=
NULL
)
{
if
(
strncpy_s
(
options
,
OPTIONS_SIZE
-
1
,
restPtr
,
strlen
(
restPtr
))
!=
0
)
{
goto
out
;
return
;
}
}
}
if
(
!
fileName
)
{
goto
out
;
return
;
}
fd
=
open
(
fileName
,
O_RDONLY
|
O_NOFOLLOW
|
O_CLOEXEC
);
char
*
realPath
=
NULL
;
realPath
=
realpath
(
fileName
,
realPath
);
if
(
realPath
==
NULL
)
{
return
;
}
int
fd
=
open
(
realPath
,
O_RDONLY
|
O_NOFOLLOW
|
O_CLOEXEC
);
if
(
fd
<
0
)
{
printf
(
"[Init] failed to open %s: %d
\n
"
,
fileName
,
errno
);
goto
out
;
printf
(
"[Init] failed to open %s: %d
\n
"
,
realPath
,
errno
);
return
;
}
int
rc
=
syscall
(
__NR_finit_module
,
fd
,
options
,
flags
);
if
(
rc
==
-
1
)
{
printf
(
"[Init] finit_module for %s failed: %d
\n
"
,
fileName
,
errno
);
printf
(
"[Init] finit_module for %s failed: %d
\n
"
,
realPath
,
errno
);
}
out:
if
(
fd
>=
0
)
{
close
(
fd
);
}
...
...
services/src/uevent.c
浏览文件 @
3b1104c5
...
...
@@ -102,32 +102,35 @@ static int UeventFD()
return
g_ueventFD
;
}
static
void
DoTrigger
(
DIR
*
dir
)
static
void
DoTrigger
(
DIR
*
dir
,
const
char
*
path
,
int32_t
pathLen
)
{
struct
dirent
*
de
=
NULL
;
int
dfd
=
dirfd
(
dir
);
int
fd
=
openat
(
dfd
,
"uevent"
,
O_WRONLY
);
if
(
pathLen
<
0
)
{
return
;
}
struct
dirent
*
dirent
=
NULL
;
char
ueventPath
[
MAX_BUFFER
];
if
(
snprintf_s
(
ueventPath
,
sizeof
(
ueventPath
),
sizeof
(
ueventPath
)
-
1
,
"%s/uevent"
,
path
)
==
-
1
)
{
return
;
}
int
fd
=
open
(
ueventPath
,
O_WRONLY
);
if
(
fd
>=
0
)
{
write
(
fd
,
"add
\n
"
,
TRIGGER_ADDR_SIZE
);
close
(
fd
);
HandleUevent
();
}
while
((
de
=
readdir
(
dir
))
!=
NULL
)
{
DIR
*
dir2
=
NULL
;
if
(
de
->
d_type
!=
DT_DIR
||
de
->
d_name
[
0
]
==
'.'
)
{
while
((
dirent
=
readdir
(
dir
))
!=
NULL
)
{
if
(
dirent
->
d_name
[
0
]
==
'.'
||
dirent
->
d_type
!=
DT_DIR
)
{
continue
;
}
fd
=
openat
(
dfd
,
de
->
d_name
,
O_RDONLY
|
O_DIRECTORY
)
;
if
(
fd
<
0
)
{
char
tmpPath
[
MAX_BUFFER
]
;
if
(
snprintf_s
(
tmpPath
,
sizeof
(
tmpPath
),
sizeof
(
tmpPath
)
-
1
,
"%s/%s"
,
path
,
dirent
->
d_name
)
==
-
1
)
{
continue
;
}
dir2
=
fdopendir
(
fd
);
if
(
dir2
==
NULL
)
{
close
(
fd
);
}
else
{
DoTrigger
(
dir2
);
DIR
*
dir2
=
opendir
(
tmpPath
);
if
(
dir2
)
{
DoTrigger
(
dir2
,
tmpPath
,
strlen
(
tmpPath
));
closedir
(
dir2
);
}
}
...
...
@@ -137,7 +140,7 @@ void Trigger(const char *sysPath)
{
DIR
*
dir
=
opendir
(
sysPath
);
if
(
dir
)
{
DoTrigger
(
dir
);
DoTrigger
(
dir
,
sysPath
,
strlen
(
sysPath
)
);
closedir
(
dir
);
}
}
...
...
@@ -197,7 +200,6 @@ ssize_t ReadUevent(int fd, void *buf, size_t len)
struct
iovec
iov
=
{
buf
,
len
};
struct
sockaddr_nl
addr
;
char
control
[
CMSG_SPACE
(
sizeof
(
struct
ucred
))];
uid_t
uid
=
-
1
;
struct
msghdr
hdr
=
{
&
addr
,
sizeof
(
addr
),
...
...
@@ -213,23 +215,24 @@ ssize_t ReadUevent(int fd, void *buf, size_t len)
}
struct
cmsghdr
*
cMsg
=
CMSG_FIRSTHDR
(
&
hdr
);
if
(
cMsg
==
NULL
||
cMsg
->
cmsg_type
!=
SCM_CREDENTIALS
)
{
goto
out
;
bzero
(
buf
,
len
);
errno
=
-
EIO
;
return
n
;
}
struct
ucred
*
cRed
=
(
struct
ucred
*
)
CMSG_DATA
(
cMsg
);
uid
=
cRed
->
uid
;
if
(
uid
!=
0
)
{
goto
out
;
if
(
cRed
->
uid
!=
0
)
{
bzero
(
buf
,
len
);
errno
=
-
EIO
;
return
n
;
}
if
(
addr
.
nl_groups
==
0
||
addr
.
nl_pid
!=
0
)
{
/* ignoring non-kernel or unicast netlink message */
goto
out
;
bzero
(
buf
,
len
);
errno
=
-
EIO
;
return
n
;
}
return
n
;
out:
bzero
(
buf
,
len
);
errno
=
-
EIO
;
return
n
;
}
...
...
@@ -305,22 +308,19 @@ static struct PlatformNode *FindPlatformDevice(const char *path)
return
NULL
;
}
static
void
Sanitize
(
char
*
s
)
static
void
CheckValidPartitionName
(
char
*
partitionName
)
{
const
char
*
accept
=
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789"
"_-."
;
if
(
!
s
)
{
const
char
*
supportPartition
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-"
;
if
(
!
partitionName
)
{
return
;
}
for
(;
*
s
;
s
++
)
{
s
+=
strspn
(
s
,
accept
);
if
(
*
s
)
{
*
s
=
'_'
;
for
(
size_t
i
=
0
;
i
<
strlen
(
partitionName
);
i
++
)
{
int
len
=
strspn
(
partitionName
,
supportPartition
);
partitionName
+=
len
;
i
=
len
;
if
(
*
partitionName
)
{
*
partitionName
=
'_'
;
}
}
}
...
...
@@ -350,7 +350,7 @@ static char **ParsePlatformBlockDevice(const struct Uevent *uevent)
}
if
(
uevent
->
partitionName
)
{
p
=
strdup
(
uevent
->
partitionName
);
Sanitiz
e
(
p
);
CheckValidPartitionNam
e
(
p
);
if
(
strcmp
(
uevent
->
partitionName
,
p
))
{
printf
(
"Linking partition '%s' as '%s'
\n
"
,
uevent
->
partitionName
,
p
);
}
...
...
@@ -594,16 +594,6 @@ static const char *ParseDeviceName(const struct Uevent *uevent, unsigned int len
return
name
;
}
static
void
FindCharEnd
(
const
char
*
parent
)
{
while
(
*++
parent
)
{
if
(
*
parent
==
'/'
)
{
return
;
}
}
return
;
}
static
char
**
GetCharacterDeviceSymlinks
(
const
struct
Uevent
*
uevent
)
{
char
*
slash
=
NULL
;
...
...
@@ -625,33 +615,28 @@ static char **GetCharacterDeviceSymlinks(const struct Uevent *uevent)
goto
err
;
}
if
(
!
strncmp
(
parent
,
"/usb"
,
DEV_USB
))
{
/* skip root hub name and device. use device interface */
FindCharEnd
(
parent
);
if
(
*
parent
)
{
FindCharEnd
(
parent
);
}
if
(
!*
parent
)
{
goto
err
;
}
slash
=
strchr
(
++
parent
,
'/'
);
if
(
!
slash
)
{
goto
err
;
}
width
=
slash
-
parent
;
if
(
width
<=
0
)
{
goto
err
;
}
if
(
strncmp
(
parent
,
"/usb"
,
DEV_USB
))
{
goto
err
;
}
/* skip root hub name and device. use device interface */
if
(
!*
parent
)
{
goto
err
;
}
slash
=
strchr
(
++
parent
,
'/'
);
if
(
!
slash
)
{
goto
err
;
}
width
=
slash
-
parent
;
if
(
width
<=
0
)
{
goto
err
;
}
if
(
asprintf
(
&
links
[
linkNum
],
"/dev/usb/%s%.*s"
,
uevent
->
subsystem
,
width
,
parent
)
>
0
)
{
linkNum
++
;
}
else
{
links
[
linkNum
]
=
NULL
;
}
mkdir
(
"/dev/usb"
,
DEFAULT_DIR_MODE
);
if
(
asprintf
(
&
links
[
linkNum
],
"/dev/usb/%s%.*s"
,
uevent
->
subsystem
,
width
,
parent
)
>
0
)
{
linkNum
++
;
}
else
{
goto
err
;
links
[
linkNum
]
=
NULL
;
}
mkdir
(
"/dev/usb"
,
DEFAULT_DIR_MODE
);
return
links
;
err:
free
(
links
);
...
...
@@ -690,11 +675,11 @@ static int HandleUsbDevice(const struct Uevent *event, char *devpath, int len)
/* build directories */
MakeDir
(
"/dev/bus"
,
DEFAULT_DIR_MODE
);
MakeDir
(
"/dev/bus/usb"
,
DEFAULT_DIR_MODE
);
if
(
snprintf_s
(
devpath
,
len
,
len
,
"/dev/bus/usb/%03d"
,
busId
)
==
-
1
)
{
if
(
snprintf_s
(
devpath
,
len
,
len
-
1
,
"/dev/bus/usb/%03d"
,
busId
)
==
-
1
)
{
return
-
1
;
}
MakeDir
(
devpath
,
DEFAULT_DIR_MODE
);
if
(
snprintf_s
(
devpath
,
len
,
len
,
"/dev/bus/usb/%03d/%03d"
,
busId
,
if
(
snprintf_s
(
devpath
,
len
,
len
-
1
,
"/dev/bus/usb/%03d/%03d"
,
busId
,
deviceId
)
==
-
1
)
{
return
-
1
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录