Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
002cf45f
S
Startup Init Lite
项目概览
OpenHarmony
/
Startup Init Lite
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
未验证
提交
002cf45f
编写于
6月 01, 2023
作者:
O
openharmony_ci
提交者:
Gitee
6月 01, 2023
浏览文件
操作
浏览文件
下载
差异文件
!1994 timespec 替换 time
Merge pull request !1994 from cheng_jinsong/init_time
上级
573a49f8
7637c554
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
51 addition
and
51 deletion
+51
-51
device_info/BUILD.gn
device_info/BUILD.gn
+2
-0
device_info/device_info_stub.cpp
device_info/device_info_stub.cpp
+10
-9
services/include/init_utils.h
services/include/init_utils.h
+3
-0
services/init/include/init_service.h
services/init/include/init_service.h
+1
-1
services/init/init_common_cmds.c
services/init/init_common_cmds.c
+0
-2
services/init/init_common_service.c
services/init/init_common_service.c
+6
-4
services/param/base/param_comm.c
services/param/base/param_comm.c
+1
-1
services/param/include/param_manager.h
services/param/include/param_manager.h
+1
-1
services/param/include/param_osadp.h
services/param/include/param_osadp.h
+0
-2
services/param/include/param_utils.h
services/param/include/param_utils.h
+1
-0
services/param/linux/param_osadp.c
services/param/linux/param_osadp.c
+0
-5
services/param/linux/param_request.c
services/param/linux/param_request.c
+5
-5
services/param/liteos/param_client.c
services/param/liteos/param_client.c
+5
-5
services/param/liteos/param_osadp.c
services/param/liteos/param_osadp.c
+0
-10
services/param/manager/param_persist.c
services/param/manager/param_persist.c
+6
-6
services/utils/init_utils.c
services/utils/init_utils.c
+10
-0
未找到文件。
device_info/BUILD.gn
浏览文件 @
002cf45f
...
...
@@ -38,6 +38,7 @@ if (!defined(ohos_lite)) {
include_dirs = [
"//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include/",
".",
"//base/startup/init/services/include",
"//base/startup/init/services/include/param",
"//base/startup/init/interfaces/innerkits/include",
"//base/startup/init/interfaces/innerkits/include/syspara",
...
...
@@ -54,6 +55,7 @@ if (!defined(ohos_lite)) {
"//base/startup/init/interfaces/innerkits:libbegetutil",
"//base/startup/init/services/log:agent_log",
"//base/startup/init/services/modules/udid:libudidcomm",
"//base/startup/init/services/utils:libinit_utils",
"//third_party/bounds_checking_function:libsec_shared",
]
...
...
device_info/device_info_stub.cpp
浏览文件 @
002cf45f
...
...
@@ -31,6 +31,7 @@
#include "param_comm.h"
#include "parameter.h"
#include "sysparam_errno.h"
#include "init_utils.h"
namespace
OHOS
{
using
namespace
Security
;
...
...
@@ -40,21 +41,21 @@ namespace device_info {
REGISTER_SYSTEM_ABILITY_BY_ID
(
DeviceInfoService
,
SYSPARAM_DEVICE_SERVICE_ID
,
true
)
static
std
::
mutex
g_lock
;
static
time_t
g_lastTime
;
static
struct
timespec
g_lastTime
;
#ifndef STARTUP_INIT_TEST
static
const
int
DEVICE_INFO_EXIT_TIMEOUT_
M
S
=
15
;
static
const
int
DEVICE_INFO_EXIT_TIMEOUT_S
=
15
;
#else
static
const
int
DEVICE_INFO_EXIT_TIMEOUT_
M
S
=
3
;
static
const
int
DEVICE_INFO_EXIT_TIMEOUT_S
=
3
;
#endif
static
void
UnloadDeviceInfoSa
(
int
signo
)
{
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
g_lock
);
time_t
currTime
;
(
void
)
time
(
&
currTime
);
if
(
difftime
(
currTime
,
g_lastTime
)
<
DEVICE_INFO_EXIT_TIMEOUT_M
S
)
{
alarm
(
DEVICE_INFO_EXIT_TIMEOUT_
M
S
/
3
);
// 3 half
struct
timespec
currTimer
=
{}
;
(
void
)
clock_gettime
(
CLOCK_MONOTONIC
,
&
currTimer
);
if
(
IntervalTime
(
&
g_lastTime
,
&
currTimer
)
<
DEVICE_INFO_EXIT_TIMEOUT_
S
)
{
alarm
(
DEVICE_INFO_EXIT_TIMEOUT_S
/
3
);
// 3 half
return
;
}
}
...
...
@@ -75,7 +76,7 @@ int32_t DeviceInfoStub::OnRemoteRequest(uint32_t code,
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
g_lock
);
(
void
)
time
(
&
g_lastTime
);
(
void
)
clock_gettime
(
CLOCK_MONOTONIC
,
&
g_lastTime
);
}
int
ret
=
ERR_FAIL
;
...
...
@@ -144,7 +145,7 @@ void DeviceInfoService::OnStart(void)
DINFO_LOGE
(
"DeviceInfoService Publish failed"
);
}
signal
(
SIGALRM
,
UnloadDeviceInfoSa
);
alarm
(
DEVICE_INFO_EXIT_TIMEOUT_
M
S
/
2
);
// 2 half
alarm
(
DEVICE_INFO_EXIT_TIMEOUT_S
/
2
);
// 2 half
return
;
}
...
...
services/include/init_utils.h
浏览文件 @
002cf45f
...
...
@@ -34,6 +34,7 @@ typedef struct {
int
value
;
}
InitArgInfo
;
#define BASE_MS_UNIT 1000
#define MAX_INT_LEN 20
#define HEX_BASE 16
#define BINARY_BASE 2
...
...
@@ -89,6 +90,8 @@ void OpenConsole(void);
void
TrimTail
(
char
*
str
,
char
c
);
char
*
TrimHead
(
char
*
str
,
char
c
);
INIT_LOCAL_API
uint32_t
IntervalTime
(
struct
timespec
*
startTime
,
struct
timespec
*
endTime
);
INIT_LOCAL_API
int
StringToULL
(
const
char
*
str
,
unsigned
long
long
int
*
out
);
INIT_LOCAL_API
int
StringToLL
(
const
char
*
str
,
long
long
int
*
out
);
void
CloseStdio
(
void
);
...
...
services/init/include/init_service.h
浏览文件 @
002cf45f
...
...
@@ -134,7 +134,7 @@ typedef struct Service_ {
char
*
name
;
int
pid
;
int
crashCnt
;
time
_t
firstCrashTime
;
uint32
_t
firstCrashTime
;
int
crashCount
;
int
crashTime
;
unsigned
int
attribute
;
...
...
services/init/init_common_cmds.c
浏览文件 @
002cf45f
...
...
@@ -38,8 +38,6 @@
#include "init_utils.h"
#include "securec.h"
#define BASE_MS_UNIT 1000
#ifndef OHOS_LITE
#include "hookmgr.h"
#include "bootstage.h"
...
...
services/init/init_common_service.c
浏览文件 @
002cf45f
...
...
@@ -573,15 +573,17 @@ static bool CalculateCrashTime(Service *service, int crashTimeLimit, int crashCo
{
INIT_ERROR_CHECK
(
service
!=
NULL
&&
crashTimeLimit
>
0
&&
crashCountLimit
>
0
,
return
false
,
"input params error."
);
time_t
curTime
=
time
(
NULL
);
struct
timespec
curTime
=
{};
(
void
)
clock_gettime
(
CLOCK_MONOTONIC
,
&
curTime
);
struct
timespec
crashTime
=
{
service
->
firstCrashTime
,
0
};
if
(
service
->
crashCnt
==
0
)
{
service
->
firstCrashTime
=
curTime
;
service
->
firstCrashTime
=
curTime
.
tv_sec
;
++
service
->
crashCnt
;
if
(
service
->
crashCnt
==
crashCountLimit
)
{
return
false
;
}
}
else
if
(
difftime
(
curTime
,
service
->
firstCrash
Time
)
>
crashTimeLimit
)
{
service
->
firstCrashTime
=
curTime
;
}
else
if
(
IntervalTime
(
&
crashTime
,
&
cur
Time
)
>
crashTimeLimit
)
{
service
->
firstCrashTime
=
curTime
.
tv_sec
;
service
->
crashCnt
=
1
;
}
else
{
++
service
->
crashCnt
;
...
...
services/param/base/param_comm.c
浏览文件 @
002cf45f
...
...
@@ -187,4 +187,4 @@ INIT_LOCAL_API int ParamStrCpy(char *strDest, size_t destMax, const char *strSrc
ret
=
strcpy_s
(
strDest
,
destMax
,
strSrc
);
#endif
return
ret
;
}
\ No newline at end of file
}
services/param/include/param_manager.h
浏览文件 @
002cf45f
...
...
@@ -85,7 +85,7 @@ typedef struct {
uint32_t
flags
;
long
long
commitId
;
ParamTaskPtr
saveTimer
;
time_t
lastSaveTimer
;
struct
timespec
lastSaveTimer
;
PersistParamOps
persistParamOps
;
}
ParamPersistWorkSpace
;
...
...
services/param/include/param_osadp.h
浏览文件 @
002cf45f
...
...
@@ -211,8 +211,6 @@ INIT_LOCAL_API void FreeSharedMem(const MemHandle *handle, void *mem, uint32_t d
#define ATOMIC_STORE_EXPLICIT(commitId, value, order) atomic_store_explicit((commitId), (value), (order))
#endif
INIT_LOCAL_API
uint32_t
Difftime
(
time_t
curr
,
time_t
base
);
#ifdef __cplusplus
#if __cplusplus
}
...
...
services/param/include/param_utils.h
浏览文件 @
002cf45f
...
...
@@ -140,6 +140,7 @@ typedef int (*DUMP_PRINTF)(const char *fmt, ...);
INIT_LOCAL_API
int
SplitParamString
(
char
*
line
,
const
char
*
exclude
[],
uint32_t
count
,
int
(
*
result
)(
const
uint32_t
*
context
,
const
char
*
name
,
const
char
*
value
),
const
uint32_t
*
context
);
#ifdef __cplusplus
#if __cplusplus
}
...
...
services/param/linux/param_osadp.c
浏览文件 @
002cf45f
...
...
@@ -102,8 +102,3 @@ INIT_LOCAL_API void FreeSharedMem(const MemHandle *handle, void *mem, uint32_t d
PARAM_CHECK
(
mem
!=
NULL
&&
handle
!=
NULL
,
return
,
"Invalid mem or handle"
);
munmap
((
char
*
)
mem
,
dataSize
);
}
INIT_LOCAL_API
uint32_t
Difftime
(
time_t
curr
,
time_t
base
)
{
return
(
uint32_t
)
difftime
(
curr
,
base
);
}
\ No newline at end of file
services/param/linux/param_request.c
浏览文件 @
002cf45f
...
...
@@ -93,16 +93,16 @@ static int ReadMessage(int fd, char *buffer, uint32_t timeout)
{
int
ret
=
0
;
uint32_t
diff
=
0
;
time_t
startTime
;
(
void
)
time
(
&
startTime
);
struct
timespec
startTime
=
{}
;
(
void
)
clock_gettime
(
CLOCK_MONOTONIC
,
&
startTime
);
do
{
ssize_t
recvLen
=
recv
(
fd
,
(
char
*
)
buffer
,
RECV_BUFFER_MAX
,
0
);
if
(
recvLen
>
0
)
{
break
;
}
time_t
finishTime
;
(
void
)
time
(
&
finishTime
);
diff
=
(
uint32_t
)
difftime
(
finishTime
,
startTime
);
struct
timespec
finishTime
=
{}
;
(
void
)
clock_gettime
(
CLOCK_MONOTONIC
,
&
finishTime
);
diff
=
IntervalTime
(
&
finishTime
,
&
startTime
);
if
(
diff
>=
timeout
)
{
ret
=
PARAM_CODE_TIMEOUT
;
break
;
...
...
services/param/liteos/param_client.c
浏览文件 @
002cf45f
...
...
@@ -71,11 +71,11 @@ int SystemWaitParameter(const char *name, const char *value, int32_t timeout)
int
ret
=
CheckParamPermission
(
GetParamSecurityLabel
(),
name
,
DAC_READ
);
PARAM_CHECK
(
ret
==
0
,
return
ret
,
"Forbid to wait parameter %s"
,
name
);
uint32_t
diff
=
0
;
time_t
startTime
;
struct
timespec
startTime
=
{}
;
if
(
timeout
<=
0
)
{
timeout
=
DEFAULT_PARAM_WAIT_TIMEOUT
;
}
(
void
)
time
(
&
startTime
);
(
void
)
clock_gettime
(
CLOCK_MONOTONIC
,
&
startTime
);
do
{
long
long
commit
=
GetSystemCommitId
();
if
(
commit
!=
globalCommit
)
{
...
...
@@ -88,9 +88,9 @@ int SystemWaitParameter(const char *name, const char *value, int32_t timeout)
globalCommit
=
commit
;
usleep
(
MIN_SLEEP
);
time_t
finishTime
;
(
void
)
time
(
&
finishTime
);
diff
=
(
uint32_t
)
difftime
(
finishTime
,
startTime
);
struct
timespec
finishTime
=
{}
;
(
void
)
clock_gettime
(
CLOCK_MONOTONIC
,
&
finishTime
);
diff
=
IntervalTime
(
&
finishTime
,
&
startTime
);
if
(
diff
>=
timeout
)
{
ret
=
PARAM_CODE_TIMEOUT
;
break
;
...
...
services/param/liteos/param_osadp.c
浏览文件 @
002cf45f
...
...
@@ -323,13 +323,3 @@ INIT_LOCAL_API int ParamMutexDelete(ParamMutex *mutex)
}
#endif
INIT_LOCAL_API
uint32_t
Difftime
(
time_t
curr
,
time_t
base
)
{
#ifndef __LITEOS_M__
return
(
uint32_t
)
difftime
(
curr
,
base
);
#else
(
void
)
curr
;
(
void
)
base
;
return
0
;
#endif
}
services/param/manager/param_persist.c
浏览文件 @
002cf45f
...
...
@@ -23,7 +23,7 @@
#include "param_osadp.h"
#include "securec.h"
static
ParamPersistWorkSpace
g_persistWorkSpace
=
{
0
,
0
,
NULL
,
0
,
{
0
}};
static
ParamPersistWorkSpace
g_persistWorkSpace
=
{
0
,
0
,
NULL
,
{}
,
{
0
}};
static
int
IsNeedToSave
(
const
char
*
name
)
{
#if defined(__LITEOS_M__) || defined(__LITEOS_A__)
...
...
@@ -118,7 +118,7 @@ static int BatchSavePersistParam(void)
PARAM_CHECK
(
ret
==
0
,
return
PARAM_CODE_INVALID_NAME
,
"Save persist param fail"
);
PARAM_CLEAR_FLAG
(
g_persistWorkSpace
.
flags
,
WORKSPACE_FLAGS_UPDATE
);
(
void
)
time
(
&
g_persistWorkSpace
.
lastSaveTimer
);
(
void
)
clock_gettime
(
CLOCK_MONOTONIC
,
&
g_persistWorkSpace
.
lastSaveTimer
);
return
ret
;
}
...
...
@@ -127,7 +127,7 @@ INIT_LOCAL_API int InitPersistParamWorkSpace(void)
if
(
PARAM_TEST_FLAG
(
g_persistWorkSpace
.
flags
,
WORKSPACE_FLAGS_INIT
))
{
return
0
;
}
(
void
)
time
(
&
g_persistWorkSpace
.
lastSaveTimer
);
(
void
)
clock_gettime
(
CLOCK_MONOTONIC
,
&
g_persistWorkSpace
.
lastSaveTimer
);
RegisterPersistParamOps
(
&
g_persistWorkSpace
.
persistParamOps
);
PARAM_SET_FLAG
(
g_persistWorkSpace
.
flags
,
WORKSPACE_FLAGS_INIT
);
return
0
;
...
...
@@ -194,9 +194,9 @@ INIT_LOCAL_API int WritePersistParam(const char *name, const char *value)
}
// check timer for save all
time_t
currTimer
;
(
void
)
time
(
&
currTimer
);
uint32_t
diff
=
Difftime
(
currTimer
,
g_persistWorkSpace
.
lastSave
Timer
);
struct
timespec
currTimer
=
{}
;
(
void
)
clock_gettime
(
CLOCK_MONOTONIC
,
&
currTimer
);
uint32_t
diff
=
IntervalTime
(
&
g_persistWorkSpace
.
lastSaveTimer
,
&
curr
Timer
);
if
(
diff
>
PARAM_MUST_SAVE_PARAM_DIFF
)
{
if
(
g_persistWorkSpace
.
saveTimer
!=
NULL
)
{
ParamTimerClose
(
g_persistWorkSpace
.
saveTimer
);
...
...
services/utils/init_utils.c
浏览文件 @
002cf45f
...
...
@@ -685,3 +685,13 @@ int GetParameterFromCmdLine(const char *paramName, char *value, size_t valueLen)
return
ret
;
}
uint32_t
IntervalTime
(
struct
timespec
*
startTime
,
struct
timespec
*
endTime
)
{
uint32_t
diff
=
0
;
if
(
endTime
->
tv_sec
>
startTime
->
tv_sec
)
{
diff
=
(
uint32_t
)(
endTime
->
tv_sec
-
startTime
->
tv_sec
);
}
else
{
diff
=
(
uint32_t
)(
startTime
->
tv_sec
-
endTime
->
tv_sec
);
}
return
diff
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录