From 94bb5bb1a7f56220a579bd5a72a736cf7576efc9 Mon Sep 17 00:00:00 2001 From: Bertho Stultiens Date: Mon, 19 Apr 1999 16:44:22 +0000 Subject: [PATCH] Removed non-portable hacks and replaced them with more general versions. --- include/elfdll.h | 1 + loader/elf.c | 3 +- loader/elfdll.c | 72 ++++++++++++++++++++++++++++++++++++++++++---- loader/loadorder.c | 16 ++--------- 4 files changed, 73 insertions(+), 19 deletions(-) diff --git a/include/elfdll.h b/include/elfdll.h index 134b1118f43..0c389e36b6a 100644 --- a/include/elfdll.h +++ b/include/elfdll.h @@ -4,5 +4,6 @@ WINE_MODREF *ELFDLL_LoadLibraryExA(LPCSTR libname, DWORD flags, DWORD *err); HINSTANCE16 ELFDLL_LoadModule16(LPCSTR libname, BOOL implicit); void ELFDLL_UnloadLibrary(WINE_MODREF *wm); +void *ELFDLL_dlopen(const char *libname, int flags); #endif diff --git a/loader/elf.c b/loader/elf.c index 50dfae681e1..bed827d84fe 100644 --- a/loader/elf.c +++ b/loader/elf.c @@ -25,6 +25,7 @@ #include "pe_image.h" #include "debug.h" #include "winerror.h" +#include "elfdll.h" DEFAULT_DEBUG_CHANNEL(win32) @@ -138,7 +139,7 @@ WINE_MODREF *ELF_LoadLibraryExA( LPCSTR libname, DWORD flags, DWORD *err) /* FIXME: make UNIX filename from DOS fn? */ /* ... and open it */ - dlhandle = dlopen(t,RTLD_NOW); + dlhandle = ELFDLL_dlopen(t,RTLD_NOW); if (!dlhandle) { HeapFree( GetProcessHeap(), 0, t ); *err = ERROR_FILE_NOT_FOUND; diff --git a/loader/elfdll.c b/loader/elfdll.c index 7d45fc35544..127d78c498e 100644 --- a/loader/elfdll.c +++ b/loader/elfdll.c @@ -6,6 +6,7 @@ #include #include +#include #include "config.h" #include "windef.h" @@ -42,6 +43,70 @@ 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. + */ +void *ELFDLL_dlopen(const char *libname, int flags) +{ + char *ldpath = getenv("LD_LIBRARY_PATH"); + char buffer[256]; + int namelen; + + if(!ldpath) + { + WARN(elfdll, "No LD_LIBRARY_PATH set\n"); + return dlopen(libname, flags); + } + + namelen = strlen(libname); + while(ldpath) + { + int len; + char *cptr; + char *from; + void *handle; + + from = ldpath; + cptr = strchr(ldpath, ':'); + if(!cptr) + { + len = strlen(ldpath); + ldpath = NULL; + } + else + { + len = cptr - ldpath; + ldpath = cptr + 1; + } + + if(len + namelen + 1 >= sizeof(buffer)) + { + ERR(elfdll, "Buffer overflow! Check LD_LIBRARY_PATH or increase buffer size.\n"); + return NULL; + } + + strncpy(buffer, from, len); + if(len) + { + buffer[len] = '/'; + strcpy(buffer + len + 1, libname); + } + else + strcpy(buffer + len, libname); + + TRACE(elfdll, "Trying dlopen('%s', %d)\n", buffer, flags); + + handle = dlopen(buffer, flags); + if(handle) + return handle; + } + return NULL; +} + + /**************************************************************************** * get_sobasename (internal) * @@ -221,11 +286,8 @@ WINE_MODREF *ELFDLL_LoadLibraryExA(LPCSTR path, DWORD flags, DWORD *err) strcpy(soname, name); strcat(soname, ".so"); - /* Try to open the elf-dll. - * The dlopen will search the correct path and our extended - * LD_LIBRARY as well. - */ - dlhandle = dlopen(soname, RTLD_LAZY); + /* Try to open the elf-dll */ + dlhandle = ELFDLL_dlopen(soname, RTLD_LAZY); if(!dlhandle) { WARN(elfdll, "Could not load %s (%s)\n", soname, dlerror()); diff --git a/loader/loadorder.c b/loader/loadorder.c index 365befc69e3..797a6a25580 100644 --- a/loader/loadorder.c +++ b/loader/loadorder.c @@ -50,7 +50,7 @@ static char *get_tok(const char *str, const char *delim) static char *buf = NULL; char *cptr; - if(!str && (!buf || !index)) + if(!str && !buf) return NULL; if(str && buf) @@ -335,7 +335,6 @@ BOOL MODULE_InitLoadOrder(void) if(nbuffer) { - extern char *_dl_library_path; char *ld_lib_path = getenv("LD_LIBRARY_PATH"); if(ld_lib_path) { @@ -343,22 +342,13 @@ BOOL MODULE_InitLoadOrder(void) * Append new path to current */ char *tmp = HEAP_strdupA(SystemHeap, 0, buffer); - sprintf(buffer, "%s:%s", ld_lib_path, tmp); + 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); - setenv("LD_LIBRARY_PATH", buffer, 1); - - /* - * This is a cruel hack required to have libdl check this path. - * The problem is that libdl caches the environment variable - * and we won't get our modifications applied. We ensure the - * the correct search path by explicitely modifying the libdl - * internal variable which holds the path. - */ - _dl_library_path = HEAP_strdupA(SystemHeap, 0, buffer); + putenv(buffer); } /* Get the default load order */