summaryrefslogtreecommitdiffstats
path: root/sal/osl/all/log.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sal/osl/all/log.cxx')
-rw-r--r--sal/osl/all/log.cxx19
1 files changed, 15 insertions, 4 deletions
diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx
index bac0e9313919..934d88aa0a3e 100644
--- a/sal/osl/all/log.cxx
+++ b/sal/osl/all/log.cxx
@@ -38,6 +38,7 @@
#include <sstream>
#include <stdio.h> // vsnprintf
+#include <string.h> // strdup
#include "osl/thread.hxx"
#include "rtl/string.h"
@@ -82,14 +83,24 @@ char const * toString(sal_detail_LogLevel level) {
}
}
+// getenv is not thread safe, so minimize use of result:
+char const * getEnvironmentVariable() {
+ char const * p1 = std::getenv("SAL_LOG");
+ if (p1 == 0) {
+ return "+WARN";
+ }
+ char const * p2 = strdup(p1); // leaked
+ if (p2 == 0) {
+ std::abort(); // cannot do much here
+ }
+ return p2;
+}
+
bool report(sal_detail_LogLevel level, char const * area) {
if (level == SAL_DETAIL_LOG_LEVEL_DEBUG)
return true;
assert(area != 0);
- char const * env = std::getenv("SAL_LOG");
- if (env == 0) {
- env = "+WARN";
- }
+ static char const * env = getEnvironmentVariable();
std::size_t areaLen = std::strlen(area);
enum Sense { POSITIVE = 0, NEGATIVE = 1 };
std::size_t senseLen[2] = { 0, 1 };