[Libreoffice-commits] .: 3 commits - sal/Library_sal.mk sal/osl
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Wed Sep 12 05:19:17 PDT 2012
sal/Library_sal.mk | 2
sal/osl/all/log.cxx | 19 ++
sal/osl/unx/diagnose.c | 305 ---------------------------------------------
sal/osl/unx/diagnose.cxx | 316 +++++++++++++++++++++++++++++++++++++++++++++++
sal/osl/unx/file.cxx | 28 +---
sal/osl/unx/file_url.cxx | 3
sal/osl/unx/process.cxx | 27 ----
7 files changed, 350 insertions(+), 350 deletions(-)
New commits:
commit d19c40f45dc8e8bcd9db4c6b83bdcf6367f6fbe7
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Wed Sep 12 14:10:44 2012 +0200
Work around some potential problems with thread-unsafe getenv
I have seen at least one failure of one of our unoapi tests where soffice.bin
crashed in getenv(3). This patch is just a drop in the ocean, though.
Change-Id: Iac8a2283b0a62e4fa95a0d063c1676af6c2390be
diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx
index bac0e93..934d88a 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 };
diff --git a/sal/osl/unx/diagnose.cxx b/sal/osl/unx/diagnose.cxx
index 38f11e0..8c289f2 100644
--- a/sal/osl/unx/diagnose.cxx
+++ b/sal/osl/unx/diagnose.cxx
@@ -209,6 +209,17 @@ static void osl_diagnose_backtrace_Impl (oslDebugMessageFunc f)
/************************************************************************/
/* osl_assertFailedLine */
/************************************************************************/
+
+namespace {
+
+// getenv is not thread safe, so minimize use of result:
+bool isEnv(char const * name) {
+ char * p = getenv(name);
+ return p != NULL && *p != '\0';
+}
+
+}
+
sal_Bool SAL_CALL osl_assertFailedLine (
const sal_Char* pszFileName,
sal_Int32 nLine,
@@ -219,9 +230,9 @@ sal_Bool SAL_CALL osl_assertFailedLine (
// after reporting the assertion, abort if told so by SAL_DIAGNOSE_ABORT, but *not* if
// assertions are routed to some external instance
- char const * env = getenv( "SAL_DIAGNOSE_ABORT" );
- char const * envBacktrace = getenv( "SAL_DIAGNOSE_BACKTRACE" );
- sal_Bool const doAbort = ( ( env != NULL ) && ( *env != '\0' ) && ( f == NULL ) );
+ static bool envAbort = isEnv( "SAL_DIAGNOSE_ABORT" );
+ static bool envBacktrace = isEnv( "SAL_DIAGNOSE_BACKTRACE" );
+ sal_Bool const doAbort = envAbort && f == NULL;
/* If there's a callback for detailed messages, use it */
if ( g_pDetailedDebugMessageFunc != NULL )
@@ -251,7 +262,7 @@ sal_Bool SAL_CALL osl_assertFailedLine (
OSL_DIAGNOSE_OUTPUTMESSAGE(f, szMessage);
/* should we output backtrace? */
- if( envBacktrace != NULL && *envBacktrace != '\0' )
+ if( envBacktrace )
osl_diagnose_backtrace_Impl(f);
/* release lock and leave */
diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx
index 536e1bf..699cb31 100644
--- a/sal/osl/unx/file.cxx
+++ b/sal/osl/unx/file.cxx
@@ -831,27 +831,19 @@ static int osl_file_adjustLockFlags (const char * path, int flags)
/****************************************************************************
* osl_file_queryLocking
***************************************************************************/
-struct Locking_Impl
+static bool osl_file_queryLocking (sal_uInt32 uFlags)
{
- int m_enabled;
- Locking_Impl() : m_enabled(0)
+#if !defined HAVE_O_EXLOCK
+ if (!(uFlags & osl_File_OpenFlag_NoLock)
+ && ((uFlags & osl_File_OpenFlag_Write)
+ || (uFlags & osl_File_OpenFlag_Create)))
{
-#ifndef HAVE_O_EXLOCK
- m_enabled = (getenv("SAL_ENABLE_FILE_LOCKING") != 0);
-#endif /* HAVE_O_EXLOCK */
- }
-};
-static int osl_file_queryLocking (sal_uInt32 uFlags)
-{
- if (!(uFlags & osl_File_OpenFlag_NoLock))
- {
- if ((uFlags & osl_File_OpenFlag_Write) || (uFlags & osl_File_OpenFlag_Create))
- {
- static Locking_Impl g_locking;
- return (g_locking.m_enabled != 0);
- }
+ static bool enabled = getenv("SAL_ENABLE_FILE_LOCKING") != 0;
+ // getenv is not thread safe, so minimize use of result
+ return enabled;
}
- return 0;
+#endif
+ return false;
}
#ifdef UNX
diff --git a/sal/osl/unx/file_url.cxx b/sal/osl/unx/file_url.cxx
index 7addb8e..b582515 100644
--- a/sal/osl/unx/file_url.cxx
+++ b/sal/osl/unx/file_url.cxx
@@ -633,7 +633,6 @@ oslFileError osl_getAbsoluteFileURL(rtl_uString* ustrBaseDirURL, rtl_uString* u
{
FileBase::RC rc;
rtl::OUString unresolved_path;
- static char *allow_symlinks = getenv( "SAL_ALLOW_LINKOO_SYMLINKS" );
rc = FileBase::getSystemPathFromFileURL(rtl::OUString(ustrRelativeURL), unresolved_path);
@@ -656,6 +655,8 @@ oslFileError osl_getAbsoluteFileURL(rtl_uString* ustrBaseDirURL, rtl_uString* u
rtl::OUString resolved_path;
+ static bool allow_symlinks = getenv("SAL_ALLOW_LINKOO_SYMLINKS") != 0;
+ // getenv is not thread safe, so minimize use of result
if (!allow_symlinks)
{
rc = (FileBase::RC) osl_getAbsoluteFileURL_impl_(unresolved_path, resolved_path);
commit 2738355f9f10d31ba942d4c2142e3c6dd20055d3
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Wed Sep 12 13:51:48 2012 +0200
diagnose.c -> diagnose.cxx (to ease further modification)
Change-Id: I6c050c0cedab6aeed556dc770c3700e6fbbb4731
diff --git a/sal/Library_sal.mk b/sal/Library_sal.mk
index de22417..4da0e3b 100644
--- a/sal/Library_sal.mk
+++ b/sal/Library_sal.mk
@@ -161,6 +161,7 @@ endif
ifeq ($(GUI),UNX)
$(eval $(call gb_Library_add_exception_objects,sal,\
sal/osl/unx/conditn \
+ sal/osl/unx/diagnose \
sal/osl/unx/file \
sal/osl/unx/file_error_transl \
sal/osl/unx/file_misc \
@@ -175,7 +176,6 @@ $(eval $(call gb_Library_add_exception_objects,sal,\
sal/osl/unx/uunxapi \
))
$(eval $(call gb_Library_add_cobjects,sal,\
- sal/osl/unx/diagnose \
sal/osl/unx/mutex \
sal/osl/unx/nlsupport \
sal/osl/unx/pipe \
diff --git a/sal/osl/unx/diagnose.c b/sal/osl/unx/diagnose.c
deleted file mode 100644
index 38f11e0..0000000
--- a/sal/osl/unx/diagnose.c
+++ /dev/null
@@ -1,305 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-#include "osl/diagnose.h"
-#include "system.h"
-
-#ifndef HAVE_DLFCN_H
-
-#if defined(LINUX) || defined(SOLARIS)
-#define HAVE_DLFCN_H
-#endif /* LINUX || SOLARIS */
-
-#endif /* HAVE_DLFCN_H */
-
-
-#ifdef HAVE_DLFCN_H
-
-#ifndef INCLUDED_DLFCN_H
-#include <dlfcn.h>
-#define INCLUDED_DLFCN_H
-#endif
-
-#endif /* HAVE_DLFCN_H */
-
-#ifndef INCLUDED_PTHREAD_H
-#include <pthread.h>
-#define INCLUDED_PTHREAD_H
-#endif
-
-#ifndef INCLUDED_STDDEF_H
-#include <stddef.h>
-#define INCLUDED_STDDEF_H
-#endif
-
-/************************************************************************/
-/* Internal data structures and functions */
-/************************************************************************/
-
-static pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER;
-
-typedef pfunc_osl_printDebugMessage oslDebugMessageFunc;
-static oslDebugMessageFunc volatile g_pDebugMessageFunc = 0;
-
-typedef pfunc_osl_printDetailedDebugMessage oslDetailedDebugMessageFunc;
-static oslDetailedDebugMessageFunc volatile g_pDetailedDebugMessageFunc = 0;
-
-static void osl_diagnose_backtrace_Impl (
- oslDebugMessageFunc f);
-
-#define OSL_DIAGNOSE_OUTPUTMESSAGE(f, s) \
-((f != 0) ? (*(f))((s)) : (void)fprintf(stderr, "%s", (s)))
-
-#if defined (LINUX) || defined (SOLARIS)
-/************************************************************************/
-/* osl_diagnose_frame_Impl */
-/************************************************************************/
-static void osl_diagnose_frame_Impl (
- oslDebugMessageFunc f,
- int depth,
- void * pc)
-{
- const char *fname = 0, *sname = 0;
- void *fbase = 0, *saddr = 0;
- ptrdiff_t offset;
- char szMessage[1024];
-
-#ifdef INCLUDED_DLFCN_H
- Dl_info dli;
- if (dladdr (pc, &dli) != 0)
- {
- fname = dli.dli_fname;
- fbase = dli.dli_fbase;
- sname = dli.dli_sname;
- saddr = dli.dli_saddr;
- }
-#endif /* INCLUDED_DLFCN_H */
-
- if (saddr)
- offset = (ptrdiff_t)(pc) - (ptrdiff_t)(saddr);
- else if (fbase)
- offset = (ptrdiff_t)(pc) - (ptrdiff_t)(fbase);
- else
- offset = (ptrdiff_t)(pc);
-
- snprintf (szMessage, sizeof(szMessage),
- "Backtrace: [%d] %s: %s+0x%" SAL_PRI_PTRDIFFT "x\n",
- depth,
- fname ? fname : "<unknown>",
- sname ? sname : "???",
- offset);
-
- OSL_DIAGNOSE_OUTPUTMESSAGE(f, szMessage);
-}
-#endif
-
-/************************************************************************/
-/* osl_diagnose_backtrace_Impl */
-/************************************************************************/
-#if defined(LINUX)
-
-#include <execinfo.h>
-
-#define FRAME_COUNT 64
-#define FRAME_OFFSET 1
-
-static void osl_diagnose_backtrace_Impl (oslDebugMessageFunc f)
-{
- void * ppFrames[FRAME_COUNT];
- int i, n;
-
- n = backtrace (ppFrames, FRAME_COUNT);
- for (i = FRAME_OFFSET; i < n; i++)
- {
- osl_diagnose_frame_Impl (f, (i - FRAME_OFFSET), ppFrames[i]);
- }
-}
-
-#elif defined(SOLARIS)
-
-#include <pthread.h>
-#include <setjmp.h>
-#include <sys/frame.h>
-
-#if defined(SPARC)
-
-#if defined IS_LP64
-
-#define FRAME_PTR_OFFSET 1
-#define FRAME_OFFSET 0
-#define STACK_BIAS 0x7ff
-
-#else
-
-#define FRAME_PTR_OFFSET 1
-#define FRAME_OFFSET 0
-#define STACK_BIAS 0
-
-#endif
-
-#elif defined(INTEL)
-
-#define FRAME_PTR_OFFSET 3
-#define FRAME_OFFSET 0
-#define STACK_BIAS 0
-
-#endif /* (SPARC || INTEL) */
-
-static void osl_diagnose_backtrace_Impl (oslDebugMessageFunc f)
-{
- jmp_buf ctx;
- long fpval;
- struct frame * fp;
- int i;
-
-#if defined(SPARC)
- asm("ta 3");
-#endif /* SPARC */
- setjmp (ctx);
-
- fpval = ((long*)(ctx))[FRAME_PTR_OFFSET];
- fp = (struct frame*)((char*)(fpval) + STACK_BIAS);
-
- for (i = 0; (i < FRAME_OFFSET) && (fp != 0); i++)
- fp = (struct frame*)((char*)(fp->fr_savfp) + STACK_BIAS);
-
- for (i = 0; (fp != 0) && (fp->fr_savpc != 0); i++)
- {
- struct frame * prev = (struct frame*)((char*)(fp->fr_savfp) + STACK_BIAS);
- osl_diagnose_frame_Impl (f, i, (void*)(fp->fr_savpc));
- fp = (prev > fp) ? prev : 0;
- }
-}
-
-#else /* (LINUX || SOLARIS) */
-
-static void osl_diagnose_backtrace_Impl (oslDebugMessageFunc f)
-{
- (void) f;
- /* not yet implemented */
-}
-
-#endif /* (LINUX || SOLARIS) */
-
-/************************************************************************/
-/* osl_assertFailedLine */
-/************************************************************************/
-sal_Bool SAL_CALL osl_assertFailedLine (
- const sal_Char* pszFileName,
- sal_Int32 nLine,
- const sal_Char* pszMessage)
-{
- oslDebugMessageFunc f = g_pDebugMessageFunc;
- char szMessage[1024];
-
- // after reporting the assertion, abort if told so by SAL_DIAGNOSE_ABORT, but *not* if
- // assertions are routed to some external instance
- char const * env = getenv( "SAL_DIAGNOSE_ABORT" );
- char const * envBacktrace = getenv( "SAL_DIAGNOSE_BACKTRACE" );
- sal_Bool const doAbort = ( ( env != NULL ) && ( *env != '\0' ) && ( f == NULL ) );
-
- /* If there's a callback for detailed messages, use it */
- if ( g_pDetailedDebugMessageFunc != NULL )
- {
- g_pDetailedDebugMessageFunc( pszFileName, nLine, pszMessage );
- return sal_False;
- }
-
- /* format message into buffer */
- if (pszMessage != 0)
- {
- snprintf(szMessage, sizeof(szMessage),
- "Error: File %s, Line %" SAL_PRIdINT32 ": %s\n",
- pszFileName, nLine, pszMessage);
- }
- else
- {
- snprintf(szMessage, sizeof(szMessage),
- "Error: File %s, Line %" SAL_PRIdINT32 "\n",
- pszFileName, nLine);
- }
-
- /* acquire lock to serialize output message(s) */
- pthread_mutex_lock(&g_mutex);
-
- /* output message buffer */
- OSL_DIAGNOSE_OUTPUTMESSAGE(f, szMessage);
-
- /* should we output backtrace? */
- if( envBacktrace != NULL && *envBacktrace != '\0' )
- osl_diagnose_backtrace_Impl(f);
-
- /* release lock and leave */
- pthread_mutex_unlock(&g_mutex);
-
- return doAbort;
-}
-
-/************************************************************************/
-/* osl_breakDebug */
-/************************************************************************/
-void SAL_CALL osl_breakDebug()
-{
- abort();
-}
-
-/************************************************************************/
-/* osl_reportError */
-/************************************************************************/
-sal_Int32 SAL_CALL osl_reportError (
- sal_uInt32 nType,
- const sal_Char* pszMessage)
-{
- (void) nType; /* unused */
- fputs(pszMessage, stderr);
- return 0;
-}
-
-/************************************************************************/
-/* osl_setDebugMessageFunc */
-/************************************************************************/
-oslDebugMessageFunc SAL_CALL osl_setDebugMessageFunc (
- oslDebugMessageFunc pNewFunc)
-{
- oslDebugMessageFunc pOldFunc = g_pDebugMessageFunc;
- g_pDebugMessageFunc = pNewFunc;
- return pOldFunc;
-}
-
-/************************************************************************/
-/* osl_setDetailedDebugMessageFunc */
-/************************************************************************/
-pfunc_osl_printDetailedDebugMessage SAL_CALL osl_setDetailedDebugMessageFunc (
- pfunc_osl_printDetailedDebugMessage pNewFunc)
-{
- oslDetailedDebugMessageFunc pOldFunc = g_pDetailedDebugMessageFunc;
- g_pDetailedDebugMessageFunc = pNewFunc;
- return pOldFunc;
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/osl/unx/diagnose.cxx b/sal/osl/unx/diagnose.cxx
new file mode 100644
index 0000000..38f11e0
--- /dev/null
+++ b/sal/osl/unx/diagnose.cxx
@@ -0,0 +1,305 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "osl/diagnose.h"
+#include "system.h"
+
+#ifndef HAVE_DLFCN_H
+
+#if defined(LINUX) || defined(SOLARIS)
+#define HAVE_DLFCN_H
+#endif /* LINUX || SOLARIS */
+
+#endif /* HAVE_DLFCN_H */
+
+
+#ifdef HAVE_DLFCN_H
+
+#ifndef INCLUDED_DLFCN_H
+#include <dlfcn.h>
+#define INCLUDED_DLFCN_H
+#endif
+
+#endif /* HAVE_DLFCN_H */
+
+#ifndef INCLUDED_PTHREAD_H
+#include <pthread.h>
+#define INCLUDED_PTHREAD_H
+#endif
+
+#ifndef INCLUDED_STDDEF_H
+#include <stddef.h>
+#define INCLUDED_STDDEF_H
+#endif
+
+/************************************************************************/
+/* Internal data structures and functions */
+/************************************************************************/
+
+static pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+typedef pfunc_osl_printDebugMessage oslDebugMessageFunc;
+static oslDebugMessageFunc volatile g_pDebugMessageFunc = 0;
+
+typedef pfunc_osl_printDetailedDebugMessage oslDetailedDebugMessageFunc;
+static oslDetailedDebugMessageFunc volatile g_pDetailedDebugMessageFunc = 0;
+
+static void osl_diagnose_backtrace_Impl (
+ oslDebugMessageFunc f);
+
+#define OSL_DIAGNOSE_OUTPUTMESSAGE(f, s) \
+((f != 0) ? (*(f))((s)) : (void)fprintf(stderr, "%s", (s)))
+
+#if defined (LINUX) || defined (SOLARIS)
+/************************************************************************/
+/* osl_diagnose_frame_Impl */
+/************************************************************************/
+static void osl_diagnose_frame_Impl (
+ oslDebugMessageFunc f,
+ int depth,
+ void * pc)
+{
+ const char *fname = 0, *sname = 0;
+ void *fbase = 0, *saddr = 0;
+ ptrdiff_t offset;
+ char szMessage[1024];
+
+#ifdef INCLUDED_DLFCN_H
+ Dl_info dli;
+ if (dladdr (pc, &dli) != 0)
+ {
+ fname = dli.dli_fname;
+ fbase = dli.dli_fbase;
+ sname = dli.dli_sname;
+ saddr = dli.dli_saddr;
+ }
+#endif /* INCLUDED_DLFCN_H */
+
+ if (saddr)
+ offset = (ptrdiff_t)(pc) - (ptrdiff_t)(saddr);
+ else if (fbase)
+ offset = (ptrdiff_t)(pc) - (ptrdiff_t)(fbase);
+ else
+ offset = (ptrdiff_t)(pc);
+
+ snprintf (szMessage, sizeof(szMessage),
+ "Backtrace: [%d] %s: %s+0x%" SAL_PRI_PTRDIFFT "x\n",
+ depth,
+ fname ? fname : "<unknown>",
+ sname ? sname : "???",
+ offset);
+
+ OSL_DIAGNOSE_OUTPUTMESSAGE(f, szMessage);
+}
+#endif
+
+/************************************************************************/
+/* osl_diagnose_backtrace_Impl */
+/************************************************************************/
+#if defined(LINUX)
+
+#include <execinfo.h>
+
+#define FRAME_COUNT 64
+#define FRAME_OFFSET 1
+
+static void osl_diagnose_backtrace_Impl (oslDebugMessageFunc f)
+{
+ void * ppFrames[FRAME_COUNT];
+ int i, n;
+
+ n = backtrace (ppFrames, FRAME_COUNT);
+ for (i = FRAME_OFFSET; i < n; i++)
+ {
+ osl_diagnose_frame_Impl (f, (i - FRAME_OFFSET), ppFrames[i]);
+ }
+}
+
+#elif defined(SOLARIS)
+
+#include <pthread.h>
+#include <setjmp.h>
+#include <sys/frame.h>
+
+#if defined(SPARC)
+
+#if defined IS_LP64
+
+#define FRAME_PTR_OFFSET 1
+#define FRAME_OFFSET 0
+#define STACK_BIAS 0x7ff
+
+#else
+
+#define FRAME_PTR_OFFSET 1
+#define FRAME_OFFSET 0
+#define STACK_BIAS 0
+
+#endif
+
+#elif defined(INTEL)
+
+#define FRAME_PTR_OFFSET 3
+#define FRAME_OFFSET 0
+#define STACK_BIAS 0
+
+#endif /* (SPARC || INTEL) */
+
+static void osl_diagnose_backtrace_Impl (oslDebugMessageFunc f)
+{
+ jmp_buf ctx;
+ long fpval;
+ struct frame * fp;
+ int i;
+
+#if defined(SPARC)
+ asm("ta 3");
+#endif /* SPARC */
+ setjmp (ctx);
+
+ fpval = ((long*)(ctx))[FRAME_PTR_OFFSET];
+ fp = (struct frame*)((char*)(fpval) + STACK_BIAS);
+
+ for (i = 0; (i < FRAME_OFFSET) && (fp != 0); i++)
+ fp = (struct frame*)((char*)(fp->fr_savfp) + STACK_BIAS);
+
+ for (i = 0; (fp != 0) && (fp->fr_savpc != 0); i++)
+ {
+ struct frame * prev = (struct frame*)((char*)(fp->fr_savfp) + STACK_BIAS);
+ osl_diagnose_frame_Impl (f, i, (void*)(fp->fr_savpc));
+ fp = (prev > fp) ? prev : 0;
+ }
+}
+
+#else /* (LINUX || SOLARIS) */
+
+static void osl_diagnose_backtrace_Impl (oslDebugMessageFunc f)
+{
+ (void) f;
+ /* not yet implemented */
+}
+
+#endif /* (LINUX || SOLARIS) */
+
+/************************************************************************/
+/* osl_assertFailedLine */
+/************************************************************************/
+sal_Bool SAL_CALL osl_assertFailedLine (
+ const sal_Char* pszFileName,
+ sal_Int32 nLine,
+ const sal_Char* pszMessage)
+{
+ oslDebugMessageFunc f = g_pDebugMessageFunc;
+ char szMessage[1024];
+
+ // after reporting the assertion, abort if told so by SAL_DIAGNOSE_ABORT, but *not* if
+ // assertions are routed to some external instance
+ char const * env = getenv( "SAL_DIAGNOSE_ABORT" );
+ char const * envBacktrace = getenv( "SAL_DIAGNOSE_BACKTRACE" );
+ sal_Bool const doAbort = ( ( env != NULL ) && ( *env != '\0' ) && ( f == NULL ) );
+
+ /* If there's a callback for detailed messages, use it */
+ if ( g_pDetailedDebugMessageFunc != NULL )
+ {
+ g_pDetailedDebugMessageFunc( pszFileName, nLine, pszMessage );
+ return sal_False;
+ }
+
+ /* format message into buffer */
+ if (pszMessage != 0)
+ {
+ snprintf(szMessage, sizeof(szMessage),
+ "Error: File %s, Line %" SAL_PRIdINT32 ": %s\n",
+ pszFileName, nLine, pszMessage);
+ }
+ else
+ {
+ snprintf(szMessage, sizeof(szMessage),
+ "Error: File %s, Line %" SAL_PRIdINT32 "\n",
+ pszFileName, nLine);
+ }
+
+ /* acquire lock to serialize output message(s) */
+ pthread_mutex_lock(&g_mutex);
+
+ /* output message buffer */
+ OSL_DIAGNOSE_OUTPUTMESSAGE(f, szMessage);
+
+ /* should we output backtrace? */
+ if( envBacktrace != NULL && *envBacktrace != '\0' )
+ osl_diagnose_backtrace_Impl(f);
+
+ /* release lock and leave */
+ pthread_mutex_unlock(&g_mutex);
+
+ return doAbort;
+}
+
+/************************************************************************/
+/* osl_breakDebug */
+/************************************************************************/
+void SAL_CALL osl_breakDebug()
+{
+ abort();
+}
+
+/************************************************************************/
+/* osl_reportError */
+/************************************************************************/
+sal_Int32 SAL_CALL osl_reportError (
+ sal_uInt32 nType,
+ const sal_Char* pszMessage)
+{
+ (void) nType; /* unused */
+ fputs(pszMessage, stderr);
+ return 0;
+}
+
+/************************************************************************/
+/* osl_setDebugMessageFunc */
+/************************************************************************/
+oslDebugMessageFunc SAL_CALL osl_setDebugMessageFunc (
+ oslDebugMessageFunc pNewFunc)
+{
+ oslDebugMessageFunc pOldFunc = g_pDebugMessageFunc;
+ g_pDebugMessageFunc = pNewFunc;
+ return pOldFunc;
+}
+
+/************************************************************************/
+/* osl_setDetailedDebugMessageFunc */
+/************************************************************************/
+pfunc_osl_printDetailedDebugMessage SAL_CALL osl_setDetailedDebugMessageFunc (
+ pfunc_osl_printDetailedDebugMessage pNewFunc)
+{
+ oslDetailedDebugMessageFunc pOldFunc = g_pDetailedDebugMessageFunc;
+ g_pDetailedDebugMessageFunc = pNewFunc;
+ return pOldFunc;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit bb5ea68ed5e48b1ac39a279a9fc9a0d9b6ff71e4
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Wed Sep 12 13:29:40 2012 +0200
Simplify osl_searchPath_impl
Change-Id: I78a97b5a1abbcb7921eba60b8014a21373c0b596
diff --git a/sal/osl/unx/process.cxx b/sal/osl/unx/process.cxx
index 280b7ec..eb1fdf4 100644
--- a/sal/osl/unx/process.cxx
+++ b/sal/osl/unx/process.cxx
@@ -120,14 +120,6 @@ oslProcessError SAL_CALL osl_psz_executeProcess(sal_Char *pszImageName,
oslFileHandle *pErrorRead );
-oslProcessError SAL_CALL osl_searchPath_impl(
- const sal_Char* pszName,
- const sal_Char* pszPath,
- sal_Char Separator,
- sal_Char *pszBuffer,
- sal_uInt32 Max);
-
-
sal_Bool osl_getFullPath(const sal_Char* pszFilename, sal_Char* pszPath, sal_uInt32 MaxLen);
static oslProcessImpl* ChildList;
@@ -140,8 +132,8 @@ static oslMutex ChildListMutex;
A new implemenation is in file_path_helper.cxx
*****************************************************************************/
-oslProcessError SAL_CALL osl_searchPath_impl(const sal_Char* pszName, const sal_Char* pszPath,
- sal_Char Separator, sal_Char *pszBuffer, sal_uInt32 Max)
+static oslProcessError SAL_CALL osl_searchPath_impl(const sal_Char* pszName,
+ sal_Char *pszBuffer, sal_uInt32 Max)
{
sal_Char path[PATH_MAX + 1];
sal_Char *pchr;
@@ -155,14 +147,7 @@ oslProcessError SAL_CALL osl_searchPath_impl(const sal_Char* pszName, const sal_
return osl_Process_E_NotFound;
}
- if (pszPath == NULL)
- pszPath = "PATH";
-
- if (Separator == '\0')
- Separator = ':';
-
-
- if ( (pchr = getenv(pszPath)) != 0 )
+ if ( (pchr = getenv("PATH")) != 0 )
{
sal_Char *pstr;
@@ -170,7 +155,7 @@ oslProcessError SAL_CALL osl_searchPath_impl(const sal_Char* pszName, const sal_
{
pstr = path;
- while ((*pchr != '\0') && (*pchr != Separator))
+ while ((*pchr != '\0') && (*pchr != ':'))
*pstr++ = *pchr++;
if ((pstr > path) && ((*(pstr - 1) != '/')))
@@ -192,7 +177,7 @@ oslProcessError SAL_CALL osl_searchPath_impl(const sal_Char* pszName, const sal_
return osl_Process_E_None;
}
- if (*pchr == Separator)
+ if (*pchr == ':')
pchr++;
}
}
@@ -698,7 +683,7 @@ oslProcessError SAL_CALL osl_psz_executeProcess(sal_Char *pszImageName,
}
if ((Options & osl_Process_SEARCHPATH) &&
- (osl_searchPath_impl(pszImageName, NULL, '\0', path, sizeof(path)) == osl_Process_E_None))
+ (osl_searchPath_impl(pszImageName, path, sizeof(path)) == osl_Process_E_None))
pszImageName = path;
Data.m_pszArgs[0] = strdup(pszImageName);
More information about the Libreoffice-commits
mailing list