aboutsummaryrefslogtreecommitdiffstats
path: root/erts/etc
diff options
context:
space:
mode:
authorJohn Högberg <[email protected]>2017-12-05 12:06:26 +0100
committerJohn Högberg <[email protected]>2017-12-05 12:06:26 +0100
commitad484fc2003885e12b92ea49dcb1c71669761d62 (patch)
tree01c301b5c46173264cb70e4d9cdca51dad73a487 /erts/etc
parent0ac5b1f06939e36a512e5c54331e09105e127704 (diff)
parent80c8a01cf69dcf571eb28519e3f90c5bde9919cd (diff)
downloadotp-ad484fc2003885e12b92ea49dcb1c71669761d62.tar.gz
otp-ad484fc2003885e12b92ea49dcb1c71669761d62.tar.bz2
otp-ad484fc2003885e12b92ea49dcb1c71669761d62.zip
Merge branch 'john/erts/erlexec-bindir-path/OTP-14719'
Diffstat (limited to 'erts/etc')
-rw-r--r--erts/etc/common/erlexec.c43
1 files changed, 34 insertions, 9 deletions
diff --git a/erts/etc/common/erlexec.c b/erts/etc/common/erlexec.c
index 08e326b33b..f7c8c27d53 100644
--- a/erts/etc/common/erlexec.c
+++ b/erts/etc/common/erlexec.c
@@ -537,19 +537,44 @@ int main(int argc, char **argv)
} else {
add_Eargs(emu); /* argv[0] = erl or cerl */
}
- /*
- * Add the bindir to the path (unless it is there already).
- */
+
+ /* Add the bindir to the front of the PATH, and remove all subsequent
+ * occurrences to avoid ballooning it on repeated up/downgrades. */
s = get_env("PATH");
- if (!s) {
- erts_snprintf(tmpStr, sizeof(tmpStr), "%s" PATHSEP "%s" DIRSEP "bin", bindir, rootdir);
- } else if (strstr(s, bindir) == NULL) {
- erts_snprintf(tmpStr, sizeof(tmpStr), "%s" PATHSEP "%s" DIRSEP "bin" PATHSEP "%s", bindir,
- rootdir, s);
+
+ if (s == NULL) {
+ erts_snprintf(tmpStr, sizeof(tmpStr),
+ "%s" PATHSEP "%s" DIRSEP "bin" PATHSEP, bindir, rootdir);
+ } else if (strstr(s, rootdir) == NULL) {
+ erts_snprintf(tmpStr, sizeof(tmpStr),
+ "%s" PATHSEP "%s" DIRSEP "bin" PATHSEP "%s", bindir, rootdir, s);
} else {
- erts_snprintf(tmpStr, sizeof(tmpStr), "%s", s);
+ const char *bindir_slug, *bindir_slug_index;
+ int bindir_slug_length;
+ const char *in_index;
+ char *out_index;
+
+ erts_snprintf(tmpStr, sizeof(tmpStr), "%s" PATHSEP, bindir);
+
+ bindir_slug = strsave(tmpStr);
+ bindir_slug_length = strlen(bindir_slug);
+
+ out_index = &tmpStr[bindir_slug_length];
+ in_index = s;
+
+ while ((bindir_slug_index = strstr(in_index, bindir_slug))) {
+ int block_length = (bindir_slug_index - in_index);
+
+ memcpy(out_index, in_index, block_length);
+
+ in_index = bindir_slug_index + bindir_slug_length;
+ out_index += block_length;
+ }
+
+ strcpy(out_index, in_index);
}
+
free_env_val(s);
set_env("PATH", tmpStr);