summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2013-01-11 15:46:47 +0100
committerStephan Bergmann <sbergman@redhat.com>2013-01-11 15:48:12 +0100
commit4fbf6df784529d48cf194a2d9c495ffb47933d59 (patch)
tree0aa1d545519240f0efc6e177be835405113e2bb8 /sal
parent03910bdfd964ee34bdd93fda3339908cad2b01f4 (diff)
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
Diffstat (limited to 'sal')
-rw-r--r--sal/osl/all/log.cxx36
1 files changed, 24 insertions, 12 deletions
diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx
index 2b94f180bf5b..13bd7c0b987f 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 };