Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
284caa22
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看板
提交
284caa22
编写于
7月 23, 2021
作者:
S
sun_fan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
init: modify code style
Signed-off-by:
N
sun_fan
<
sun_fan1@hoperun.com
>
上级
d5437075
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
44 addition
and
28 deletion
+44
-28
services/include/init_cmds.h
services/include/init_cmds.h
+1
-1
services/log/init_log.c
services/log/init_log.c
+1
-1
services/src/device.c
services/src/device.c
+2
-2
services/src/init_cmds.c
services/src/init_cmds.c
+4
-4
services/src/init_import.c
services/src/init_import.c
+3
-0
services/src/init_reboot.c
services/src/init_reboot.c
+1
-1
services/src/init_service.c
services/src/init_service.c
+9
-1
services/src/init_service_manager.c
services/src/init_service_manager.c
+19
-14
services/src/init_service_socket.c
services/src/init_service_socket.c
+1
-1
services/src/init_utils.c
services/src/init_utils.c
+3
-3
未找到文件。
services/include/init_cmds.h
浏览文件 @
284caa22
...
...
@@ -50,7 +50,7 @@ struct CmdArgs {
char
**
argv
;
};
int
GetParamValue
(
char
*
symValue
,
char
*
paramValue
,
unsigned
int
paramLen
);
int
GetParamValue
(
c
onst
c
har
*
symValue
,
char
*
paramValue
,
unsigned
int
paramLen
);
struct
CmdArgs
*
GetCmd
(
const
char
*
cmdContent
,
const
char
*
delim
,
int
argsCount
);
void
FreeCmd
(
struct
CmdArgs
**
cmd
);
...
...
services/log/init_log.c
浏览文件 @
284caa22
...
...
@@ -53,7 +53,7 @@ void InitToHiLog(const char *tag, LogLevel logLevel, const char *fmt, ...)
return
;
}
if
(
tag
==
NULL
)
{
return
;
tag
=
"Init"
;
}
va_list
list
;
va_start
(
list
,
fmt
);
...
...
services/src/device.c
浏览文件 @
284caa22
...
...
@@ -22,8 +22,8 @@
#include <unistd.h>
#include "init_log.h"
#define DEFAULT_RW_MODE
0666
#define DEFAULT_NO_AUTHORITY_MODE
0600
#define DEFAULT_RW_MODE
S_IRUSR | S_IWUSR | S_IRGRP | S_IRGRP | S_IROTH | S_IWOTH
#define DEFAULT_NO_AUTHORITY_MODE
S_IWUSR | S_IRUSR
#define DEVICE_ID_THIRD 3
#define DEVICE_ID_EIGHTH 8
#define DEVICE_ID_NINTH 9
...
...
services/src/init_cmds.c
浏览文件 @
284caa22
...
...
@@ -42,7 +42,7 @@
#include "init_utils.h"
#include "securec.h"
#define DEFAULT_DIR_MODE
0755
// mkdir, default mode
#define DEFAULT_DIR_MODE
S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH | S_IROTH
// mkdir, default mode
#define SPACES_CNT_IN_CMD_MAX 10 // mount, max number of spaces in cmdline
#define SPACES_CNT_IN_CMD_MIN 2 // mount, min number of spaces in cmdline
...
...
@@ -88,7 +88,7 @@ static const char* g_supportedCmds[] = {
};
#ifndef OHOS_LITE
int
GetParamValue
(
char
*
symValue
,
char
*
paramValue
,
unsigned
int
paramLen
)
int
GetParamValue
(
c
onst
c
har
*
symValue
,
char
*
paramValue
,
unsigned
int
paramLen
)
{
if
((
symValue
==
NULL
)
||
(
paramValue
==
NULL
)
||
(
paramLen
==
0
))
{
return
-
1
;
...
...
@@ -143,7 +143,7 @@ int GetParamValue(char *symValue, char *paramValue, unsigned int paramLen)
}
#else
// For ite ohos, do not support parameter operation. just do string copy
inline
int
GetParamValue
(
char
*
symValue
,
char
*
paramValue
,
unsigned
int
paramLen
)
inline
int
GetParamValue
(
c
onst
c
har
*
symValue
,
char
*
paramValue
,
unsigned
int
paramLen
)
{
return
(
strncpy_s
(
paramValue
,
paramLen
,
symValue
,
strlen
(
symValue
))
==
EOK
)
?
0
:
-
1
;
}
...
...
@@ -777,7 +777,7 @@ static void DoLoadCfg(const char *path)
return
;
}
while
(
fgets
(
buf
,
LOADCFG_BUF_SIZE
,
fp
)
!=
NULL
&&
maxLoop
<
LOADCFG_MAX_LOOP
)
{
while
(
fgets
(
buf
,
LOADCFG_BUF_SIZE
-
1
,
fp
)
!=
NULL
&&
maxLoop
<
LOADCFG_MAX_LOOP
)
{
maxLoop
++
;
len
=
strlen
(
buf
);
if
(
len
<
1
)
{
...
...
services/src/init_import.c
浏览文件 @
284caa22
...
...
@@ -29,6 +29,9 @@ static int ExtractCfgFile(char **cfgFile, char *content)
return
-
1
;
}
size_t
cfgFileLen
=
strlen
(
content
)
+
MAX_PARAM_VALUE_LEN
+
1
;
if
(
cfgFileLen
<=
0
)
{
return
-
1
;
}
if
((
*
cfgFile
=
malloc
(
cfgFileLen
))
==
NULL
)
{
INIT_LOGW
(
"Failed to allocate memory to import cfg file. err = %d"
,
errno
);
return
-
1
;
...
...
services/src/init_reboot.c
浏览文件 @
284caa22
...
...
@@ -113,7 +113,7 @@ static int GetMountStatusForMountPoint(const char *mountPoint)
return
1
;
}
while
(
fgets
(
buffer
,
sizeof
(
buffer
),
fp
)
!=
NULL
)
{
while
(
fgets
(
buffer
,
sizeof
(
buffer
)
-
1
,
fp
)
!=
NULL
)
{
n
=
strlen
(
buffer
);
if
(
buffer
[
n
-
1
]
==
'\n'
)
{
buffer
[
n
-
1
]
=
'\0'
;
...
...
services/src/init_service.c
浏览文件 @
284caa22
...
...
@@ -200,14 +200,22 @@ int ServiceStart(Service *service)
if
(
service
->
writepidFiles
[
i
]
==
NULL
)
{
continue
;
}
FILE
*
fd
=
fopen
(
service
->
writepidFiles
[
i
],
"wb"
);
char
*
realPath
=
realpath
(
service
->
writepidFiles
[
i
],
NULL
);
if
(
realPath
==
NULL
)
{
continue
;
}
FILE
*
fd
=
fopen
(
realPath
,
"wb"
);
if
(
fd
==
NULL
)
{
INIT_LOGE
(
"start service writepidFiles %s invalid."
,
service
->
writepidFiles
[
i
]);
free
(
realPath
);
realPath
=
NULL
;
continue
;
}
if
(
fwrite
(
pidString
,
1
,
strlen
(
pidString
),
fd
)
!=
strlen
(
pidString
))
{
INIT_LOGE
(
"start service writepid error.file:%s pid:%s"
,
service
->
writepidFiles
[
i
],
pidString
);
}
free
(
realPath
);
realPath
=
NULL
;
fclose
(
fd
);
INIT_LOGE
(
"ServiceStart writepid filename=%s, childPid=%s, ok"
,
service
->
writepidFiles
[
i
],
pidString
);
...
...
services/src/init_service_manager.c
浏览文件 @
284caa22
...
...
@@ -178,14 +178,12 @@ static int GetWritepidStrings(const cJSON *curArrItem, Service *curServ)
}
for
(
int
i
=
0
;
i
<
writepidCnt
;
++
i
)
{
if
(
!
cJSON_GetArrayItem
(
filedJ
,
i
)
||
!
cJSON_GetStringValue
(
cJSON_GetArrayItem
(
filedJ
,
i
))
||
strlen
(
cJSON_GetStringValue
(
cJSON_GetArrayItem
(
filedJ
,
i
)))
<=
0
)
{
// check all errors
INIT_LOGE
(
"GetWritepidStrings, parse item[%d] error."
,
i
);
cJSON
*
item
=
cJSON_GetArrayItem
(
filedJ
,
i
);
if
(
item
==
NULL
)
{
return
SERVICE_FAILURE
;
}
char
*
fieldStr
=
cJSON_GetStringValue
(
cJSON_GetArrayItem
(
filedJ
,
i
));
if
(
fieldStr
==
NULL
)
{
char
*
fieldStr
=
cJSON_GetStringValue
(
item
);
if
((
fieldStr
==
NULL
)
||
(
fieldStr
[
0
]
==
'\0'
))
{
return
SERVICE_FAILURE
;
}
size_t
strLen
=
strlen
(
fieldStr
);
...
...
@@ -267,12 +265,14 @@ static int GetGidArray(const cJSON *curArrItem, Service *curServ) // gid
curServ
->
servPerm
.
gIDCnt
=
gIDCnt
;
int
i
=
0
;
for
(;
i
<
gIDCnt
;
++
i
)
{
if
(
cJSON_GetArrayItem
(
filedJ
,
i
)
==
NULL
||
!
cJSON_GetStringValue
(
cJSON_GetArrayItem
(
filedJ
,
i
))
||
strlen
(
cJSON_GetStringValue
(
cJSON_GetArrayItem
(
filedJ
,
i
)))
<=
0
)
{
// check all errors
INIT_LOGE
(
"GetGidArray, parse item[%d] as string, error."
,
i
);
cJSON
*
item
=
cJSON_GetArrayItem
(
filedJ
,
i
);
if
(
item
==
NULL
)
{
break
;
}
char
*
fieldStr
=
cJSON_GetStringValue
(
item
);
if
((
fieldStr
==
NULL
)
||
(
fieldStr
[
0
]
==
'\0'
))
{
break
;
}
char
*
fieldStr
=
cJSON_GetStringValue
(
cJSON_GetArrayItem
(
filedJ
,
i
));
gid_t
gID
=
DecodeUid
(
fieldStr
);
if
((
gID
)
==
(
gid_t
)(
-
1
))
{
INIT_LOGE
(
"GetGidArray, DecodeUid item[%d] error."
,
i
);
...
...
@@ -284,11 +284,14 @@ static int GetGidArray(const cJSON *curArrItem, Service *curServ) // gid
return
SERVICE_SUCCESS
;
}
for
(
i
=
0
;
i
<
gIDCnt
;
++
i
)
{
if
(
cJSON_GetArrayItem
(
filedJ
,
i
)
==
NULL
||
!
cJSON_IsNumber
(
cJSON_GetArrayItem
(
filedJ
,
i
)))
{
INIT_LOGE
(
"GetGidArray, parse item[%d] as number, error."
,
i
);
cJSON
*
item
=
cJSON_GetArrayItem
(
filedJ
,
i
);
if
(
item
==
NULL
)
{
break
;
}
if
(
!
cJSON_IsNumber
(
item
))
{
break
;
}
gid_t
gID
=
(
int
)
cJSON_GetNumberValue
(
cJSON_GetArrayItem
(
filedJ
,
i
)
);
gid_t
gID
=
(
int
)
cJSON_GetNumberValue
(
item
);
if
(
gID
<
0
)
{
INIT_LOGE
(
"GetGidArray gID = %d, error"
,
gID
);
break
;
...
...
@@ -533,7 +536,7 @@ static int GetServiceSocket(const cJSON* curArrItem, Service* curServ)
}
curServ
->
socketCfg
=
NULL
;
for
(
int
i
=
0
;
i
<
sockCnt
;
++
i
)
{
cJSON
*
sockJ
=
cJSON_GetArrayItem
(
filedJ
,
i
);
cJSON
*
sockJ
=
cJSON_GetArrayItem
(
filedJ
,
i
);
if
(
!
cJSON_IsString
(
sockJ
)
||
!
cJSON_GetStringValue
(
sockJ
))
{
return
SERVICE_FAILURE
;
}
...
...
@@ -549,6 +552,8 @@ static int GetServiceSocket(const cJSON* curArrItem, Service* curServ)
}
int
ret
=
ParseServiceSocket
(
tmpStr
,
SOCK_OPT_NUMS
,
socktmp
);
if
(
ret
<
0
)
{
free
(
socktmp
);
socktmp
=
NULL
;
return
SERVICE_FAILURE
;
}
if
(
curServ
->
socketCfg
==
NULL
)
{
...
...
services/src/init_service_socket.c
浏览文件 @
284caa22
...
...
@@ -92,7 +92,7 @@ static int CreateSocket(struct ServiceSocket *sockopt)
return
sockopt
->
sockFd
;
}
static
int
SetSocketEnv
(
int
fd
,
char
*
name
)
static
int
SetSocketEnv
(
int
fd
,
c
onst
c
har
*
name
)
{
if
(
name
==
NULL
)
{
return
-
1
;
...
...
services/src/init_utils.c
浏览文件 @
284caa22
...
...
@@ -65,11 +65,11 @@ int DecodeUid(const char *name)
}
return
result
;
}
else
{
struct
passwd
*
pwd
=
getpwnam
(
name
);
if
(
pwd
==
NULL
)
{
struct
passwd
*
userInf
=
getpwnam
(
name
);
if
(
userInf
==
NULL
)
{
return
-
1
;
}
return
pwd
->
pw_uid
;
return
userInf
->
pw_uid
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录