e start - fix path prepend/append if already in path assuming clue

"
I have a directory at the head of my PATH that contains alternate
versions of command line utils like grep, ls, etc., but E puts
/usr/bin ahead of it, overriding my tools of choice with the system
defaults.

If my understanding is correct, the only way currently to have
directories that E prepends to your PATH appended instead is to use
-i-really-know-what-i-am-doing-and-accept-full-responsibility-for-it.
I'd like to see a more sane option if there isn't one already.
Alternatively, I wonder if it wouldn't be a better idea to only
prepend directories to PATH if they aren't already contained within
it--thereby preserving the user's desired search order.
"

this should fix T5953

@fix
This commit is contained in:
Carsten Haitzler 2017-09-13 18:32:38 +09:00 committed by Mike Blumenkrantz
parent 82e095e8b0
commit d8753a3c72
1 changed files with 58 additions and 4 deletions

View File

@ -1,6 +1,7 @@
#include "config.h"
#include <stdio.h>
#include <unistd.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
@ -495,6 +496,56 @@ _e_call_alert(int child, siginfo_t sig, int exit_gdb, const char *backtrace_str,
return system(buf);
}
static int
path_contains(const char *path)
{
char *realp, *realp2, *env2 = NULL, *p, *p2;
char buf[PATH_MAX], buf2[PATH_MAX];
const char *env;
ssize_t p_len;
int ret = 0;
if (!path) return ret;
realp = realpath(path, buf);
if (!realp) realp = (char *)path;
env = getenv("PATH");
if (!env) goto done;
env2 = strdup(env);
if (!env2) goto done;
p = env2;
while (p)
{
p2 = strchr(p, ':');
if (p2) p_len = p2 - p;
else p_len = strlen(p);
if (p_len <= 0) goto next;
if (p2) *p2 = 0;
realp2 = realpath(p, buf2);
if (realp2)
{
if (!strcmp(realp, realp2)) goto ok;
}
else
{
if (!strcmp(realp, p)) goto ok;
}
next:
if (p2) p = p2 + 1;
else break;
}
// failed to find
goto done;
ok:
ret = 1;
done:
free(env2);
return ret;
}
int
main(int argc, char **argv)
{
@ -504,6 +555,7 @@ main(int argc, char **argv)
char buf[16384], **args, *home;
char valgrind_path[PATH_MAX] = "";
const char *valgrind_log = NULL;
const char *bindir;
Eina_Bool really_know = EINA_FALSE;
struct sigaction action;
pid_t child = -1;
@ -592,10 +644,12 @@ main(int argc, char **argv)
}
}
if (really_know)
_env_path_append("PATH", eina_prefix_bin_get(pfx));
else
_env_path_prepend("PATH", eina_prefix_bin_get(pfx));
bindir = eina_prefix_bin_get(pfx);
if (!path_contains(bindir))
{
if (really_know) _env_path_append("PATH", bindir);
else _env_path_prepend("PATH", bindir);
}
if ((valgrind_mode || valgrind_tool) &&
!find_valgrind(valgrind_path, sizeof(valgrind_path)))