localtime: use reentrant variant 32/236832/2
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Mon, 22 Jun 2020 10:57:58 +0000 (12:57 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Mon, 22 Jun 2020 11:55:53 +0000 (11:55 +0000)
configure was never setup up properly to support both legacy and reentrant
localtime, consequently legacy variant has been selected all the time.

This commit drops legacy variant leaving reentrant as the default.

Change-Id: Id502121a1197584621cb5b9d65b1c630f2a380f1

Makefile.am
src/libdlog/log.c
src/shared/logprint.c
src/tests/logprint.c

index b8705c2..77c68dd 100644 (file)
@@ -441,7 +441,7 @@ src_tests_config_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=openat64,--wrap=openat,--wra
 
 src_tests_logprint_SOURCES = src/tests/logprint.c src/shared/ptrs_list.c src/shared/logprint.c src/shared/logcommon.c src/shared/queued_entry.c src/shared/parsers.c src/shared/translate_syslog.c src/shared/queued_entry_timestamp.c
 src_tests_logprint_CFLAGS = $(check_CFLAGS)
-src_tests_logprint_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=write,--wrap=malloc,--wrap=calloc,--wrap=localtime,--wrap=strdup,--wrap=strndup,--wrap=list_add
+src_tests_logprint_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=write,--wrap=malloc,--wrap=calloc,--wrap=localtime_r,--wrap=strdup,--wrap=strndup,--wrap=list_add
 
 src_tests_logger_SOURCES = src/tests/logger.c $(dlog_logger_SOURCES)
 src_tests_logger_CFLAGS = $(check_CFLAGS)
index e5e5d17..9256902 100644 (file)
@@ -384,12 +384,8 @@ int __critical_log_append_timestamp(char *buf, size_t buflen)
        const time_t tt = ts.tv_sec;
        const long int real_millisec = ts.tv_nsec / 1000000;
        clock_gettime(CLOCK_MONOTONIC, &ts);
-#ifdef HAVE_LOCALTIME_R
        struct tm tmBuf;
        struct tm *const ptm = localtime_r(&tt, &tmBuf);
-#else
-       struct tm *const ptm = localtime(&tt);
-#endif
        assert(ptm); // we're in a short lived fork so asserts are fine and make things simple
 
        int len = strftime(buf, buflen, "%m-%d %H:%M:%S", ptm);
index 85f2162..6bdb74f 100644 (file)
@@ -671,9 +671,7 @@ char *log_format_json(
                return NULL;
 
        char recv_real[64], recv_mono[64], sent_real[64], sent_mono[64];
-#if defined(HAVE_LOCALTIME_R)
        struct tm tmBuf;
-#endif
        struct tm* ptm;
        time_t time_t_temp;
 
@@ -681,11 +679,7 @@ char *log_format_json(
                recv_real[0] = '\0';
        else {
                time_t_temp = entry->sec_recv_real;
-#if defined(HAVE_LOCALTIME_R)
                ptm = localtime_r(&time_t_temp, &tmBuf);
-#else
-               ptm = localtime(&time_t_temp);
-#endif
                if (!ptm)
                        return NULL;
                strftime(recv_real, sizeof recv_real, "\"recv_real\":\"%FT%T%z\",", ptm);
@@ -695,11 +689,7 @@ char *log_format_json(
                sent_real[0] = '\0';
        else {
                time_t_temp = entry->sec_sent_real;
-#if defined(HAVE_LOCALTIME_R)
                ptm = localtime_r(&time_t_temp, &tmBuf);
-#else
-               ptm = localtime(&time_t_temp);
-#endif
                if (!ptm)
                        return NULL;
                strftime(sent_real, sizeof sent_real, "\"sent_real\":\"%FT%T%z\",", ptm);
@@ -829,9 +819,7 @@ char *log_format_log_line(
                const dlogutil_entry_s *entry,
                size_t *p_outLength)
 {
-#if defined(HAVE_LOCALTIME_R)
        struct tm tmBuf;
-#endif
        struct tm* ptm;
        time_t time_t_temp;
        char timeBuf[32], tzBuf[16];
@@ -886,21 +874,13 @@ char *log_format_log_line(
        nsec_recv = ts.tv_nsec;
 
        time_t_temp = sec_sent;
-#if defined(HAVE_LOCALTIME_R)
        ptm = localtime_r(&time_t_temp, &tmBuf);
-#else
-       ptm = localtime(&time_t_temp);
-#endif
        if (!ptm)
                return NULL;
        strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", ptm);
 
        time_t_temp = sec_recv;
-#if defined(HAVE_LOCALTIME_R)
        ptm = localtime_r(&time_t_temp, &tmBuf);
-#else
-       ptm = localtime(&time_t_temp);
-#endif
        if (!ptm)
                return NULL;
 
index 9b87352..9c00232 100644 (file)
@@ -27,12 +27,12 @@ ssize_t __wrap_write(int fd, const void *buf, size_t count)
        return count;
 }
 
-static int fail_localtime;
-struct tm *__real_localtime(const time_t *timep);
-struct tm *__wrap_localtime(const time_t *timep)
+static int fail_localtime_r;
+struct tm *__real_localtime_r(const time_t *timep, struct tm *result);
+struct tm *__wrap_localtime_r(const time_t *timep, struct tm *result)
 {
-       struct tm *const ret = (fail_localtime & 1) ? NULL : __real_localtime(timep);
-       fail_localtime >>= 1;
+       struct tm *const ret = (fail_localtime_r & 1) ? NULL : __real_localtime_r(timep, result);
+       fail_localtime_r >>= 1;
        return ret;
 }
 
@@ -691,9 +691,9 @@ void check_syscall_failure_handling()
        assert(-1 == log_print_log_line(format, 0, &entry.header));
        fail_alloc = false;
 
-       fail_localtime = 1;
+       fail_localtime_r = 1;
        assert(-1 == log_print_log_line(format, 0, &entry.header));
-       fail_localtime = 2;
+       fail_localtime_r = 2;
        assert(-1 == log_print_log_line(format, 0, &entry.header));
 
        partial_write = -1;