diff options
-rw-r--r-- | src/heart/heart-abnormal.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/heart/heart-abnormal.c b/src/heart/heart-abnormal.c index 7096a82f..7ff900e3 100644 --- a/src/heart/heart-abnormal.c +++ b/src/heart/heart-abnormal.c @@ -177,15 +177,20 @@ static int heart_abnormal_report_malfunction(char *name) struct timeval time_of_day; int milli; time_t unix_time = time(NULL); + struct tm loc_tm; if (gettimeofday(&time_of_day, NULL)) { _E("gettimeofday failed"); return ret; } + if (!localtime_r(&time_of_day.tv_sec, &loc_tm)) { + _E("localtime_r failed"); + return ret; + } snprintf(timestr, sizeof(timestr), "%.10ld", unix_time); milli = time_of_day.tv_usec / MILLISEC; - strftime(ts, TIME_MAX_LEN, "%Y.%m.%d-%H:%M:%S", localtime(&time_of_day.tv_sec)); + strftime(ts, TIME_MAX_LEN, "%Y.%m.%d-%H:%M:%S", &loc_tm); snprintf(msgid, sizeof(msgid), "%s+%d", ts, milli); snprintf(pa1, TIMESTAMP_LEN, SLUG_TYPE_MALFUN); snprintf(pa2, TIMESTAMP_LEN, NOPID); |