Browse Source

TT#111150 Use localtime_r() instead of thread-unsafe localtime()

While the code is not threaded, better be future-proof and use safer
APIs, which in addition has less side-effects as it does not set the
global TZ related variables.

Also check for failures.

Change-Id: I083d2b5ad6901ac1a91d42d1ab7fe3e0989b02a0
Warned-by: lgtm
pull/1218/head
Guillem Jover 5 years ago
parent
commit
eb84cb0148
1 changed files with 13 additions and 7 deletions
  1. +13
    -7
      daemon/recording.c

+ 13
- 7
daemon/recording.c View File

@ -456,16 +456,22 @@ static int rec_pcap_meta_finish_file(struct call *call) {
time_t start = call->created.tv_sec;
time_t end = rtpe_now.tv_sec;
char timebuffer[20];
struct tm *timeinfo;
struct tm timeinfo;
struct timeval *terminate;
terminate = &(((struct call_monologue *)call->monologues.head->data)->terminated);
fprintf(recording->u.pcap.meta_fp, "\nTimestamp terminated ms(first monologue): %.3lf", terminate->tv_sec*1000.0 + terminate->tv_usec/1000.0);
timeinfo = localtime(&start);
strftime(timebuffer, 20, "%FT%T", timeinfo);
fprintf(recording->u.pcap.meta_fp, "\n\ncall start time: %s\n", timebuffer);
timeinfo = localtime(&end);
strftime(timebuffer, 20, "%FT%T", timeinfo);
fprintf(recording->u.pcap.meta_fp, "call end time: %s\n", timebuffer);
if (localtime_r(&start, &timeinfo) < 0) {
ilog(LOG_ERROR, "Cannot get start local time, while cleaning up recording meta file: %s", strerror(errno));
} else {
strftime(timebuffer, 20, "%FT%T", &timeinfo);
fprintf(recording->u.pcap.meta_fp, "\n\ncall start time: %s\n", timebuffer);
}
if (localtime_r(&end, &timeinfo) < 0) {
ilog(LOG_ERROR, "Cannot get end local time, while cleaning up recording meta file: %s", strerror(errno));
} else {
strftime(timebuffer, 20, "%FT%T", &timeinfo);
fprintf(recording->u.pcap.meta_fp, "call end time: %s\n", timebuffer);
}
// Print metadata
if (call->metadata.len)


Loading…
Cancel
Save