From: Mark H Weaver <mhw@netris.org>
To: Guile Development <guile-devel@gnu.org>
Cc: Bruce Korb <bruce.korb@gmail.com>
Subject: [PATCH] Fix library search order and don't change LD_LIBRARY_PATH
Date: Tue, 27 Nov 2012 17:54:21 -0500 [thread overview]
Message-ID: <87sj7uy7vm.fsf_-_@tines.lan> (raw)
In-Reply-To: <87y5jnn8y4.fsf_-_@tines.lan> (Mark H. Weaver's message of "Wed, 03 Oct 2012 06:31:15 -0400")
[-- Attachment #1: Type: text/plain, Size: 321 bytes --]
Hello all,
Apologies for the delay in resolving this issue with LD_LIBRARY_PATH,
but we *do* plan to get this fix in 2.0.7. After discussion with
Ludovic on IRC, I believe we've reached agreement.
I've attached a revised patch that incorporates Ludovic's suggestions.
Comments and suggestions solicited.
Mark
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: [PATCH] Fix library search order and don't change LD_LIBRARY_PATH --]
[-- Type: text/x-diff, Size: 6906 bytes --]
From 83167214083e24a8eeac6b6e04e8035497fff73a Mon Sep 17 00:00:00 2001
From: Mark H Weaver <mhw@netris.org>
Date: Tue, 27 Nov 2012 17:44:38 -0500
Subject: [PATCH] Fix library search order and don't change LD_LIBRARY_PATH
* libguile/dynl.c (system_extensions_path): New static variable.
(sysdep_dynl_link): If 'lt_dlopenext' fails, manually search
in 'system_extensions_path'.
(augment_env): Remove.
(sysdep_dynl_init): Don't change LD_LIBRARY_PATH, and don't use
lt_dladdsearchdir if GUILE_SYSTEM_EXTENSIONS_PATH is set. Instead,
initialize 'system_extensions_path' from GUILE_SYSTEM_EXTENSIONS_PATH
(or if it's unset: <SCM_LIB_DIR>:<SCM_EXTENSIONS_DIR>), and rely on
sysdep_dynl_link to search those directories manually.
---
libguile/dynl.c | 133 ++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 88 insertions(+), 45 deletions(-)
diff --git a/libguile/dynl.c b/libguile/dynl.c
index a2ae6e2..2948f78 100644
--- a/libguile/dynl.c
+++ b/libguile/dynl.c
@@ -26,6 +26,7 @@
#endif
#include <alloca.h>
+#include <string.h>
/* "dynl.c" dynamically link&load object files.
Author: Aubrey Jaffer
@@ -61,6 +62,7 @@ maybe_drag_in_eprintf ()
#include "libguile/validate.h"
#include "libguile/dynwind.h"
#include "libguile/foreign.h"
+#include "libguile/gc.h"
#include <ltdl.h>
@@ -75,18 +77,77 @@ maybe_drag_in_eprintf ()
*/
/* njrev: not threadsafe, protection needed as described above */
+
+static char *system_extensions_path; /* library search path of last resort */
+
static void *
sysdep_dynl_link (const char *fname, const char *subr)
{
lt_dlhandle handle;
- if (fname != NULL)
- handle = lt_dlopenext (fname);
- else
+ if (fname == NULL)
/* Return a handle for the program as a whole. */
handle = lt_dlopen (NULL);
+ else
+ {
+ handle = lt_dlopenext (fname);
- if (NULL == handle)
+ if (handle == NULL
+#ifdef LT_DIRSEP_CHAR
+ && strchr (fname, LT_DIRSEP_CHAR) == NULL
+#endif
+ && strchr (fname, '/') == NULL)
+ {
+ /* FNAME contains no directory separators and was not in the
+ usual library search paths, so now we search for it in
+ SYSTEM_EXTENSIONS_PATH. */
+ char *fname_attempt
+ = scm_gc_malloc_pointerless (strlen (system_extensions_path)
+ + strlen (fname) + 2,
+ "dynl fname_attempt");
+ char *path; /* remaining path to search */
+ char *end; /* end of current path component */
+ char *s;
+
+ /* Iterate over the components of SYSTEM_EXTENSIONS_PATH */
+ for (path = system_extensions_path;
+ *path != '\0';
+ path = (*end == '\0') ? end : (end + 1))
+ {
+ /* Find end of path component */
+ end = strchr (path, LT_PATHSEP_CHAR);
+ if (end == NULL)
+ end = strchr (path, '\0');
+
+ /* Skip empty path components */
+ if (path == end)
+ continue;
+
+ /* Construct FNAME_ATTEMPT, starting with path component */
+ s = fname_attempt;
+ memcpy (s, path, end - path);
+ s += end - path;
+
+ /* Append directory separator, but avoid duplicates */
+ if (s[-1] != '/'
+#ifdef LT_DIRSEP_CHAR
+ && s[-1] != LT_DIRSEP_CHAR
+#endif
+ )
+ *s++ = '/';
+
+ /* Finally, append FNAME (including null terminator) */
+ strcpy (s, fname);
+
+ /* Try to load it, and terminate the search if successful */
+ handle = lt_dlopenext (fname_attempt);
+ if (handle != NULL)
+ break;
+ }
+ }
+ }
+
+ if (handle == NULL)
{
SCM fn;
SCM msg;
@@ -120,30 +181,6 @@ sysdep_dynl_value (const char *symb, void *handle, const char *subr)
return fptr;
}
-/* Augment environment variable VARIABLE with VALUE, assuming VARIABLE
- is a path kind of variable. */
-static void
-augment_env (const char *variable, const char *value)
-{
- const char *env;
-
- env = getenv (variable);
- if (env != NULL)
- {
- char *new_value;
- static const char path_sep[] = { LT_PATHSEP_CHAR, 0 };
-
- new_value = alloca (strlen (env) + strlen (value) + 2);
- strcpy (new_value, env);
- strcat (new_value, path_sep);
- strcat (new_value, value);
-
- setenv (variable, new_value, 1);
- }
- else
- setenv (variable, value, 1);
-}
-
static void
sysdep_dynl_init ()
{
@@ -151,26 +188,32 @@ sysdep_dynl_init ()
lt_dlinit ();
+ /* Initialize 'system_extensions_path' from
+ $GUILE_SYSTEM_EXTENSIONS_PATH, or if that's not set:
+ <SCM_LIB_DIR> <LT_PATHSEP_CHAR> <SCM_EXTENSIONS_DIR>.
+
+ 'lt_dladdsearchdir' can't be used because it is searched before
+ the system-dependent search path, which is the one 'libtool
+ --mode=execute -dlopen' fiddles with (info "(libtool) Libltdl
+ Interface"). See
+ <http://lists.gnu.org/archive/html/guile-devel/2010-11/msg00095.html>.
+
+ The environment variables $LTDL_LIBRARY_PATH and $LD_LIBRARY_PATH
+ can't be used because they would be propagated to subprocesses
+ which may cause problems for other programs. See
+ <http://lists.gnu.org/archive/html/guile-devel/2012-09/msg00037.html> */
+
env = getenv ("GUILE_SYSTEM_EXTENSIONS_PATH");
- if (env && strcmp (env, "") == 0)
- /* special-case interpret system-ltdl-path=="" as meaning no system path,
- which is the case during the build */
- ;
- else if (env)
- /* FIXME: should this be a colon-separated path? Or is the only point to
- allow the build system to turn off the installed extensions path? */
- lt_dladdsearchdir (env);
+ if (env)
+ system_extensions_path = env;
else
{
- /* Add SCM_LIB_DIR and SCM_EXTENSIONS_DIR to the loader's search
- path. `lt_dladdsearchdir' and $LTDL_LIBRARY_PATH can't be used
- for that because they are searched before the system-dependent
- search path, which is the one `libtool --mode=execute -dlopen'
- fiddles with (info "(libtool) Libltdl Interface"). See
- <http://lists.gnu.org/archive/html/guile-devel/2010-11/msg00095.html>
- for details. */
- augment_env (SHARED_LIBRARY_PATH_VARIABLE, SCM_LIB_DIR);
- augment_env (SHARED_LIBRARY_PATH_VARIABLE, SCM_EXTENSIONS_DIR);
+ system_extensions_path
+ = scm_gc_malloc_pointerless (strlen (SCM_LIB_DIR)
+ + strlen (SCM_EXTENSIONS_DIR) + 2,
+ "system_extensions_path");
+ sprintf (system_extensions_path, "%s%c%s",
+ SCM_LIB_DIR, LT_PATHSEP_CHAR, SCM_EXTENSIONS_DIR);
}
}
--
1.7.10.4
next prev parent reply other threads:[~2012-11-27 22:54 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-21 23:36 [PATCH] do not augment environment Bruce Korb
2012-10-01 1:13 ` Bruce Korb
2012-10-01 2:38 ` Mark H Weaver
2012-10-01 14:24 ` Bruce Korb
2012-10-01 14:39 ` Bruce Korb
2012-10-01 16:59 ` Mark H Weaver
2012-10-01 18:27 ` Bruce Korb
2012-10-03 10:31 ` [PATCH] Don't augment LD_LIBRARY_PATH (was Re: [PATCH] do not augment environment) Mark H Weaver
2012-10-04 20:37 ` Ludovic Courtès
2012-10-06 2:30 ` Mark H Weaver
2012-10-06 12:36 ` Mark H Weaver
2012-10-07 21:16 ` Ludovic Courtès
2012-10-06 12:42 ` Ludovic Courtès
2012-10-06 14:31 ` Mark H Weaver
2012-10-05 9:43 ` Sjoerd van Leent Privé
2012-10-05 21:58 ` Mark H Weaver
2012-11-27 22:54 ` Mark H Weaver [this message]
2012-11-27 22:59 ` [PATCH] Fix library search order and don't change LD_LIBRARY_PATH Ludovic Courtès
2012-11-27 23:23 ` Mark H Weaver
2012-11-27 23:01 ` Bruce Korb
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87sj7uy7vm.fsf_-_@tines.lan \
--to=mhw@netris.org \
--cc=bruce.korb@gmail.com \
--cc=guile-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).