I want to get the path of the shared library from inside the function
in the shared library. We can get the path of the executable by using
dlinfo on solaris, /proc/self/exe on linux, GetModuleFileName() on
windows etc. But I could not get the shared library path from the
function inside that shared library itself. Can anyone please tell me
how to achieve this?
Following is what is my requirement.
I have a static utility library which gets linked with all the
components. The components are servers, tools and some are webplugins
(plugins to webserver). I want to have a function "char*
getComponentFullPath()" in my utility library which will return the
full path of the component. If the component is server or tools, the
function should return the full path of the server or tool executable
file. If the component is webserver plugin (as a shared library xxx.so
), then the function call should return the full path of the shared
library from where it was loaded.
For servers and tools, this can be achieved by using dlinfo on solaris
etc. as I mentioned above. But the problem is with the webplugins which
are the shared libraries (.so files) loaded by the webserver. The above
mentioned approach of dlinfo or /proc/self/exe returns the path of the
webserver but not the shared library path.
How to get the shared library path from getComponentFullPath().
Thanks,
Sharad.
Sharad Chavali wrote:
[snip]
> I want to have a function "char*
> getComponentFullPath()" in my utility library which will return the
> full path of the component.
[snip]
One question: Why do you want to retrieve the "full path of the component"?
- --
Lew Pitcher
IT Specialist, Enterprise Data Systems,
Enterprise Technology Solutions, TD Bank Financial Group
(Opinions expressed are my own, not my employers')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)
iD8DBQFDV99QagVFX4UWr64RAqwKAKDgwTzUBaE5LA5bNHFygWwX+lqFXQCfW3Qe
3Yoq1/6hJMg8Alx5LdwMBeg=
=rvy4
-----END PGP SIGNATURE-----
> I want to get the path of the shared library from inside the function
> in the shared library. We can get the path of the executable by using
> dlinfo on solaris, /proc/self/exe on linux, GetModuleFileName() on
> windows etc. But I could not get the shared library path from the
> function inside that shared library itself. Can anyone please tell me
> how to achieve this?
On GNU/Linux (this is a GNU-ism) you could use the dladdr
function. See the appropriate man page, and #define GNU_SOURCE before
#include-ing <dlfcn.h>; also look into /usr/include/dlfcn.h and read
the comments there
Alternatively, you might parse the /proc/self/maps file.
However, I don't see any reason to do what you want. Maybe the
RTLD_GLOBAL flag to dlopen might help you.
Also, be aware that there are some corner pathological cases where
what you try to achieve don't make sense (consider for example that a
shared library is removed or replaced while your process is running,
or that your process calls -possibly thru a runtime loaded plugin- the
chroot system call).
I'm suprised you don't describe your real application need; what you
describe is some half-baked pseudo-solution (to some unstated problem)
you are trying to implement; you'll better also describe your real
needs or motivations.
--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basile(at)starynkevitch(dot)net
8, rue de la Faïencerie, 92340 Bourg La Reine, France