aboutsummaryrefslogtreecommitdiffstats
path: root/pseudo_util.c
diff options
context:
space:
mode:
authorMark Hatle <mark.hatle@windriver.com>2010-08-06 17:31:25 -0500
committerseebs <seebs@seebs-eee.(none)>2010-08-06 17:39:47 -0500
commitbd87eec4538921535f6a8e88044996f092643a2b (patch)
tree7a0d11e9a5cd5590e3b7539da8efc86c08a0208b /pseudo_util.c
parent551bf567c171c9f6f475f02de80e35df9563dce7 (diff)
downloadpseudo-bd87eec4538921535f6a8e88044996f092643a2b.tar.gz
pseudo-bd87eec4538921535f6a8e88044996f092643a2b.tar.bz2
pseudo-bd87eec4538921535f6a8e88044996f092643a2b.zip
Fix an exec program with an empty environment
If the environment has been cleared (in an execve for instance), we need to seed the environment with the PSEUDO_PREFIX, PSEUDO_BINDIR, PSEUDO_LIBDIR, and PSEUDO_LOCALSTATEDIR values.
Diffstat (limited to 'pseudo_util.c')
-rw-r--r--pseudo_util.c55
1 files changed, 54 insertions, 1 deletions
diff --git a/pseudo_util.c b/pseudo_util.c
index 0408a56..ee6e50d 100644
--- a/pseudo_util.c
+++ b/pseudo_util.c
@@ -488,6 +488,7 @@ pseudo_setupenv(char * const *environ, char *opts) {
char **new_environ;
int env_count = 0;
int found_preload = 0, found_libpath = 0, found_debug = 0, found_opts = 0;
+ int found_prefix = 0, found_bindir = 0, found_libdir = 0, found_localstatedir = 0;
int i, j;
size_t len;
char *newenv;
@@ -501,9 +502,17 @@ pseudo_setupenv(char * const *environ, char *opts) {
found_debug = 1;
if (!memcmp(environ[i], "LD_LIBRARY_PATH=", 16))
found_libpath = 1;
+ if (!memcmp(environ[i], "PSEUDO_PREFIX=", 14))
+ found_prefix = 1;
+ if (!memcmp(environ[i], "PSEUDO_BINDIR=", 14))
+ found_bindir = 1;
+ if (!memcmp(environ[i], "PSEUDO_LIBDIR=", 14))
+ found_libdir = 1;
+ if (!memcmp(environ[i], "PSEUDO_LOCALSTATEDIR=", 21))
+ found_localstatedir = 1;
++env_count;
}
- env_count += 4 - (found_preload + found_libpath + found_debug + found_opts);
+ env_count += 4 - (found_preload + found_libpath + found_debug + found_opts + found_prefix + found_bindir + found_libdir + found_localstatedir);
new_environ = malloc((env_count + 1) * sizeof(*new_environ));
if (!new_environ) {
@@ -571,6 +580,50 @@ pseudo_setupenv(char * const *environ, char *opts) {
snprintf(newenv, len, "PSEUDO_OPTS=%s", opts);
new_environ[j++] = newenv;
}
+ if (!found_prefix) {
+ char * prefix_path = pseudo_prefix_path(NULL);
+ len = 14 + strlen(prefix_path) + 1;
+ newenv = malloc(len);
+ if (!newenv) {
+ pseudo_diag("fatal: can't allocate new environment variable.\n");
+ }
+ snprintf(newenv, len, "PSEUDO_PREFIX=%s", prefix_path);
+ new_environ[j++] = newenv;
+ free(prefix_path);
+ }
+ if (!found_bindir) {
+ char * bindir_path = pseudo_bindir_path(NULL);
+ len = 14 + strlen(bindir_path) + 1;
+ newenv = malloc(len);
+ if (!newenv) {
+ pseudo_diag("fatal: can't allocate new environment variable.\n");
+ }
+ snprintf(newenv, len, "PSEUDO_BINDIR=%s", bindir_path);
+ new_environ[j++] = newenv;
+ free(bindir_path);
+ }
+ if (!found_libdir) {
+ char * libdir_path = pseudo_libdir_path(NULL);
+ len = 14 + strlen(libdir_path) + 1;
+ newenv = malloc(len);
+ if (!newenv) {
+ pseudo_diag("fatal: can't allocate new environment variable.\n");
+ }
+ snprintf(newenv, len, "PSEUDO_LIBDIR=%s", libdir_path);
+ new_environ[j++] = newenv;
+ free(libdir_path);
+ }
+ if (!found_localstatedir) {
+ char * localstatedir_path = pseudo_localstatedir_path(NULL);
+ len = 21 + strlen(localstatedir_path) + 1;
+ newenv = malloc(len);
+ if (!newenv) {
+ pseudo_diag("fatal: can't allocate new environment variable.\n");
+ }
+ snprintf(newenv, len, "PSEUDO_LOCALSTATEDIR=%s", localstatedir_path);
+ new_environ[j++] = newenv;
+ free(localstatedir_path);
+ }
new_environ[j++] = NULL;
return new_environ;
}