Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
d510c9cd
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d510c9cd
编写于
9月 29, 2021
作者:
S
sun_fan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
init: fix codedex ...
Signed-off-by:
N
sun_fan
<
sun_fan1@hoperun.com
>
上级
ed5f1d2c
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
58 addition
and
65 deletion
+58
-65
services/src/main.c
services/src/main.c
+7
-12
services/utils/init_utils.c
services/utils/init_utils.c
+2
-2
ueventd/ueventd.c
ueventd/ueventd.c
+29
-27
ueventd/ueventd_device_handler.c
ueventd/ueventd_device_handler.c
+13
-11
ueventd/ueventd_firmware_handler.c
ueventd/ueventd_firmware_handler.c
+1
-6
ueventd/ueventd_read_cfg.c
ueventd/ueventd_read_cfg.c
+6
-7
未找到文件。
services/src/main.c
浏览文件 @
d510c9cd
...
...
@@ -74,9 +74,8 @@ int main(int argc, char **argv)
#ifdef OHOS_DEBUG
struct
timespec
tmEnter
;
if
(
clock_gettime
(
CLOCK_REALTIME
,
&
tmEnter
)
!=
0
)
{
INIT_LOGE
(
"main, enter, get time failed! err %d.
\n
"
,
errno
);
}
INIT_CHECK_ONLY_ELOG
(
clock_gettime
(
CLOCK_REALTIME
,
&
tmEnter
)
==
0
,
"main, enter, get time failed! err %d.
\n
"
,
errno
);
#endif // OHOS_DEBUG
if
(
getpid
()
!=
INIT_PROCESS_PID
)
{
...
...
@@ -96,25 +95,21 @@ int main(int argc, char **argv)
#ifdef OHOS_DEBUG
struct
timespec
tmSysInfo
;
if
(
clock_gettime
(
CLOCK_REALTIME
,
&
tmSysInfo
)
!=
0
)
{
INIT_LOGE
(
"main, after sysinfo, get time failed! err %d."
,
errno
);
}
INIT_CHECK_ONLY_ELOG
(
clock_gettime
(
CLOCK_REALTIME
,
&
tmSysInfo
)
==
0
,
"main, after sysinfo, get time failed! err %d."
,
errno
);
#endif // OHOS_DEBUG
ExecuteRcs
();
#ifdef OHOS_DEBUG
struct
timespec
tmRcs
;
if
(
clock_gettime
(
CLOCK_REALTIME
,
&
tmRcs
)
!=
0
)
{
INIT_LOGE
(
"main, after rcs, get time failed! err %d."
,
errno
);
}
INIT_CHECK_ONLY_ELOG
(
clock_gettime
(
CLOCK_REALTIME
,
&
tmRcs
)
==
0
,
"main, after rcs, get time failed! err %d."
,
errno
);
#endif // OHOS_DEBUG
InitReadCfg
();
#ifdef OHOS_DEBUG
struct
timespec
tmCfg
;
if
(
clock_gettime
(
CLOCK_REALTIME
,
&
tmCfg
)
!=
0
)
{
INIT_LOGE
(
"main, get time failed! err %d."
,
errno
);
}
INIT_CHECK_ONLY_ELOG
(
clock_gettime
(
CLOCK_REALTIME
,
&
tmCfg
)
==
0
,
"main, get time failed! err %d."
,
errno
);
#endif // OHOS_DEBUG
#ifdef OHOS_DEBUG
...
...
services/utils/init_utils.c
浏览文件 @
d510c9cd
...
...
@@ -159,7 +159,7 @@ size_t WriteAll(int fd, const char *buffer, size_t size)
const
char
*
p
=
buffer
;
size_t
left
=
size
;
ssize_t
written
=
-
1
;
ssize_t
written
;
while
(
left
>
0
)
{
do
{
...
...
@@ -245,6 +245,6 @@ int StringToInt(const char *str, int defaultValue)
}
errno
=
0
;
int
value
=
(
int
)
strtoul
(
str
,
NULL
,
DECIMAL_BASE
);
return
errno
!=
0
?
defaultValue
:
value
;
return
((
errno
!=
0
)
?
defaultValue
:
value
)
;
}
ueventd/ueventd.c
浏览文件 @
d510c9cd
...
...
@@ -14,6 +14,7 @@
*/
#include "ueventd.h"
#include <dirent.h>
#include <limits.h>
#include <fcntl.h>
...
...
@@ -205,7 +206,7 @@ static void DoTrigger(const char *ueventPath, int sockFd)
if
(
fd
<
0
)
{
INIT_LOGE
(
"Open
\"
%s
\"
failed, err = %d"
,
ueventPath
,
errno
);
}
else
{
ssize_t
n
=
write
(
fd
,
"add
\n
"
,
4
);
ssize_t
n
=
write
(
fd
,
"add
\n
"
,
strlen
(
"add
\n
"
)
);
if
(
n
<
0
)
{
INIT_LOGE
(
"Write
\"
%s
\"
failed, err = %d"
,
ueventPath
,
errno
);
close
(
fd
);
...
...
@@ -222,31 +223,33 @@ static void DoTrigger(const char *ueventPath, int sockFd)
static
void
Trigger
(
const
char
*
path
,
int
sockFd
)
{
DIR
*
dir
=
opendir
(
path
);
if
(
dir
!=
NULL
)
{
struct
dirent
*
dirent
=
NULL
;
while
((
dirent
=
readdir
(
dir
))
!=
NULL
)
{
if
(
dirent
->
d_name
[
0
]
==
'.'
)
{
continue
;
}
if
(
dirent
->
d_type
==
DT_DIR
)
{
char
pathBuffer
[
PATH_MAX
];
if
(
snprintf_s
(
pathBuffer
,
PATH_MAX
,
PATH_MAX
-
1
,
"%s/%s"
,
path
,
dirent
->
d_name
)
==
-
1
)
{
continue
;
}
Trigger
(
pathBuffer
,
sockFd
);
}
else
{
if
(
!
strcmp
(
dirent
->
d_name
,
"uevent"
))
{
char
ueventBuffer
[
PATH_MAX
];
if
(
snprintf_s
(
ueventBuffer
,
PATH_MAX
,
PATH_MAX
-
1
,
"%s/%s"
,
path
,
"uevent"
)
==
-
1
)
{
INIT_LOGW
(
"Cannnot build uevent path under %s"
,
path
);
continue
;
}
DoTrigger
(
ueventBuffer
,
sockFd
);
}
}
}
closedir
(
dir
);
if
(
dir
==
NULL
)
{
return
;
}
struct
dirent
*
dirent
=
NULL
;
while
((
dirent
=
readdir
(
dir
))
!=
NULL
)
{
if
(
dirent
->
d_name
[
0
]
==
'.'
)
{
continue
;
}
if
(
dirent
->
d_type
==
DT_DIR
)
{
char
pathBuffer
[
PATH_MAX
];
if
(
snprintf_s
(
pathBuffer
,
PATH_MAX
,
PATH_MAX
-
1
,
"%s/%s"
,
path
,
dirent
->
d_name
)
==
-
1
)
{
continue
;
}
Trigger
(
pathBuffer
,
sockFd
);
}
else
{
if
(
strcmp
(
dirent
->
d_name
,
"uevent"
)
!=
0
)
{
continue
;
}
char
ueventBuffer
[
PATH_MAX
];
if
(
snprintf_s
(
ueventBuffer
,
PATH_MAX
,
PATH_MAX
-
1
,
"%s/%s"
,
path
,
"uevent"
)
==
-
1
)
{
INIT_LOGW
(
"Cannnot build uevent path under %s"
,
path
);
continue
;
}
DoTrigger
(
ueventBuffer
,
sockFd
);
}
}
closedir
(
dir
);
}
static
void
RetriggerUevent
(
int
sockFd
)
...
...
@@ -263,7 +266,6 @@ int main(int argc, char **argv)
{
char
*
ueventdConfigs
[]
=
{
"/etc/ueventd.config"
,
NULL
};
int
i
=
0
;
int
ret
=
-
1
;
while
(
ueventdConfigs
[
i
]
!=
NULL
)
{
ParseUeventdConfigFile
(
ueventdConfigs
[
i
++
]);
}
...
...
@@ -280,7 +282,7 @@ int main(int argc, char **argv)
while
(
1
)
{
pfd
.
revents
=
0
;
ret
=
poll
(
&
pfd
,
1
,
-
1
);
int
ret
=
poll
(
&
pfd
,
1
,
-
1
);
if
(
ret
<=
0
)
{
continue
;
}
...
...
ueventd/ueventd_device_handler.c
浏览文件 @
d510c9cd
...
...
@@ -174,7 +174,7 @@ static void BuildDeviceSymbolLinks(char **links, int linkNum, const char *parent
INIT_LOGW
(
"Failed set linkNum, links ignore"
);
return
;
}
if
(
parent
==
NULL
||
partitionName
==
NULL
||
deviceName
==
NULL
)
{
if
(
parent
==
NULL
)
{
return
;
}
links
[
linkNum
]
=
calloc
(
sizeof
(
char
),
DEVICE_FILE_SIZE
);
...
...
@@ -230,22 +230,24 @@ static char **GetBlockDeviceSymbolLinks(const struct Uevent *uevent)
// Reverse walk through sysPath, and check subystem file under each directory.
char
*
parent
=
dirname
(
sysPath
);
while
(
parent
!=
NULL
&&
!
STRINGEQUAL
(
parent
,
"/"
)
&&
!
STRINGEQUAL
(
parent
,
"."
))
{
char
subsystem
[
SYSPATH_SIZE
];
char
subsystem
[
SYSPATH_SIZE
]
=
{
0
}
;
if
(
snprintf_s
(
subsystem
,
SYSPATH_SIZE
,
SYSPATH_SIZE
-
1
,
"%s/subsystem"
,
parent
)
==
-
1
)
{
INIT_LOGE
(
"Failed to build subsystem path for device
\"
%s
\"
"
,
uevent
->
syspath
);
return
NULL
;
}
char
bus
[
PATH_MAX
]
=
{
0
};
if
(
Realpath
(
subsystem
,
bus
,
sizeof
(
bus
))
!=
NULL
)
{
if
(
STRINGEQUAL
(
bus
,
"/sys/bus/platform"
))
{
INIT_LOGD
(
"Find a platform device: %s"
,
parent
);
parent
=
FindPlatformDeviceName
(
parent
);
if
(
parent
!=
NULL
)
{
BuildDeviceSymbolLinks
(
links
,
linkNum
,
parent
,
uevent
->
partitionName
,
uevent
->
deviceName
);
}
linkNum
++
;
if
(
Realpath
(
subsystem
,
bus
,
sizeof
(
bus
))
==
NULL
)
{
parent
=
dirname
(
parent
);
continue
;
}
if
(
STRINGEQUAL
(
bus
,
"/sys/bus/platform"
))
{
INIT_LOGD
(
"Find a platform device: %s"
,
parent
);
parent
=
FindPlatformDeviceName
(
parent
);
if
(
parent
!=
NULL
)
{
BuildDeviceSymbolLinks
(
links
,
linkNum
,
parent
,
uevent
->
partitionName
,
uevent
->
deviceName
);
}
linkNum
++
;
}
parent
=
dirname
(
parent
);
}
...
...
@@ -302,7 +304,7 @@ static const char *GetDeviceName(char *sysPath, const char *deviceName)
}
if
(
deviceName
!=
NULL
&&
deviceName
[
0
]
!=
'\0'
)
{
// if device name reported by kernel includes '/', skip it.
//
TODO:
use entire device name reported by kernel
// use entire device name reported by kernel
devName
=
basename
((
char
*
)
deviceName
);
char
*
p
=
strrchr
(
deviceName
,
'/'
);
if
(
p
!=
NULL
)
{
// device name includes slash
...
...
ueventd/ueventd_firmware_handler.c
浏览文件 @
d510c9cd
...
...
@@ -13,17 +13,12 @@
* limitations under the License.
*/
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "ueventd_firmware_handler.h"
#include "ueventd.h"
#define INIT_LOG_TAG "ueventd"
#include "init_log.h"
void
HandleFimwareDeviceEvent
(
const
struct
Uevent
*
uevent
)
{
//
TODO, i
mplement it later.
//
I
mplement it later.
INIT_LOGI
(
"Firmware handler not implemented yet."
);
}
ueventd/ueventd_read_cfg.c
浏览文件 @
d510c9cd
...
...
@@ -16,17 +16,16 @@
#include "ueventd_read_cfg.h"
#include <ctype.h>
#include <limits.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include "init_utils.h"
#include "list.h"
#include "ueventd_utils.h"
#include "securec.h"
#include "ueventd_utils.h"
#define INIT_LOG_TAG "ueventd"
#include "init_log.h"
...
...
@@ -292,7 +291,7 @@ int ParseUeventConfig(char *buffer)
callback
=
funcMapper
[
type
].
func
;
return
0
;
}
return
callback
!=
NULL
?
callback
(
p
)
:
-
1
;
return
((
callback
!=
NULL
)
?
callback
(
p
)
:
-
1
)
;
}
static
void
DoUeventConfigParse
(
char
*
buffer
,
size_t
length
)
...
...
@@ -418,7 +417,7 @@ void ChangeSysAttributePermissions(const char *sysPath)
if
(
config
==
NULL
)
{
return
;
}
char
sysAttr
[
SYSPATH_SIZE
]
=
{};
char
sysAttr
[
SYSPATH_SIZE
]
=
{
0
};
if
(
config
->
sysPath
!=
NULL
&&
config
->
attr
!=
NULL
)
{
if
(
snprintf_s
(
sysAttr
,
SYSPATH_SIZE
,
SYSPATH_SIZE
-
1
,
"/sys%s/%s"
,
config
->
sysPath
,
config
->
attr
)
==
-
1
)
{
INIT_LOGE
(
"Failed to build sys attribute for sys path %s, attr: %s"
,
config
->
sysPath
,
config
->
attr
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录