summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwtc%google.com <devnull@localhost>2008-01-27 05:55:13 +0000
committerwtc%google.com <devnull@localhost>2008-01-27 05:55:13 +0000
commitc24e1d73867f047e79e4a927854cc051d8caf48e (patch)
tree64b428d89db89c5ffee631c6edc6804a5d3f5a0f
parent7de5322c4c3e4061969c39137c2c0f3ae7339eb7 (diff)
downloadnspr-hg-c24e1d73867f047e79e4a927854cc051d8caf48e.tar.gz
Bug 204151: Search for existing NSPR_INHERIT_FDS environment variable in
the environment. If it exists, replace it with the new value rather than appending the new value to the environment. r=sfraser Modified files: bproc.c uxproces.c ntmisc.c
-rw-r--r--pr/src/md/beos/bproc.c9
-rw-r--r--pr/src/md/unix/uxproces.c10
-rw-r--r--pr/src/md/windows/ntmisc.c22
3 files changed, 29 insertions, 12 deletions
diff --git a/pr/src/md/beos/bproc.c b/pr/src/md/beos/bproc.c
index f21e9465..dd24871b 100644
--- a/pr/src/md/beos/bproc.c
+++ b/pr/src/md/beos/bproc.c
@@ -50,6 +50,7 @@ _MD_create_process (const char *path, char *const *argv,
char *const *childEnvp;
char **newEnvp = NULL;
int flags;
+ PRBool found = PR_FALSE;
process = PR_NEW(PRProcess);
if (!process) {
@@ -72,8 +73,14 @@ _MD_create_process (const char *path, char *const *argv,
}
for (idx = 0; idx < nEnv; idx++) {
newEnvp[idx] = childEnvp[idx];
+ if (!found && !strncmp(newEnvp[idx], "NSPR_INHERIT_FDS=", 17)) {
+ newEnvp[idx] = attr->fdInheritBuffer;
+ found = PR_TRUE;
+ }
+ }
+ if (!found) {
+ newEnvp[idx++] = attr->fdInheritBuffer;
}
- newEnvp[idx++] = attr->fdInheritBuffer;
newEnvp[idx] = NULL;
childEnvp = newEnvp;
}
diff --git a/pr/src/md/unix/uxproces.c b/pr/src/md/unix/uxproces.c
index 6806caf2..ab19f034 100644
--- a/pr/src/md/unix/uxproces.c
+++ b/pr/src/md/unix/uxproces.c
@@ -187,6 +187,8 @@ ForkAndExec(
childEnvp = envp;
if (attr && attr->fdInheritBuffer) {
+ PRBool found = PR_FALSE;
+
if (NULL == childEnvp) {
#ifdef DARWIN
childEnvp = *(_NSGetEnviron());
@@ -204,8 +206,14 @@ ForkAndExec(
}
for (idx = 0; idx < nEnv; idx++) {
newEnvp[idx] = childEnvp[idx];
+ if (!found && !strncmp(newEnvp[idx], "NSPR_INHERIT_FDS=", 17)) {
+ newEnvp[idx] = attr->fdInheritBuffer;
+ found = PR_TRUE;
+ }
+ }
+ if (!found) {
+ newEnvp[idx++] = attr->fdInheritBuffer;
}
- newEnvp[idx++] = attr->fdInheritBuffer;
newEnvp[idx] = NULL;
childEnvp = newEnvp;
}
diff --git a/pr/src/md/windows/ntmisc.c b/pr/src/md/windows/ntmisc.c
index 67c970f3..b8c09de6 100644
--- a/pr/src/md/windows/ntmisc.c
+++ b/pr/src/md/windows/ntmisc.c
@@ -310,6 +310,7 @@ PRProcess * _PR_CreateWindowsProcess(
char **newEnvp = NULL;
const char *cwd = NULL; /* current working directory */
PRProcess *proc = NULL;
+ PRBool hasFdInheritBuffer;
proc = PR_NEW(PRProcess);
if (!proc) {
@@ -326,33 +327,34 @@ PRProcess * _PR_CreateWindowsProcess(
* If attr->fdInheritBuffer is not NULL, we need to insert
* it into the envp array, so envp cannot be NULL.
*/
- if ((envp == NULL) && attr && attr->fdInheritBuffer) {
+ hasFdInheritBuffer = (attr && attr->fdInheritBuffer);
+ if ((envp == NULL) && hasFdInheritBuffer) {
envp = environ;
}
if (envp != NULL) {
int idx;
int numEnv;
- int newEnvpSize;
+ PRBool found = PR_FALSE;
numEnv = 0;
while (envp[numEnv]) {
numEnv++;
}
- newEnvpSize = numEnv + 1; /* terminating null pointer */
- if (attr && attr->fdInheritBuffer) {
- newEnvpSize++;
- }
- newEnvp = (char **) PR_MALLOC(newEnvpSize * sizeof(char *));
+ newEnvp = (char **) PR_MALLOC((numEnv + 2) * sizeof(char *));
for (idx = 0; idx < numEnv; idx++) {
newEnvp[idx] = envp[idx];
+ if (hasFdInheritBuffer && !found
+ && !strncmp(newEnvp[idx], "NSPR_INHERIT_FDS=", 17)) {
+ newEnvp[idx] = attr->fdInheritBuffer;
+ found = PR_TRUE;
+ }
}
- if (attr && attr->fdInheritBuffer) {
+ if (hasFdInheritBuffer && !found) {
newEnvp[idx++] = attr->fdInheritBuffer;
}
newEnvp[idx] = NULL;
- qsort((void *) newEnvp, (size_t) (newEnvpSize - 1),
- sizeof(char *), compare);
+ qsort((void *) newEnvp, (size_t) idx, sizeof(char *), compare);
}
if (assembleEnvBlock(newEnvp, &envBlock) == -1) {
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);