Skip to content

Commit 1d91d0f

Browse files
maass-hamburgmmahadevan108
authored andcommitted
logging: log_output: switch to gmtime_r
switch from gmtime() to gmtime_r(). Signed-off-by: Fin Maaß <[email protected]>
1 parent 9ab8eee commit 1d91d0f

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

subsys/logging/log_output.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,12 @@ static int timestamp_print(const struct log_output *output,
255255
if (IS_ENABLED(CONFIG_LOG_BACKEND_NET) && flags & LOG_OUTPUT_FLAG_FORMAT_SYSLOG) {
256256
#if defined(CONFIG_REQUIRES_FULL_LIBC)
257257
char time_str[sizeof("1970-01-01T00:00:00")];
258-
struct tm *tm;
259-
time_t time;
258+
struct tm tm_timestamp = {0};
259+
time_t time_seconds = total_seconds;
260260

261-
time = total_seconds;
262-
tm = gmtime(&time);
261+
gmtime_r(&time_seconds, &tm_timestamp);
263262

264-
strftime(time_str, sizeof(time_str), "%FT%T", tm);
263+
strftime(time_str, sizeof(time_str), "%FT%T", &tm_timestamp);
265264

266265
length = print_formatted(output, "%s.%06uZ ",
267266
time_str, ms * 1000U + us);
@@ -289,12 +288,12 @@ static int timestamp_print(const struct log_output *output,
289288
} else if (IS_ENABLED(CONFIG_LOG_OUTPUT_FORMAT_DATE_TIMESTAMP)) {
290289
#if defined(CONFIG_REQUIRES_FULL_LIBC)
291290
char time_str[sizeof("1970-01-01 00:00:00")];
292-
struct tm *tm_timestamp;
291+
struct tm tm_timestamp = {0};
293292
time_t time_seconds = total_seconds;
294293

295-
tm_timestamp = gmtime(&time_seconds);
294+
gmtime_r(&time_seconds, &tm_timestamp);
296295

297-
strftime(time_str, sizeof(time_str), "%F %T", tm_timestamp);
296+
strftime(time_str, sizeof(time_str), "%F %T", &tm_timestamp);
298297

299298
length = print_formatted(output, "[%s.%03u,%03u] ", time_str, ms,
300299
us);
@@ -311,12 +310,12 @@ static int timestamp_print(const struct log_output *output,
311310
} else if (IS_ENABLED(CONFIG_LOG_OUTPUT_FORMAT_ISO8601_TIMESTAMP)) {
312311
#if defined(CONFIG_REQUIRES_FULL_LIBC)
313312
char time_str[sizeof("1970-01-01T00:00:00")];
314-
struct tm *tm_timestamp;
313+
struct tm tm_timestamp = {0};
315314
time_t time_seconds = total_seconds;
316315

317-
tm_timestamp = gmtime(&time_seconds);
316+
gmtime_r(&time_seconds, &tm_timestamp);
318317

319-
strftime(time_str, sizeof(time_str), "%FT%T", tm_timestamp);
318+
strftime(time_str, sizeof(time_str), "%FT%T", &tm_timestamp);
320319

321320
length = print_formatted(output, "[%s,%06uZ] ", time_str,
322321
ms * 1000U + us);

0 commit comments

Comments
 (0)