summaryrefslogtreecommitdiff
path: root/indra/media_plugins/base/media_plugin_base.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/media_plugins/base/media_plugin_base.cpp')
-rw-r--r--indra/media_plugins/base/media_plugin_base.cpp99
1 files changed, 98 insertions, 1 deletions
diff --git a/indra/media_plugins/base/media_plugin_base.cpp b/indra/media_plugins/base/media_plugin_base.cpp
index 545eee25a9..d54e67c532 100644
--- a/indra/media_plugins/base/media_plugin_base.cpp
+++ b/indra/media_plugins/base/media_plugin_base.cpp
@@ -167,10 +167,60 @@ void MediaPluginBase::sendStatus()
sendMessage(message);
}
+#if LL_LINUX || __FreeBSD__
+
+size_t SymbolGrabber::registerSymbol( SymbolToGrab aSymbol )
+{
+ gSymbolsToGrab.emplace_back(aSymbol);
+ return gSymbolsToGrab.size();
+}
+
+bool SymbolGrabber::grabSymbols(std::vector< std::string > const &aDSONames)
+{
+ std::cerr << "SYMBOLS: " << gSymbolsToGrab.size() << std::endl;
+
+ if (sSymsGrabbed)
+ return true;
+
+ //attempt to load the shared libraries
+ apr_pool_create(&sSymDSOMemoryPool, nullptr);
+
+ for( std::vector< std::string >::const_iterator itr = aDSONames.begin(); itr != aDSONames.end(); ++itr )
+ {
+ apr_dso_handle_t *pDSO(NULL);
+ std::string strDSO{ *itr };
+ if( APR_SUCCESS == apr_dso_load( &pDSO, strDSO.c_str(), sSymDSOMemoryPool ))
+ sLoadedLibraries.push_back( pDSO );
+
+ for( auto i = 0; i < gSymbolsToGrab.size(); ++i )
+ {
+ if( !*gSymbolsToGrab[i].mPPFunc )
+ apr_dso_sym( gSymbolsToGrab[i].mPPFunc, pDSO, gSymbolsToGrab[i].mName );
+ }
+ }
+
+ bool sym_error = false;
+
+ for( auto i = 0; i < gSymbolsToGrab.size(); ++i )
+ {
+ if( gSymbolsToGrab[ i ].mRequired && ! *gSymbolsToGrab[ i ].mPPFunc )
+ sym_error = true;
+ }
+
+ sSymsGrabbed = !sym_error;
+ return sSymsGrabbed;
+}
+
+void SymbolGrabber::ungrabSymbols()
+{
+
+}
+#endif
+
#if LL_WINDOWS
# define LLSYMEXPORT __declspec(dllexport)
-#elif LL_LINUX
+#elif LL_LINUX || __FreeBSD__
# define LLSYMEXPORT __attribute__ ((visibility("default")))
#else
# define LLSYMEXPORT /**/
@@ -204,3 +254,50 @@ int WINAPI DllEntryPoint( HINSTANCE hInstance, unsigned long reason, void* param
return 1;
}
#endif
+
+#if LL_LINUX
+pid_t getParentPid( pid_t aPid )
+{
+ std::stringstream strm;
+ strm << "/proc/" << aPid << "/status";
+ std::ifstream in{ strm.str() };
+
+ if( !in.is_open() )
+ return 0;
+
+ pid_t res {0};
+ while( !in.eof() && res == 0 )
+ {
+ std::string line;
+ line.resize( 1024, 0 );
+ in.getline( &line[0], line.length() );
+
+ auto i = line.find( "PPid:" );
+
+ if( i == std::string::npos )
+ continue;
+
+ char const *pIn = line.c_str() + 5; // Skip over pid;
+ while( *pIn != 0 && isspace( *pIn ) )
+ ++pIn;
+
+ if( *pIn )
+ res = atoll( pIn );
+ }
+ return res;
+}
+
+bool isPluginPid( pid_t aPid )
+{
+ auto myPid = getpid();
+
+ do
+ {
+ if( aPid == myPid )
+ return true;
+ aPid = getParentPid( aPid );
+ } while( aPid > 1 );
+
+ return false;
+}
+#endif