Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
364f1581
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看板
提交
364f1581
编写于
11月 27, 2021
作者:
X
xionglei6
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
init: fix codedex
Signed-off-by:
N
xionglei6
<
xionglei6@huawei.com
>
上级
7ee6dc2b
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
57 addition
and
29 deletion
+57
-29
interfaces/innerkits/fs_manager/fs_manager_log.c
interfaces/innerkits/fs_manager/fs_manager_log.c
+6
-2
interfaces/innerkits/fs_manager/fstab.c
interfaces/innerkits/fs_manager/fstab.c
+5
-4
services/cmds/misc/misc_daemon.cpp
services/cmds/misc/misc_daemon.cpp
+9
-2
services/init/init_common_cmds.c
services/init/init_common_cmds.c
+5
-6
services/init/init_config.c
services/init/init_config.c
+1
-1
services/init/init_service_manager.c
services/init/init_service_manager.c
+6
-1
services/init/standard/init_mount.c
services/init/standard/init_mount.c
+1
-1
services/init/standard/init_mount.h
services/init/standard/init_mount.h
+1
-1
services/init/standard/init_reboot.c
services/init/standard/init_reboot.c
+6
-7
services/init/standard/switch_root.c
services/init/standard/switch_root.c
+16
-3
ueventd/ueventd_socket.c
ueventd/ueventd_socket.c
+1
-1
未找到文件。
interfaces/innerkits/fs_manager/fs_manager_log.c
浏览文件 @
364f1581
...
...
@@ -152,8 +152,12 @@ void FsManagerLogInit(LogTarget target, const char *fileName)
break
;
case
LOG_TO_FILE
:
if
(
fileName
!=
NULL
&&
*
fileName
!=
'\0'
)
{
g_logFile
=
fopen
(
fileName
,
"a+"
);
setbuf
(
g_logFile
,
NULL
);
char
*
realPath
=
GetRealPath
(
fileName
);
if
(
realPath
!=
NULL
)
{
g_logFile
=
fopen
(
realPath
,
"a+"
);
setbuf
(
g_logFile
,
NULL
);
free
(
realPath
);
}
// Do not check return values. The log writte function will do this.
}
g_logFunc
=
FsManagerLogToFile
;
...
...
interfaces/innerkits/fs_manager/fstab.c
浏览文件 @
364f1581
...
...
@@ -191,12 +191,13 @@ Fstab *ReadFstabFromFile(const char *file, bool procMounts)
ssize_t
readn
=
0
;
Fstab
*
fstab
=
NULL
;
if
(
file
==
NULL
)
{
char
*
realPath
=
GetRealPath
(
file
);
if
(
realPath
==
NULL
)
{
FSMGR_LOGE
(
"Invalid file"
);
return
NULL
;
}
FILE
*
fp
=
fopen
(
file
,
"r"
);
FILE
*
fp
=
fopen
(
realPath
,
"r"
);
free
(
realPath
);
if
(
fp
==
NULL
)
{
FSMGR_LOGE
(
"Open %s failed, err = %d"
,
file
,
errno
);
return
NULL
;
...
...
@@ -250,7 +251,7 @@ FstabItem *FindFstabItemForMountPoint(Fstab fstab, const char *mp)
FstabItem
*
item
=
NULL
;
if
(
mp
!=
NULL
)
{
for
(
item
=
fstab
.
head
;
item
!=
NULL
;
item
=
item
->
next
)
{
if
(
strcmp
(
item
->
mountPoint
,
mp
)
==
0
)
{
if
(
(
item
->
mountPoint
!=
NULL
)
&&
(
strcmp
(
item
->
mountPoint
,
mp
)
==
0
)
)
{
break
;
}
}
...
...
services/cmds/misc/misc_daemon.cpp
浏览文件 @
364f1581
...
...
@@ -55,6 +55,7 @@ static std::string GetMiscDevicePath()
FstabItem
*
misc
=
FindFstabItemForMountPoint
(
*
fstab
,
"/misc"
);
if
(
misc
==
nullptr
)
{
std
::
cout
<<
"Cannot find misc partition from fstab
\n
"
;
ReleaseFstab
(
fstab
);
return
miscDev
;
}
miscDev
=
misc
->
deviceName
;
...
...
@@ -86,22 +87,27 @@ static void WriteLogoContent(int fd, const std::string &logoPath, uint32_t size)
std
::
cout
<<
"path is null or size illegal
\n
"
;
return
;
}
FILE
*
rgbFile
=
fopen
(
logoPath
.
c_str
(),
"rb"
);
FILE
*
rgbFile
=
fopen
(
logoPath
.
c_str
(),
"rb"
);
if
(
rgbFile
==
nullptr
)
{
std
::
cout
<<
"cannot find pic file
\n
"
;
return
;
}
char
*
buffer
=
(
char
*
)
malloc
(
size
);
char
*
buffer
=
(
char
*
)
malloc
(
size
);
if
(
buffer
==
nullptr
)
{
(
void
)
fclose
(
rgbFile
);
return
;
}
uint32_t
ret
=
fread
(
buffer
,
1
,
size
,
rgbFile
);
if
(
ret
<
0
)
{
(
void
)
fclose
(
rgbFile
);
free
(
buffer
);
return
;
}
ret
=
write
(
fd
,
buffer
,
size
);
if
(
ret
!=
size
)
{
(
void
)
fclose
(
rgbFile
);
free
(
buffer
);
return
;
}
...
...
@@ -194,6 +200,7 @@ static void WriteLogoToMisc(const std::string &logoPath)
int
fd1
=
open
(
miscDev
.
c_str
(),
O_RDWR
|
O_CLOEXEC
,
S_IRUSR
|
S_IWUSR
|
S_IRGRP
|
S_IROTH
);
if
(
lseek
(
fd1
,
addrOffset
*
BLOCK_SZIE_1
,
SEEK_SET
)
<
0
)
{
std
::
cout
<<
"Failed to seek file
\n
"
;
close
(
fd1
);
return
;
}
...
...
services/init/init_common_cmds.c
浏览文件 @
364f1581
...
...
@@ -56,6 +56,7 @@ static char *AddOneArg(const char *param, size_t paramLen)
char
*
BuildStringFromCmdArg
(
const
struct
CmdArgs
*
ctx
,
int
startIndex
)
{
INIT_ERROR_CHECK
(
ctx
!=
NULL
,
return
NULL
,
"Failed to get cmd args "
);
char
*
options
=
(
char
*
)
calloc
(
1
,
OPTIONS_SIZE
+
1
);
INIT_ERROR_CHECK
(
options
!=
NULL
,
return
NULL
,
"Failed to get memory "
);
options
[
0
]
=
'\0'
;
...
...
@@ -336,7 +337,7 @@ static int GetMountFlag(unsigned long *mountflag, const char *targetStr, const c
INIT_CHECK_RETURN_VALUE
(
targetStr
!=
NULL
&&
mountflag
!=
NULL
,
0
);
struct
{
char
*
flagName
;
int
value
;
unsigned
long
value
;
}
mountFlagMap
[]
=
{
{
"noatime"
,
MS_NOATIME
},
{
"noexec"
,
MS_NOEXEC
},
...
...
@@ -416,18 +417,16 @@ static void DoWrite(const struct CmdArgs *ctx)
int
fd
=
-
1
;
if
(
realPath
!=
NULL
)
{
fd
=
open
(
realPath
,
O_WRONLY
|
O_CREAT
|
O_NOFOLLOW
|
O_CLOEXEC
,
S_IRUSR
|
S_IWUSR
);
free
(
realPath
);
realPath
=
NULL
;
}
else
{
fd
=
open
(
ctx
->
argv
[
0
],
O_WRONLY
|
O_CREAT
|
O_NOFOLLOW
|
O_CLOEXEC
,
S_IRUSR
|
S_IWUSR
);
}
if
(
fd
>=
0
)
{
size_t
ret
=
write
(
fd
,
ctx
->
argv
[
1
],
strlen
(
ctx
->
argv
[
1
]));
INIT_CHECK_ONLY_ELOG
(
ret
>=
0
,
"DoWrite: write to file %s failed: %d"
,
ctx
->
argv
[
0
],
errno
);
close
(
fd
);
}
if
(
realPath
!=
NULL
)
{
free
(
realPath
);
}
realPath
=
NULL
;
close
(
fd
);
}
static
void
DoRmdir
(
const
struct
CmdArgs
*
ctx
)
...
...
services/init/init_config.c
浏览文件 @
364f1581
...
...
@@ -50,7 +50,7 @@ static int ParseInitCfg(const char *configFile, void *context)
static
void
ParseAllImports
(
const
cJSON
*
root
)
{
char
*
tmpParamValue
=
malloc
(
PARAM_VALUE_LEN_MAX
+
1
);
char
*
tmpParamValue
=
calloc
(
sizeof
(
char
),
PARAM_VALUE_LEN_MAX
+
1
);
INIT_ERROR_CHECK
(
tmpParamValue
!=
0
,
return
,
"Failed to alloc memory for param"
);
cJSON
*
importAttr
=
cJSON_GetObjectItemCaseSensitive
(
root
,
"import"
);
...
...
services/init/init_service_manager.c
浏览文件 @
364f1581
...
...
@@ -326,6 +326,7 @@ static int AddServiceSocket(cJSON *json, Service *service)
sockopt
->
gid
=
DecodeUid
(
opt
[
SERVICE_SOCK_GID
]);
if
(
sockopt
->
uid
==
(
uid_t
)
-
1
||
sockopt
->
gid
==
(
uid_t
)
-
1
)
{
free
(
sockopt
);
sockopt
=
NULL
;
INIT_LOGE
(
"Invalid uid %d or gid %d"
,
sockopt
->
uid
,
sockopt
->
gid
);
return
SERVICE_FAILURE
;
}
...
...
@@ -399,6 +400,7 @@ static int AddServiceFile(cJSON *json, Service *service)
fileOpt
->
gid
=
DecodeUid
(
opt
[
SERVICE_FILE_GID
]);
if
(
fileOpt
->
uid
==
(
uid_t
)
-
1
||
fileOpt
->
gid
==
(
gid_t
)
-
1
)
{
free
(
fileOpt
);
fileOpt
=
NULL
;
INIT_LOGE
(
"Invalid uid %d or gid %d"
,
fileOpt
->
uid
,
fileOpt
->
gid
);
return
SERVICE_FAILURE
;
}
...
...
@@ -641,10 +643,13 @@ Service *GetServiceByPid(pid_t pid)
Service
*
GetServiceByName
(
const
char
*
servName
)
{
INIT_ERROR_CHECK
(
servName
!=
NULL
,
return
NULL
,
"Failed get servName"
);
ListNode
*
node
=
g_serviceSpace
.
services
.
next
;
while
(
node
!=
&
g_serviceSpace
.
services
)
{
Service
*
service
=
ListEntry
(
node
,
Service
,
node
);
INIT_CHECK_RETURN_VALUE
(
strcmp
(
service
->
name
,
servName
)
!=
0
,
service
);
if
((
service
!=
NULL
)
&&
(
service
->
name
!=
NULL
))
{
INIT_CHECK_RETURN_VALUE
(
strcmp
(
service
->
name
,
servName
)
!=
0
,
service
);
}
node
=
node
->
next
;
}
return
NULL
;
...
...
services/init/standard/init_mount.c
浏览文件 @
364f1581
...
...
@@ -18,7 +18,7 @@
#include "init_log.h"
#include "securec.h"
int
MountRequriedPartitions
(
Fstab
*
fstab
)
int
MountRequriedPartitions
(
const
Fstab
*
fstab
)
{
INIT_ERROR_CHECK
(
fstab
!=
NULL
,
return
-
1
,
"Failed fstab is NULL"
);
int
rc
=
-
1
;
...
...
services/init/standard/init_mount.h
浏览文件 @
364f1581
...
...
@@ -23,7 +23,7 @@
extern
"C"
{
#endif
#endif
int
MountRequriedPartitions
(
Fstab
*
fstab
);
int
MountRequriedPartitions
(
const
Fstab
*
fstab
);
#ifdef __cplusplus
#if __cplusplus
}
...
...
services/init/standard/init_reboot.c
浏览文件 @
364f1581
...
...
@@ -38,16 +38,16 @@ static int RBMiscWriteUpdaterMessage(const char *path, const struct RBMiscUpdate
INIT_CHECK_RETURN_VALUE
(
realPath
!=
NULL
,
-
1
);
int
ret
=
0
;
FILE
*
fp
=
fopen
(
realPath
,
"rb+"
);
free
(
realPath
);
realPath
=
NULL
;
if
(
fp
!=
NULL
)
{
size_t
writeLen
=
fwrite
(
boot
,
sizeof
(
struct
RBMiscUpdateMessage
),
1
,
fp
);
INIT_ERROR_CHECK
(
writeLen
==
1
,
ret
=
-
1
,
"Failed to write misc for reboot"
);
(
void
)
fclose
(
fp
);
}
else
{
ret
=
-
1
;
INIT_LOGE
(
"Failed to open %s"
,
path
);
}
free
(
realPath
);
realPath
=
NULL
;
(
void
)
fclose
(
fp
);
return
ret
;
}
...
...
@@ -57,17 +57,16 @@ static int RBMiscReadUpdaterMessage(const char *path, struct RBMiscUpdateMessage
INIT_CHECK_RETURN_VALUE
(
realPath
!=
NULL
,
-
1
);
int
ret
=
0
;
FILE
*
fp
=
fopen
(
realPath
,
"rb"
);
free
(
realPath
);
realPath
=
NULL
;
if
(
fp
!=
NULL
)
{
size_t
readLen
=
fread
(
boot
,
1
,
sizeof
(
struct
RBMiscUpdateMessage
),
fp
);
INIT_ERROR_CHECK
(
readLen
>
0
,
ret
=
-
1
,
"Failed to read misc for reboot"
);
(
void
)
fclose
(
fp
);
}
else
{
ret
=
-
1
;
INIT_LOGE
(
"Failed to open %s"
,
path
);
}
free
(
realPath
);
realPath
=
NULL
;
(
void
)
fclose
(
fp
);
return
ret
;
}
...
...
services/init/standard/switch_root.c
浏览文件 @
364f1581
...
...
@@ -135,6 +135,15 @@ static int MountToNewTarget(const char *target)
return
0
;
}
static
void
FreeRootDir
(
DIR
*
oldRoot
,
dev_t
dev
)
{
if
(
oldRoot
!=
NULL
)
{
FreeOldRoot
(
oldRoot
,
dev
);
closedir
(
oldRoot
);
oldRoot
=
NULL
;
}
}
// Switch root from ramdisk to system
int
SwitchRoot
(
const
char
*
newRoot
)
{
...
...
@@ -157,35 +166,39 @@ int SwitchRoot(const char *newRoot)
struct
stat
newRootStat
=
{};
if
(
stat
(
newRoot
,
&
newRootStat
)
!=
0
)
{
INIT_LOGE
(
"Failed to get new root
\"
%s
\"
stat"
,
newRoot
);
FreeRootDir
(
oldRoot
,
oldRootStat
.
st_dev
);
return
-
1
;
}
if
(
oldRootStat
.
st_dev
==
newRootStat
.
st_dev
)
{
INIT_LOGW
(
"Try to switch root in same device, skip switching root"
);
FreeRootDir
(
oldRoot
,
oldRootStat
.
st_dev
);
return
0
;
}
if
(
MountToNewTarget
(
newRoot
)
<
0
)
{
INIT_LOGE
(
"Failed to move mount to new root
\"
%s
\"
stat"
,
newRoot
);
FreeRootDir
(
oldRoot
,
oldRootStat
.
st_dev
);
return
-
1
;
}
// OK, we've done move mount.
// Now mount new root.
if
(
chdir
(
newRoot
)
<
0
)
{
INIT_LOGE
(
"Failed to change directory to %s, err = %d"
,
newRoot
,
errno
);
FreeRootDir
(
oldRoot
,
oldRootStat
.
st_dev
);
return
-
1
;
}
if
(
mount
(
newRoot
,
"/"
,
NULL
,
MS_MOVE
,
NULL
)
<
0
)
{
INIT_LOGE
(
"Failed to mount moving %s to %s, err = %d"
,
newRoot
,
"/"
,
errno
);
FreeRootDir
(
oldRoot
,
oldRootStat
.
st_dev
);
return
-
1
;
}
if
(
chroot
(
"."
)
<
0
)
{
INIT_LOGE
(
"Failed to change root directory"
);
FreeRootDir
(
oldRoot
,
oldRootStat
.
st_dev
);
return
-
1
;
}
FreeOldRoot
(
oldRoot
,
oldRootStat
.
st_dev
);
closedir
(
oldRoot
);
oldRoot
=
NULL
;
FreeRootDir
(
oldRoot
,
oldRootStat
.
st_dev
);
return
0
;
}
ueventd/ueventd_socket.c
浏览文件 @
364f1581
...
...
@@ -66,7 +66,7 @@ int UeventdSocketInit(void)
ssize_t
ReadUeventMessage
(
int
sockFd
,
char
*
buffer
,
size_t
length
)
{
ssize_t
n
=
-
1
;
struct
msghdr
msghdr
;
struct
msghdr
msghdr
=
{}
;
struct
iovec
iov
;
struct
sockaddr_nl
addr
;
char
credMsg
[
CMSG_SPACE
(
sizeof
(
struct
ucred
))];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录