[Libreoffice-commits] .: sal/osl

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Jan 11 06:48:34 PST 2013


 sal/osl/all/log.cxx |   36 ++++++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 12 deletions(-)

New commits:
commit 4fbf6df784529d48cf194a2d9c495ffb47933d59
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Fri Jan 11 15:46:47 2013 +0100

    Fix workaround for thead-unsafe getenv again
    
    ...from d19c40f45dc8e8bcd9db4c6b83bdcf6367f6fbe7 "Work around some potential
    problems with thread-unsafe getenv" that had been broken with
    60628799633ffde502cb105b98d3f254f93115aa "Notice if SAL_LOG is changed while the
    process is running."
    
    Change-Id: Ibd6dbc9921ae1f8dee114380f01a076b0770788c

diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx
index 2b94f18..13bd7c0 100644
--- a/sal/osl/all/log.cxx
+++ b/sal/osl/all/log.cxx
@@ -89,27 +89,36 @@ char const * toString(sal_detail_LogLevel level) {
     }
 }
 
-// getenv is not thread safe, so minimize use of result:
+// getenv is not thread safe, so minimize use of result; except on Android and
+// iOS, see 60628799633ffde502cb105b98d3f254f93115aa "Notice if SAL_LOG is
+// changed while the process is running":
+#if defined ANDROID || defined IOS
+
 char const * getEnvironmentVariable() {
-    static char const * cached_value = NULL;
+    return std::getenv("SAL_LOG");
+}
+
+#else
+
+char const * getEnvironmentVariable_() {
     char const * p1 = std::getenv("SAL_LOG");
     if (p1 == 0) {
-        return "+WARN";
+        return 0;
     }
-    char * p2 = strdup(p1); // leaked whenever it has changed
+    char const * p2 = strdup(p1); // leaked
     if (p2 == 0) {
         std::abort(); // cannot do much here
     }
-    if (cached_value == NULL) {
-        cached_value = p2;
-    } else if (strcmp(cached_value, p2) == 0) {
-        free(p2);
-    } else {
-        cached_value = p2;
-    }
-    return cached_value;
+    return p2;
 }
 
+char const * getEnvironmentVariable() {
+    static char const * env = getEnvironmentVariable_();
+    return env;
+}
+
+#endif
+
 #ifdef HAVE_SYSLOG_H
 int toSyslogPriority(sal_detail_LogLevel level) {
     switch (level) {
@@ -131,6 +140,9 @@ bool report(sal_detail_LogLevel level, char const * area) {
         return true;
     assert(area != 0);
     char const * env = getEnvironmentVariable();
+    if (env == 0) {
+        env = "+WARN";
+    }
     std::size_t areaLen = std::strlen(area);
     enum Sense { POSITIVE = 0, NEGATIVE = 1 };
     std::size_t senseLen[2] = { 0, 1 };


More information about the Libreoffice-commits mailing list