osaf/libs/core/mds/mds_log.c |  6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)


localtime is not thread safe and it can(has) cause crashes in services
that are multi threaded.

diff --git a/osaf/libs/core/mds/mds_log.c b/osaf/libs/core/mds/mds_log.c
--- a/osaf/libs/core/mds/mds_log.c
+++ b/osaf/libs/core/mds/mds_log.c
@@ -188,6 +188,7 @@ void log_mds_dbg(char *fmt, ...)
 static void log_mds(const char *str)
 {
        FILE *fp;
+       struct tm *tstamp_data, tm_info;
 
        if (lf != NULL && ((fp = fopen(lf, "a+")) != NULL)) {
                struct timeval tv;
@@ -196,7 +197,10 @@ static void log_mds(const char *str)
                int i;
 
                gettimeofday(&tv, NULL);
-               strftime(asc_tod, sizeof(asc_tod), "%b %e %k:%M:%S", 
localtime(&tv.tv_sec));
+               tstamp_data = localtime_r(&tv.tv_sec, &tm_info);
+               osafassert(tstamp_data);
+
+               strftime(asc_tod, sizeof(asc_tod), "%b %e %k:%M:%S", 
tstamp_data);
                i = snprintf(log_string, sizeof(log_string), "%s.%06ld %s %s",
                             asc_tod, tv.tv_usec, log_line_prefix, str);
 

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to