00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 const char *XrdSysPluginCVSID = "$Id: XrdSysPlugin.cc 38011 2011-02-08 18:35:57Z ganis $";
00014
00015
00016
00017 #ifdef __solaris__
00018 #include <sys/isa_defs.h>
00019 #if defined(_ILP32) && (_FILE_OFFSET_BITS != 32)
00020 #undef _FILE_OFFSET_BITS
00021 #define _FILE_OFFSET_BITS 32
00022 #undef _LARGEFILE_SOURCE
00023 #endif
00024 #endif
00025
00026 #ifndef WIN32
00027 #include <dlfcn.h>
00028 #if !defined(__macos__) && !defined(__CYGWIN__)
00029 #include <link.h>
00030 #endif
00031 #include <stdio.h>
00032 #include <strings.h>
00033 #include <sys/types.h>
00034 #include <errno.h>
00035 #else
00036 #include "XrdSys/XrdWin32.hh"
00037 #endif
00038
00039 #include "XrdSys/XrdSysError.hh"
00040 #include "XrdSys/XrdSysHeaders.hh"
00041 #include "XrdSys/XrdSysPlugin.hh"
00042
00043
00044
00045
00046
00047 XrdSysPlugin::~XrdSysPlugin()
00048 {
00049 if (libHandle) dlclose(libHandle);
00050 }
00051
00052
00053
00054
00055
00056
00057 void *XrdSysPlugin::getPlugin(const char *pname, int errok)
00058 {
00059 return getPlugin(pname, errok, false);
00060 }
00061
00062 void *XrdSysPlugin::getPlugin(const char *pname, int errok, bool global)
00063 {
00064 void *ep;
00065
00066
00067
00068 int flags = RTLD_NOW;
00069 #ifndef WIN32
00070 flags |= global ? RTLD_GLOBAL : RTLD_LOCAL;
00071 #else
00072 if (global)
00073 eDest->Emsg("getPlugin",
00074 "request for global symbols unsupported under Windows - ignored");
00075 #endif
00076 if (!libHandle && !(libHandle = dlopen(libPath, flags)))
00077 {eDest->Emsg("getPlugin", "Unable to open", libPath, dlerror());
00078 return 0;
00079 }
00080
00081
00082
00083 if (!(ep = dlsym(libHandle, pname)) && !errok)
00084 {char buff[1024];
00085 sprintf(buff, "Unable to find %s in", pname);
00086 eDest->Emsg("getPlugin", buff, libPath, dlerror());
00087 return 0;
00088 }
00089
00090
00091
00092 return ep;
00093 }