aboutsummaryrefslogtreecommitdiffstats
path: root/erts/etc
diff options
context:
space:
mode:
authorJohn Högberg <[email protected]>2017-11-21 10:38:48 +0100
committerJohn Högberg <[email protected]>2017-12-05 09:57:47 +0100
commit80c8a01cf69dcf571eb28519e3f90c5bde9919cd (patch)
tree7637f75036950713fbae863ad2ef408ca990df62 /erts/etc
parentbab7b1aba04209c90d15be7147cc3524ae6964f5 (diff)
downloadotp-80c8a01cf69dcf571eb28519e3f90c5bde9919cd.tar.gz
otp-80c8a01cf69dcf571eb28519e3f90c5bde9919cd.tar.bz2
otp-80c8a01cf69dcf571eb28519e3f90c5bde9919cd.zip
Ensure that bindir is first in $PATH on startup
erlexec adds $ROOT/erts-<vsn>/bin and $ROOT/bin first in $PATH on startup, but didn't do so if they were in the $PATH already, which meant that the bindir didn't point to the current release after a downgrade.
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 eaa94cd5e4..860e721beb 100644
--- a/erts/etc/common/erlexec.c
+++ b/erts/etc/common/erlexec.c
@@ -558,19 +558,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);