raster pushed a commit to branch master.

http://git.enlightenment.org/core/enlightenment.git/commit/?id=6972a97d5df5b0cc567c87f1e9717f97c97ad897

commit 6972a97d5df5b0cc567c87f1e9717f97c97ad897
Author: Carsten Haitzler (Rasterman) <[email protected]>
Date:   Wed Sep 13 18:32:38 2017 +0900

    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
---
 src/bin/e_start_main.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 58 insertions(+), 4 deletions(-)

diff --git a/src/bin/e_start_main.c b/src/bin/e_start_main.c
index 6088abcd1..457dcf17b 100644
--- a/src/bin/e_start_main.c
+++ b/src/bin/e_start_main.c
@@ -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>
@@ -466,6 +467,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)
 {
@@ -475,6 +526,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;
@@ -559,10 +611,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)))

-- 


Reply via email to