[Libreoffice-commits] .: sal/osl

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Sat Jan 5 13:07:13 PST 2013


 sal/osl/all/log.cxx |   17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

New commits:
commit 60628799633ffde502cb105b98d3f254f93115aa
Author: Tor Lillqvist <tml at iki.fi>
Date:   Sat Jan 5 22:57:39 2013 +0200

    Notice if SAL_LOG is changed while the process is running
    
    It used to call getenv("SAL_LOG") just once and assume it never changed.
    
    Sure, I don't expect that LO code will start changing SAL_LOG back and forth
    all the time. But it is definitely useful in our Android (and iOS) apps to be
    able to call for instance putenv("SAL_LOG=+WARN+INFO") as early as possible,
    before explicitly using any LO code.
    
    That used to work earlier, but not any more with the getEnvironmentVariable()
    thing, as the new logging mechanism gets called while initialising some static
    globals (i.e. before out app code had even started), and that then caused the
    one and only call to getenv("SAL_LOG").
    
    This meant that we didn't get any debugging logging from SAL_INFO and friends
    in the Android app(s) any more.
    
    Change-Id: I932facff4118e5f016c95a4c1461e871184d3fc6

diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx
index 7e43082..6b98c04 100644
--- a/sal/osl/all/log.cxx
+++ b/sal/osl/all/log.cxx
@@ -56,6 +56,9 @@
 #define OSL_DETAIL_GETPID getpid()
 #endif
 
+#include <android/log.h>
+#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "log.cxx", __VA_ARGS__))
+
 #ifdef HAVE_SYSLOG_H
 #include <syslog.h>
 // sal/osl/unx/salinit.cxx::sal_detail_initialize updates this:
@@ -91,15 +94,23 @@ char const * toString(sal_detail_LogLevel level) {
 
 // getenv is not thread safe, so minimize use of result:
 char const * getEnvironmentVariable() {
+    static char const * cached_value = NULL;
     char const * p1 = std::getenv("SAL_LOG");
     if (p1 == 0) {
         return "+WARN";
     }
-    char const * p2 = strdup(p1); // leaked
+    char * p2 = strdup(p1); // leaked whenever it has changed
     if (p2 == 0) {
         std::abort(); // cannot do much here
     }
-    return p2;
+    if (cached_value == NULL) {
+        cached_value = p2;
+    } else if (strcmp(cached_value, p2) == 0) {
+        free(p2);
+    } else {
+        cached_value = p2;
+    }
+    return cached_value;
 }
 
 #ifdef HAVE_SYSLOG_H
@@ -122,7 +133,7 @@ bool report(sal_detail_LogLevel level, char const * area) {
     if (level == SAL_DETAIL_LOG_LEVEL_DEBUG)
         return true;
     assert(area != 0);
-    static char const * env = getEnvironmentVariable();
+    char const * env = getEnvironmentVariable();
     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