Skip to content

Commit

Permalink
[agw][mme] Replace ctime_r with strftime (#4240)
Browse files Browse the repository at this point in the history
* Replace ctime_r with strftime

Signed-off-by: Shruti Sanadhya <ssanadhya@fb.com>
  • Loading branch information
ssanadhya committed Jan 5, 2021
1 parent be117e4 commit 7cdd230
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions lte/gateway/c/oai/common/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"%06" PRIu64 " %s %08lX %-*.*s %-*.*s %-*.*s:%04u [%lu]%*s"

#define LOG_MAGMA_REPO_ROOT "/oai/"
#define MAX_TIME_STR_LEN 32
//-------------------------------

typedef unsigned long log_message_number_t;
Expand Down Expand Up @@ -559,12 +560,15 @@ static void log_get_elapsed_time_since_start(struct timeval * const elapsed_time
}
#endif
//------------------------------------------------------------------------------
static char* log_get_readable_cur_time(time_t* cur_time) {
static void log_get_readable_cur_time(time_t* cur_time, char* time_str) {
// get the current local time
*cur_time = time(NULL);
time(cur_time);
struct tm* cur_local_time;
cur_local_time = localtime(cur_time);
// get the current local time in readable string format
char buf[26];
return (strtok(ctime_r((const time_t*) cur_time, buf), "\n"));
strftime(
time_str, MAX_TIME_STR_LEN, "%a %b %d %H:%M:%S %Y",
(const struct tm*) cur_local_time);
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -1477,11 +1481,12 @@ int append_log_ctx_info(
const log_thread_ctxt_t* thread_ctxt, time_t* cur_time,
const char* short_source_fileP) {
int rv;
char time_str[MAX_TIME_STR_LEN];
log_get_readable_cur_time(cur_time, time_str);
rv = bformata(
bstr, LOG_CTXT_INFO_FMT,
__sync_fetch_and_add(&g_oai_log.log_message_number, 1),
log_get_readable_cur_time(cur_time), thread_ctxt->tid,
LOG_DISPLAYED_LOG_LEVEL_NAME_MAX_LENGTH,
__sync_fetch_and_add(&g_oai_log.log_message_number, 1), time_str,
thread_ctxt->tid, LOG_DISPLAYED_LOG_LEVEL_NAME_MAX_LENGTH,
LOG_DISPLAYED_LOG_LEVEL_NAME_MAX_LENGTH,
&g_oai_log.log_level2str[(*log_levelP)][0],
LOG_DISPLAYED_PROTO_NAME_MAX_LENGTH, LOG_DISPLAYED_PROTO_NAME_MAX_LENGTH,
Expand All @@ -1497,11 +1502,12 @@ int append_log_ctx_info_prefix_id(
size_t filename_length, const log_thread_ctxt_t* thread_ctxt,
time_t* cur_time, const char* short_source_fileP) {
int rv;
char time_str[MAX_TIME_STR_LEN];
log_get_readable_cur_time(cur_time, time_str);
rv = bformata(
bstr, LOG_CTXT_INFO_ID_FMT,
__sync_fetch_and_add(&g_oai_log.log_message_number, 1),
log_get_readable_cur_time(cur_time), thread_ctxt->tid,
LOG_DISPLAYED_LOG_LEVEL_NAME_MAX_LENGTH,
__sync_fetch_and_add(&g_oai_log.log_message_number, 1), time_str,
thread_ctxt->tid, LOG_DISPLAYED_LOG_LEVEL_NAME_MAX_LENGTH,
LOG_DISPLAYED_LOG_LEVEL_NAME_MAX_LENGTH,
&g_oai_log.log_level2str[(*log_levelP)][0],
LOG_DISPLAYED_PROTO_NAME_MAX_LENGTH, LOG_DISPLAYED_PROTO_NAME_MAX_LENGTH,
Expand Down

0 comments on commit 7cdd230

Please sign in to comment.