aboutsummaryrefslogtreecommitdiffstats
path: root/pseudo_util.c
diff options
context:
space:
mode:
authorseebs <seebs@seebs-eee.(none)>2010-08-26 15:45:34 -0500
committerseebs <seebs@seebs-eee.(none)>2010-08-26 15:58:01 -0500
commit6f8b09a6df61a547aa58d0748c0d1aba135d9b73 (patch)
treeb69deeb886d7eeae6dfbf4f47edf382f2218dab6 /pseudo_util.c
parent281971d456c72865db87599343ca2e50cb6a6b2c (diff)
downloadpseudo-6f8b09a6df61a547aa58d0748c0d1aba135d9b73.tar.gz
pseudo-6f8b09a6df61a547aa58d0748c0d1aba135d9b73.tar.bz2
pseudo-6f8b09a6df61a547aa58d0748c0d1aba135d9b73.zip
The logic for updating LD_LIBRARY_PATH had a bug; if you had
an LD_LIBRARY_PATH that included the pseudo library directory and some other directories, the other directories would get wiped out. Also a couple of whitespace rationalizatoins.
Diffstat (limited to 'pseudo_util.c')
-rw-r--r--pseudo_util.c36
1 files changed, 21 insertions, 15 deletions
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);