72 lines
2.3 KiB
Diff
72 lines
2.3 KiB
Diff
From ec04faff6fba052b5bb4ed0b090ae441f888ce5c Mon Sep 17 00:00:00 2001
|
|
From: haozi007 <liuhao27@huawei.com>
|
|
Date: Wed, 6 Sep 2023 16:31:19 +0800
|
|
Subject: [PATCH 12/33] use gmtime_r to replace gmtime
|
|
|
|
Signed-off-by: haozi007 <liuhao27@huawei.com>
|
|
---
|
|
src/utils/cutils/utils_timestamp.c | 14 ++++++--------
|
|
1 file changed, 6 insertions(+), 8 deletions(-)
|
|
|
|
diff --git a/src/utils/cutils/utils_timestamp.c b/src/utils/cutils/utils_timestamp.c
|
|
index fee66ea8..8ae9e42a 100644
|
|
--- a/src/utils/cutils/utils_timestamp.c
|
|
+++ b/src/utils/cutils/utils_timestamp.c
|
|
@@ -652,9 +652,9 @@ int64_t util_time_seconds_since(const char *in)
|
|
int32_t nanos = 0;
|
|
int64_t result = 0;
|
|
struct tm tm = { 0 };
|
|
- struct tm *currentm = NULL;
|
|
struct types_timezone tz = { 0 };
|
|
time_t currentime;
|
|
+ struct tm result_time = { 0 };
|
|
|
|
if (in == NULL || !strcmp(in, defaultContainerTime) || !strcmp(in, "-")) {
|
|
return 0;
|
|
@@ -666,13 +666,12 @@ int64_t util_time_seconds_since(const char *in)
|
|
}
|
|
|
|
time(¤time);
|
|
- currentm = gmtime(¤time);
|
|
- if (currentm == NULL) {
|
|
+ if (gmtime_r(¤time, &result_time) == NULL) {
|
|
ERROR("Get time error");
|
|
return 0;
|
|
}
|
|
|
|
- result = get_minmus_time(currentm, &tm);
|
|
+ result = get_minmus_time(&result_time, &tm);
|
|
result = result + (int64_t)tz.hour * 3600 + (int64_t)tz.min * 60;
|
|
|
|
if (result > 0) {
|
|
@@ -871,9 +870,9 @@ int util_time_format_duration(const char *in, char *out, size_t len)
|
|
int32_t nanos = 0;
|
|
int64_t result = 0;
|
|
struct tm tm = { 0 };
|
|
- struct tm *currentm = NULL;
|
|
struct types_timezone tz = { 0 };
|
|
time_t currentime = { 0 };
|
|
+ struct tm result_time = { 0 };
|
|
|
|
if (out == NULL) {
|
|
return -1;
|
|
@@ -888,13 +887,12 @@ int util_time_format_duration(const char *in, char *out, size_t len)
|
|
}
|
|
|
|
time(¤time);
|
|
- currentm = gmtime(¤time);
|
|
- if (currentm == NULL) {
|
|
+ if (gmtime_r(¤time, &result_time) == NULL) {
|
|
ERROR("Get time error");
|
|
return -1;
|
|
}
|
|
|
|
- result = get_minmus_time(currentm, &tm);
|
|
+ result = get_minmus_time(&result_time, &tm);
|
|
result = result + (int64_t)tz.hour * 3600 + (int64_t)tz.min * 60;
|
|
|
|
if (result < 0 || !time_human_duration(result, out, len)) {
|
|
--
|
|
2.40.1
|
|
|