Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
dec0f815
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看板
提交
dec0f815
编写于
4月 11, 2022
作者:
X
xlei1030
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
appspawn 归一化
Signed-off-by:
N
xlei1030
<
xionglei6@huawei.com
>
上级
779e1987
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
79 addition
and
26 deletion
+79
-26
interfaces/innerkits/reboot/init_reboot_innerkits.c
interfaces/innerkits/reboot/init_reboot_innerkits.c
+23
-1
services/include/init_hashmap.h
services/include/init_hashmap.h
+2
-0
services/init/init_common_service.c
services/init/init_common_service.c
+17
-11
services/init/init_service_manager.c
services/init/init_service_manager.c
+4
-3
services/loopevent/include/loop_event.h
services/loopevent/include/loop_event.h
+2
-1
services/loopevent/signal/le_signal.c
services/loopevent/signal/le_signal.c
+1
-1
services/loopevent/socket/le_socket.c
services/loopevent/socket/le_socket.c
+10
-5
services/loopevent/task/le_streamtask.c
services/loopevent/task/le_streamtask.c
+5
-2
services/utils/init_hashmap.c
services/utils/init_hashmap.c
+15
-2
未找到文件。
interfaces/innerkits/reboot/init_reboot_innerkits.c
浏览文件 @
dec0f815
...
...
@@ -32,7 +32,7 @@
#define DOREBOOT_PARAM "reboot.ut"
#endif
int
DoReboot
(
const
char
*
option
)
int
DoReboot
_
(
const
char
*
option
)
{
char
value
[
MAX_REBOOT_OPTION_SIZE
];
int
ret
=
0
;
...
...
@@ -63,3 +63,25 @@ int DoReboot(const char *option)
BEGET_ERROR_CHECK
(
ret
==
0
,
return
-
1
,
"Set parameter to trigger reboot command
\"
%s
\"
failed"
,
value
);
return
0
;
}
int
DoReboot
(
const
char
*
option
)
{
// check if param set ok
const
int
maxCount
=
10
;
int
count
=
0
;
DoReboot_
(
option
);
while
(
count
<
maxCount
)
{
usleep
(
100
*
1000
);
// 100 * 1000 wait 100ms
char
result
[
10
]
=
{
0
};
// 10 stop len
uint32_t
len
=
sizeof
(
result
);
int
ret
=
SystemGetParameter
(
STARTUP_DEVICE_CTL
,
result
,
&
len
);
if
(
ret
==
0
&&
strcmp
(
result
,
DEVICE_CMD_STOP
)
==
0
)
{
BEGET_LOGE
(
"Success to reboot system"
);
return
0
;
}
count
++
;
DoReboot_
(
option
);
}
BEGET_LOGE
(
"Failed to reboot system"
);
return
0
;
}
services/include/init_hashmap.h
浏览文件 @
dec0f815
...
...
@@ -59,6 +59,8 @@ void HashMapRemove(HashMapHandle handle, const void *key);
HashNode
*
HashMapGet
(
HashMapHandle
handle
,
const
void
*
key
);
HashNode
*
HashMapFind
(
HashMapHandle
handle
,
int
hashCode
,
const
void
*
key
,
HashKeyCompare
keyCompare
);
void
HashMapTraverse
(
HashMapHandle
handle
,
void
(
*
hashNodeTraverse
)(
const
HashNode
*
node
,
const
void
*
context
),
const
void
*
context
);
#ifdef __cplusplus
#if __cplusplus
}
...
...
services/init/init_common_service.c
浏览文件 @
dec0f815
...
...
@@ -229,7 +229,10 @@ static void PublishHoldFds(Service *service)
fdBuffer
[
pos
-
1
]
=
'\0'
;
// Remove last ' '
INIT_LOGI
(
"fd buffer: [%s]"
,
fdBuffer
);
char
envName
[
MAX_BUFFER_LEN
]
=
{};
(
void
)
snprintf_s
(
envName
,
MAX_BUFFER_LEN
,
MAX_BUFFER_LEN
-
1
,
ENV_FD_HOLD_PREFIX
"%s"
,
service
->
name
);
if
(
snprintf_s
(
envName
,
MAX_BUFFER_LEN
,
MAX_BUFFER_LEN
-
1
,
ENV_FD_HOLD_PREFIX
"%s"
,
service
->
name
)
<
0
)
{
INIT_LOGE
(
"snprintf_s failed err=%d"
,
errno
);
return
;
}
if
(
setenv
(
envName
,
fdBuffer
,
1
)
<
0
)
{
INIT_LOGE
(
"Failed to set env %s"
,
envName
);
}
...
...
@@ -256,13 +259,15 @@ static int BindCpuCore(Service *service)
return
SERVICE_SUCCESS
;
}
static
void
ClearEnvironment
(
void
)
static
void
ClearEnvironment
(
Service
*
service
)
{
sigset_t
mask
;
sigemptyset
(
&
mask
);
sigaddset
(
&
mask
,
SIGCHLD
);
sigaddset
(
&
mask
,
SIGTERM
);
sigprocmask
(
SIG_UNBLOCK
,
&
mask
,
NULL
);
if
(
strcmp
(
service
->
name
,
"appspawn"
)
!=
0
)
{
sigset_t
mask
;
sigemptyset
(
&
mask
);
sigaddset
(
&
mask
,
SIGCHLD
);
sigaddset
(
&
mask
,
SIGTERM
);
sigprocmask
(
SIG_UNBLOCK
,
&
mask
,
NULL
);
}
return
;
}
...
...
@@ -294,7 +299,7 @@ int ServiceStart(Service *service)
DoJobNow
(
service
->
serviceJobs
.
jobsName
[
JOB_ON_START
]);
}
ClearEnvironment
();
ClearEnvironment
(
service
);
if
(
!
IsOnDemandService
(
service
))
{
INIT_ERROR_CHECK
(
CreateServiceSocket
(
service
)
>=
0
,
return
SERVICE_FAILURE
,
...
...
@@ -353,6 +358,7 @@ int ServiceStop(Service *service)
"stop service %s pid %d failed! err %d."
,
service
->
name
,
service
->
pid
,
errno
);
NotifyServiceChange
(
service
,
SERVICE_STOPPING
);
INIT_LOGI
(
"stop service %s, pid %d."
,
service
->
name
,
service
->
pid
);
service
->
pid
=
-
1
;
return
SERVICE_SUCCESS
;
}
...
...
@@ -451,14 +457,14 @@ void ServiceReap(Service *service)
}
if
(
service
->
attribute
&
SERVICE_ATTR_CRITICAL
)
{
// critical
if
(
CalculateCrashTime
(
service
,
service
->
crashTime
,
service
->
crashCount
)
==
false
)
{
if
(
!
CalculateCrashTime
(
service
,
service
->
crashTime
,
service
->
crashCount
)
)
{
INIT_LOGE
(
"Critical service
\"
%s
\"
crashed %d times, rebooting system"
,
service
->
name
,
service
->
crashCount
);
ServiceStop
(
GetServiceByName
(
"appspawn"
));
ExecReboot
(
"reboot"
);
}
}
else
if
(
!
(
service
->
attribute
&
SERVICE_ATTR_NEED_RESTART
))
{
if
(
CalculateCrashTime
(
service
,
service
->
crashTime
,
service
->
crashCount
)
==
false
)
{
if
(
!
CalculateCrashTime
(
service
,
service
->
crashTime
,
service
->
crashCount
)
)
{
INIT_LOGE
(
"Service name=%s, crash %d times, no more start."
,
service
->
name
,
service
->
crashCount
);
return
;
}
...
...
@@ -570,7 +576,7 @@ static void ServiceTimerStartProcess(const TimerHandle handler, void *context)
ServiceStopTimer
(
service
);
int
ret
=
ServiceStart
(
service
);
if
(
ret
!=
SERVICE_SUCCESS
)
{
INIT_LOGE
(
"Start service
\'
%s
\'
in timer failed"
);
INIT_LOGE
(
"Start service
\'
%s
\'
in timer failed"
,
service
->
name
);
}
}
...
...
services/init/init_service_manager.c
浏览文件 @
dec0f815
...
...
@@ -814,8 +814,7 @@ int ParseOneService(const cJSON *curItem, Service *service)
INIT_CHECK_RETURN_VALUE
(
curItem
!=
NULL
&&
service
!=
NULL
,
SERVICE_FAILURE
);
int
ret
=
0
;
#ifdef WITH_SELINUX
ret
=
GetStringItem
(
curItem
,
SECON_STR_IN_CFG
,
service
->
secon
,
MAX_SECON_LEN
);
INIT_CHECK_ONLY_ELOG
(
ret
==
0
,
"GetServiceSecon %s section not found, skip"
,
SECON_STR_IN_CFG
);
(
void
)
GetStringItem
(
curItem
,
SECON_STR_IN_CFG
,
service
->
secon
,
MAX_SECON_LEN
);
#endif // WITH_SELINUX
ret
=
GetServiceArgs
(
curItem
,
"path"
,
MAX_PATH_ARGS_CNT
,
&
service
->
pathArgs
);
INIT_ERROR_CHECK
(
ret
==
0
,
return
SERVICE_FAILURE
,
"Failed to get path for service %s"
,
service
->
name
);
...
...
@@ -984,8 +983,10 @@ void StopAllServices(int flags, const char **exclude, int size,
int
(
*
filter
)(
const
Service
*
service
,
const
char
**
exclude
,
int
size
))
{
Service
*
service
=
GetServiceByName
(
"appspawn"
);
if
(((
SERVICE_ATTR_NEEDWAIT
&
flags
)
==
SERVICE_ATTR_NEEDWAIT
)
&&
service
!=
NULL
&&
service
->
pid
!=
0
)
{
if
(
service
!=
NULL
&&
service
->
pid
!=
-
1
)
{
// notify appspawn stop
kill
(
service
->
pid
,
SIGTERM
);
waitpid
(
service
->
pid
,
0
,
0
);
service
->
pid
=
-
1
;
}
InitGroupNode
*
node
=
GetNextGroupNode
(
NODE_TYPE_SERVICES
,
NULL
);
...
...
services/loopevent/include/loop_event.h
浏览文件 @
dec0f815
...
...
@@ -27,7 +27,7 @@ extern "C" {
// 配置
#define LOOP_EVENT_USE_EPOLL 1
#define LOOP_DEFAULT_BUFFER
1024
#define LOOP_DEFAULT_BUFFER
(1024 * 5)
#define LOOP_MAX_BUFFER (1024 * 64)
#define LOOP_MAX_CLIENT 1024
...
...
@@ -100,6 +100,7 @@ typedef int (*LE_IncommingConntect)(const LoopHandle loopHandle, const TaskHandl
typedef
struct
{
LE_BaseInfo
baseInfo
;
char
*
server
;
int
socketId
;
LE_DisConntectComplete
disConntectComplete
;
LE_IncommingConntect
incommingConntect
;
LE_SendMessageComplete
sendMessageComplete
;
...
...
services/loopevent/signal/le_signal.c
浏览文件 @
dec0f815
...
...
@@ -33,7 +33,7 @@ static LE_STATUS HandleSignalEvent_(const LoopHandle loop, const TaskHandle task
}
struct
signalfd_siginfo
fdsi
;
ssize_t
s
=
read
(
GetSocketFd
(
task
),
&
fdsi
,
sizeof
(
fdsi
));
LE_CHECK
(
s
==
sizeof
(
fdsi
),
return
LE_FAILURE
,
"Failed to read sign
"
);
LE_CHECK
(
s
==
sizeof
(
fdsi
),
return
LE_FAILURE
,
"Failed to read sign
%d %d"
,
s
,
errno
);
SignalTask
*
sigTask
=
(
SignalTask
*
)
task
;
if
(
sigTask
->
processSignal
)
{
sigTask
->
processSignal
(
&
fdsi
);
...
...
services/loopevent/socket/le_socket.c
浏览文件 @
dec0f815
...
...
@@ -36,11 +36,15 @@ static int CreatePipeServerSocket_(const char *server, int maxClient)
unlink
(
server
);
struct
sockaddr_un
serverAddr
;
memset_s
(
&
serverAddr
,
sizeof
(
serverAddr
),
0
,
sizeof
(
serverAddr
));
int
ret
=
memset_s
(
&
serverAddr
,
sizeof
(
serverAddr
),
0
,
sizeof
(
serverAddr
));
LE_CHECK
(
ret
==
0
,
close
(
listenfd
);
return
ret
,
"Failed to memory set. error: %s"
,
strerror
(
errno
));
serverAddr
.
sun_family
=
AF_UNIX
;
strcpy_s
(
serverAddr
.
sun_path
,
sizeof
(
serverAddr
.
sun_path
),
server
);
ret
=
strcpy_s
(
serverAddr
.
sun_path
,
sizeof
(
serverAddr
.
sun_path
),
server
);
LE_CHECK
(
ret
==
0
,
close
(
listenfd
);
return
ret
,
"Failed to copy. error: %s"
,
strerror
(
errno
));
uint32_t
size
=
offsetof
(
struct
sockaddr_un
,
sun_path
)
+
strlen
(
server
);
int
ret
=
bind
(
listenfd
,
(
struct
sockaddr
*
)
&
serverAddr
,
size
);
ret
=
bind
(
listenfd
,
(
struct
sockaddr
*
)
&
serverAddr
,
size
);
LE_CHECK
(
ret
>=
0
,
close
(
listenfd
);
return
ret
,
"Failed to bind socket. error: %s"
,
strerror
(
errno
));
...
...
@@ -91,13 +95,14 @@ static int CreatePipeSocket_(const char *server)
LE_STATUS
GetSockaddrFromServer_
(
const
char
*
server
,
struct
sockaddr_in
*
addr
)
{
memset_s
(
addr
,
sizeof
(
struct
sockaddr_in
),
0
,
sizeof
(
struct
sockaddr_in
));
int
ret
=
memset_s
(
addr
,
sizeof
(
struct
sockaddr_in
),
0
,
sizeof
(
struct
sockaddr_in
));
LE_CHECK
(
ret
==
0
,
return
ret
,
"Failed to memory set. error: %s"
,
strerror
(
errno
));
addr
->
sin_family
=
AF_INET
;
const
char
*
portStr
=
strstr
(
server
,
":"
);
LE_CHECK
(
portStr
!=
NULL
,
return
LE_FAILURE
,
"Failed to get addr %s"
,
server
);
uint16_t
port
=
atoi
(
portStr
+
1
);
addr
->
sin_port
=
htons
(
port
);
int
ret
=
inet_pton
(
AF_INET
,
server
,
&
addr
->
sin_addr
);
ret
=
inet_pton
(
AF_INET
,
server
,
&
addr
->
sin_addr
);
LE_CHECK
(
ret
>=
0
,
return
LE_FAILURE
,
"Failed to inet_pton addr %s"
,
server
);
return
LE_SUCCESS
;
}
...
...
services/loopevent/task/le_streamtask.c
浏览文件 @
dec0f815
...
...
@@ -164,8 +164,11 @@ LE_STATUS LE_CreateStreamServer(const LoopHandle loopHandle,
LE_CHECK
(
info
->
incommingConntect
!=
NULL
,
return
LE_INVALID_PARAM
,
"Invalid parameters incommingConntect %s"
,
info
->
server
);
int
fd
=
CreateSocket
(
info
->
baseInfo
.
flags
,
info
->
server
);
LE_CHECK
(
fd
>
0
,
return
LE_FAILURE
,
"Failed to create socket %s"
,
info
->
server
);
int
fd
=
info
->
socketId
;
if
(
info
->
socketId
<=
0
)
{
fd
=
CreateSocket
(
info
->
baseInfo
.
flags
,
info
->
server
);
LE_CHECK
(
fd
>
0
,
return
LE_FAILURE
,
"Failed to create socket %s"
,
info
->
server
);
}
EventLoop
*
loop
=
(
EventLoop
*
)
loopHandle
;
StreamServerTask
*
task
=
(
StreamServerTask
*
)
CreateTask
(
loopHandle
,
fd
,
&
info
->
baseInfo
,
...
...
services/utils/init_hashmap.c
浏览文件 @
dec0f815
...
...
@@ -113,7 +113,6 @@ void HashMapRemove(HashMapHandle handle, const void *key)
while
(
node
!=
NULL
)
{
int
ret
=
tab
->
keyCompare
(
node
,
key
);
if
(
ret
==
0
)
{
INIT_LOGV
(
"HashMapRemove tableId %d hashCode %d node %p"
,
tab
->
tableId
,
hashCode
,
node
);
if
(
node
==
tab
->
buckets
[
hashCode
])
{
tab
->
buckets
[
hashCode
]
=
node
->
next
;
}
else
{
...
...
@@ -173,4 +172,18 @@ HashNode *HashMapFind(HashMapHandle handle,
"Invalid hashcode %d %d"
,
tab
->
maxBucket
,
hashCode
);
INIT_LOGV
(
"HashMapGet tableId %d hashCode %d"
,
tab
->
tableId
,
hashCode
);
return
GetHashNodeByKey
(
tab
,
tab
->
buckets
[
hashCode
],
key
,
keyCompare
);
}
\ No newline at end of file
}
void
HashMapTraverse
(
HashMapHandle
handle
,
void
(
*
hashNodeTraverse
)(
const
HashNode
*
node
,
const
void
*
context
),
const
void
*
context
)
{
INIT_ERROR_CHECK
(
handle
!=
NULL
&&
hashNodeTraverse
!=
NULL
,
return
,
"Invalid param"
);
HashTab
*
tab
=
(
HashTab
*
)
handle
;
for
(
int
i
=
0
;
i
<
tab
->
maxBucket
;
i
++
)
{
HashNode
*
node
=
tab
->
buckets
[
i
];
while
(
node
!=
NULL
)
{
HashNode
*
next
=
node
->
next
;
hashNodeTraverse
(
node
,
context
);
node
=
next
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录