From e04f9ef1093287155f1d0820bd63c4b3c6c5d3d2 Mon Sep 17 00:00:00 2001
From: Nat Goodspeed <nat@lindenlab.com>
Date: Tue, 14 Dec 2010 19:27:43 -0500
Subject: SWAT-352: when loading lleventhost, call apr_dso_error() function. In
 addition to its usual apr_sterror() function, APR defines a special function
 specifically for errors relating to the apr_dso_*() functions. Introduce
 ll_apr_warn_status() and ll_apr_assert_status() overloads accepting
 apr_dso_handle_t* to call apr_dso_error() as well as apr_strerror() and log
 its output. Use new ll_apr_warn_status() in
 LLAppViewer::loadEventHostModule() for apr_dso_load() and apr_dso_sym()
 calls. Instead of shorthand ll_apr_assert_status(), use with
 llassert_always() so check is still performed even in Release build. Add more
 lleventhost-related debugging output, e.g. full pathname of the DLL. On Mac
 and Linux, call 'file' command to report nature of the DLL too.

---
 indra/llcommon/llapr.cpp | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

(limited to 'indra/llcommon/llapr.cpp')

diff --git a/indra/llcommon/llapr.cpp b/indra/llcommon/llapr.cpp
index 66ec5bad2c..d1c44c9403 100644
--- a/indra/llcommon/llapr.cpp
+++ b/indra/llcommon/llapr.cpp
@@ -28,6 +28,7 @@
 
 #include "linden_common.h"
 #include "llapr.h"
+#include "apr_dso.h"
 
 apr_pool_t *gAPRPoolp = NULL; // Global APR memory pool
 LLVolatileAPRPool *LLAPRFile::sAPRFilePoolp = NULL ; //global volatile APR memory pool.
@@ -279,14 +280,31 @@ bool ll_apr_warn_status(apr_status_t status)
 {
 	if(APR_SUCCESS == status) return false;
 	char buf[MAX_STRING];	/* Flawfinder: ignore */
-	apr_strerror(status, buf, MAX_STRING);
+	apr_strerror(status, buf, sizeof(buf));
 	LL_WARNS("APR") << "APR: " << buf << LL_ENDL;
 	return true;
 }
 
+bool ll_apr_warn_status(apr_status_t status, apr_dso_handle_t *handle)
+{
+    bool result = ll_apr_warn_status(status);
+    // Despite observed truncation of actual Mac dylib load errors, increasing
+    // this buffer to more than MAX_STRING doesn't help: it appears that APR
+    // stores the output in a fixed 255-character internal buffer. (*sigh*)
+    char buf[MAX_STRING];           /* Flawfinder: ignore */
+    apr_dso_error(handle, buf, sizeof(buf));
+    LL_WARNS("APR") << "APR: " << buf << LL_ENDL;
+    return result;
+}
+
 void ll_apr_assert_status(apr_status_t status)
 {
-	llassert(ll_apr_warn_status(status) == false);
+	llassert(! ll_apr_warn_status(status));
+}
+
+void ll_apr_assert_status(apr_status_t status, apr_dso_handle_t *handle)
+{
+    llassert(! ll_apr_warn_status(status, handle));
 }
 
 //---------------------------------------------------------------------
-- 
cgit v1.2.3