aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog.txt1
-rw-r--r--pseudo_util.c36
2 files changed, 22 insertions, 15 deletions
diff --git a/ChangeLog.txt b/ChangeLog.txt
index eb67560..e93ea9e 100644
--- a/ChangeLog.txt
+++ b/ChangeLog.txt
@@ -1,5 +1,6 @@
2010-08-26:
* (seebs) make offsets.c slightly less useless
+ * (seebs) don't overwrite LD_LIBRARY_PATH values that include us
2010-08-25:
* (seebs) fix the signal mask restore
diff --git a/pseudo_util.c b/pseudo_util.c
index b8bd85b..6d66bd5 100644
--- a/pseudo_util.c
+++ b/pseudo_util.c
@@ -675,24 +675,27 @@ pseudo_setupenv() {
setenv("LD_PRELOAD", libpseudo_name, 1);
}
- const char * ld_library_path = getenv("LD_LIBRARY_PATH");
+ const char *ld_library_path = getenv("LD_LIBRARY_PATH");
char * libdir_path = pseudo_libdir_path(NULL);
- if (ld_library_path && !strstr(ld_library_path, libdir_path)) {
- size_t len = strlen(ld_library_path) + 1 + strlen(libdir_path) + 1 + (strlen(libdir_path) + 2) + 1;
+ if (!ld_library_path) {
+ size_t len = strlen(libdir_path) + 1 + (strlen(libdir_path) + 2) + 1;
char *newenv = malloc(len);
if (!newenv) {
pseudo_diag("fatal: can't allocate new LD_LIBRARY_PATH variable.\n");
}
- snprintf(newenv, len, "%s:%s:%s64", ld_library_path, libdir_path, libdir_path);
+ snprintf(newenv, len, "%s:%s64", libdir_path, libdir_path);
setenv("LD_LIBRARY_PATH", newenv, 1);
- } else {
- size_t len = strlen(libdir_path) + 1 + (strlen(libdir_path) + 2) + 1;
+ } else if (!strstr(ld_library_path, libdir_path)) {
+ size_t len = strlen(ld_library_path) + 1 + strlen(libdir_path) + 1 + (strlen(libdir_path) + 2) + 1;
char *newenv = malloc(len);
if (!newenv) {
pseudo_diag("fatal: can't allocate new LD_LIBRARY_PATH variable.\n");
}
- snprintf(newenv, len, "%s:%s64", libdir_path, libdir_path);
+ snprintf(newenv, len, "%s:%s:%s64", ld_library_path, libdir_path, libdir_path);
setenv("LD_LIBRARY_PATH", newenv, 1);
+ } else {
+ /* nothing to do, ld_library_path exists and contains
+ * our preferred path */
}
free(libdir_path);
}
@@ -711,7 +714,7 @@ pseudo_setupenvp(char * const *envp) {
size_t size_pseudoenv = 0;
- char * ld_preload=NULL, * ld_library_path=NULL;
+ char *ld_preload = NULL, *ld_library_path = NULL;
pseudo_debug(2, "setting up envp environment.\n");
@@ -757,23 +760,26 @@ pseudo_setupenvp(char * const *envp) {
new_envp[j++] = newenv;
}
- char * libdir_path = pseudo_libdir_path(NULL);
- if (ld_library_path && !strstr(ld_library_path, libdir_path)) {
- size_t len = strlen(ld_library_path) + 1 + strlen(libdir_path) + 1 + (strlen(libdir_path) + 2) + 1;
+ char *libdir_path = pseudo_libdir_path(NULL);
+ if (!ld_library_path) {
+ size_t len = strlen("LD_LIBRARY_PATH=") + strlen(libdir_path) + 1 + (strlen(libdir_path) + 2) + 1;
char *newenv = malloc(len);
if (!newenv) {
pseudo_diag("fatal: can't allocate new LD_LIBRARY_PATH variable.\n");
}
- snprintf(newenv, len, "%s:%s:%s64", ld_library_path, libdir_path, libdir_path);
+ snprintf(newenv, len, "LD_LIBRARY_PATH=%s:%s64", libdir_path, libdir_path);
new_envp[j++] = newenv;
- } else {
- size_t len = strlen("LD_LIBRARY_PATH=") + strlen(libdir_path) + 1 + (strlen(libdir_path) + 2) + 1;
+ } else if (!strstr(ld_library_path, libdir_path)) {
+ size_t len = strlen(ld_library_path) + 1 + strlen(libdir_path) + 1 + (strlen(libdir_path) + 2) + 1;
char *newenv = malloc(len);
if (!newenv) {
pseudo_diag("fatal: can't allocate new LD_LIBRARY_PATH variable.\n");
}
- snprintf(newenv, len, "LD_LIBRARY_PATH=%s:%s64", libdir_path, libdir_path);
+ snprintf(newenv, len, "%s:%s:%s64", ld_library_path, libdir_path, libdir_path);
new_envp[j++] = newenv;
+ } else {
+ /* keep old value */
+ new_envp[j++] = ld_library_path;
}
free(libdir_path);