From 3b5c29f539d529ab7433f64280f46f11c9475cf4 Mon Sep 17 00:00:00 2001 From: Bertho Stultiens Date: Thu, 22 Apr 1999 09:13:38 +0000 Subject: [PATCH] Change wine's dlopen search-patch strategy not using the environment and added #if:s to seperate the code out if libdl isn't availble. --- include/elfdll.h | 6 ++++++ loader/elfdll.c | 35 +++++++++++++++++------------------ loader/loadorder.c | 21 +++++++-------------- 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/include/elfdll.h b/include/elfdll.h index 0c389e36b6a..a8c5c1040b9 100644 --- a/include/elfdll.h +++ b/include/elfdll.h @@ -4,6 +4,12 @@ WINE_MODREF *ELFDLL_LoadLibraryExA(LPCSTR libname, DWORD flags, DWORD *err); HINSTANCE16 ELFDLL_LoadModule16(LPCSTR libname, BOOL implicit); void ELFDLL_UnloadLibrary(WINE_MODREF *wm); + +#if defined(HAVE_LIBDL) && defined(HAVE_DLFCN_H) + void *ELFDLL_dlopen(const char *libname, int flags); +extern char *extra_ld_library_path; + +#endif #endif diff --git a/loader/elfdll.c b/loader/elfdll.c index 127d78c498e..39b4ed17fd9 100644 --- a/loader/elfdll.c +++ b/loader/elfdll.c @@ -21,19 +21,16 @@ #include "winerror.h" DECLARE_DEBUG_CHANNEL(elfdll) -DECLARE_DEBUG_CHANNEL(win32) #if defined(HAVE_LIBDL) && defined(HAVE_DLFCN_H) #include /*------------------ HACKS -----------------*/ -#ifndef elfdll -#define elfdll win32 -#endif - extern DWORD fixup_imports(WINE_MODREF *wm); /*---------------- END HACKS ---------------*/ +char *extra_ld_library_path = NULL; /* The extra search-path set in wine.conf */ + struct elfdll_image { HMODULE pe_module_start; @@ -46,28 +43,30 @@ struct elfdll_image /**************************************************************************** * ELFDLL_dlopen * - * Wrapper for dlopen to search the LD_LIBRARY_PATH manually because - * libdl.so caches the environment and does not accept our changes. + * Wrapper for dlopen to search the EXTRA_LD_LIBRARY_PATH from wine.conf + * manually because libdl.so caches the environment and does not accept our + * changes. */ void *ELFDLL_dlopen(const char *libname, int flags) { - char *ldpath = getenv("LD_LIBRARY_PATH"); char buffer[256]; int namelen; + void *handle; + char *ldpath; - if(!ldpath) - { - WARN(elfdll, "No LD_LIBRARY_PATH set\n"); - return dlopen(libname, flags); - } + /* First try the default path search of dlopen() */ + handle = dlopen(libname, flags); + if(handle) + return handle; + /* Now try to construct searches through our extra search-path */ namelen = strlen(libname); - while(ldpath) + ldpath = extra_ld_library_path; + while(ldpath && *ldpath) { int len; char *cptr; char *from; - void *handle; from = ldpath; cptr = strchr(ldpath, ':'); @@ -84,7 +83,7 @@ void *ELFDLL_dlopen(const char *libname, int flags) if(len + namelen + 1 >= sizeof(buffer)) { - ERR(elfdll, "Buffer overflow! Check LD_LIBRARY_PATH or increase buffer size.\n"); + ERR(elfdll, "Buffer overflow! Check EXTRA_LD_LIBRARY_PATH or increase buffer size.\n"); return NULL; } @@ -207,7 +206,7 @@ static WINE_MODREF *ELFDLL_CreateModref(HMODULE hModule, LPCSTR path) if(!(nt->FileHeader.Characteristics & IMAGE_FILE_DLL)) { if(PROCESS_Current()->exe_modref) - FIXME(win32, "overwriting old exe_modref... arrgh\n"); + FIXME(elfdll, "overwriting old exe_modref... arrgh\n"); PROCESS_Current()->exe_modref = wm; } @@ -227,7 +226,7 @@ static WINE_MODREF *ELFDLL_CreateModref(HMODULE hModule, LPCSTR path) } } if(wm == PROCESS_Current()->exe_modref) - ERR(win32, "Have to delete current exe_modref. Expect crash now\n"); + ERR(elfdll, "Have to delete current exe_modref. Expect crash now\n"); HeapFree(procheap, 0, wm->shortname); HeapFree(procheap, 0, wm->longname); HeapFree(procheap, 0, wm->modname); diff --git a/loader/loadorder.c b/loader/loadorder.c index 797a6a25580..6c8cbb155bf 100644 --- a/loader/loadorder.c +++ b/loader/loadorder.c @@ -8,12 +8,15 @@ #include #include +#include "config.h" #include "windef.h" #include "options.h" #include "debug.h" #include "loadorder.h" #include "heap.h" #include "options.h" +#include "module.h" +#include "elfdll.h" DEFAULT_DEBUG_CHANNEL(module) @@ -330,26 +333,16 @@ BOOL MODULE_InitLoadOrder(void) char buffer[BUFFERSIZE]; int nbuffer; +#if defined(HAVE_LIBDL) && defined(HAVE_DLFCN_H) /* Get/set the new LD_LIBRARY_PATH */ nbuffer = PROFILE_GetWineIniString("DllDefaults", "EXTRA_LD_LIBRARY_PATH", "", buffer, sizeof(buffer)); if(nbuffer) { - char *ld_lib_path = getenv("LD_LIBRARY_PATH"); - if(ld_lib_path) - { - /* - * Append new path to current - */ - char *tmp = HEAP_strdupA(SystemHeap, 0, buffer); - sprintf(buffer, "LD_LIBRARY_PATH=%s:%s", ld_lib_path, tmp); - HeapFree( SystemHeap, 0, tmp ); - } - - TRACE(module, "Setting new LD_LIBRARY_PATH=%s\n", buffer); - - putenv(buffer); + extra_ld_library_path = HEAP_strdupA(SystemHeap, 0, buffer); + TRACE(module, "Setting extra LD_LIBRARY_PATH=%s\n", buffer); } +#endif /* Get the default load order */ nbuffer = PROFILE_GetWineIniString("DllDefaults", "DefaultLoadOrder", "n,e,s,b", buffer, sizeof(buffer)); -- 2.11.4.GIT