4.The embedded path of the calling module (executable program or shared library) for libraries names in calls to dlopen ,dlopene, or dlgetfileinfo. For dependent libraries, the embedded path of the library that named it as a dependent is used.

5.The standard library path.

6.The current working directory. (This is only for libraries named in calls to dlopen, dlopene, and dlgetfileinfo, not their dependent libraries.)

See dld.so(5) for additional information on search paths and options that can change the order described above.

Any combination of these paths may be disabled by setting flags to one or more of the following values alternated together:

RTLD_FLAG_DISABLE_DYNAMIC_PATH - If this flag is set, the dynamic loader does not search the directories specified in the dynamic search path.

RTLD_FLAG_DISABLE_LD_LIBRARY_PATH - If this flag is set, the dynamic loader does not search the directories specified in the LD_LIBRARY_PATH environment variable.

RTLD_FLAG_DISABLE_SHLIB_PATH- If this flag is set, the dynamic loader does not search the directories specified in the SHLIB_PATH environment variable.

RTLD_FLAG_DISABLE_EMBEDDED_PATH - If this flag is set, the dynamic loader does not search the directories specified in the embedded path.

RTLD_FLAG_DISABLE_STD_PATH - If this flag is set, the dynamic loader does not search the standard library directory.

RTLD_FLAG_DISABLE_CWD_PATH - If this flag is set, the dynamic loader does not search the current.

Mulitple search paths can be disabled by alternating individual flags: flags =

RTLD_FLAG_DISABLE_STD_PATH RTLD_FLAG_DISABLE_CWD_PATH

A single search path can be enabled by setting flags to the complement of the flag value that disables that search path: flags = ~RTLD_FLAG_DISABLE_DYNAMIC_PATH

Using dlsetlibpath to set the dynamic search path

The following example illustrates the use of dlsetlibpath to set the dynamic search path and disable other search paths. For simplicity, error checking has been omitted.

#include <dlfcn.h>

int main() { void *handle; int status; int flags;

/* Set dynamic search path and disable the embedded

*path and the standard library directory.

*/

flags = RTLD_FLAG_DISABLE_EMBEDDED_PATH

RTLD_FLAG_DISABLE_STD_PATH;

status = dlsetlibpath("/opt/lib:/opt/usr/lib", flags); /* Call dlopen to load a library using the dynamic

*search path.

*/

handle = dlopen("mylib.so"), RTLD_LAZY);

/* Remove the dynamic search path and reenable all

*disabled search paths.

*/

status = dlsetlibpath(NULL, 0);

}

154 Shared Library Management Routines