l10n: git.pot: v2.4.0 round 2 (1 update)
[gitweb.git] / exec_cmd.c
index 23f4873b2becf3fd992b60d06b3046b1eac8ad01..8ab37b5f74f360abf8ff4d689b4ff4f3d29cf785 100644 (file)
@@ -3,21 +3,38 @@
 #include "quote.h"
 #define MAX_ARGS       32
 
-extern char **environ;
 static const char *argv_exec_path;
 static const char *argv0_path;
 
-const char *system_path(const char *path)
+char *system_path(const char *path)
 {
+#ifdef RUNTIME_PREFIX
+       static const char *prefix;
+#else
        static const char *prefix = PREFIX;
+#endif
        struct strbuf d = STRBUF_INIT;
 
        if (is_absolute_path(path))
-               return path;
+               return xstrdup(path);
+
+#ifdef RUNTIME_PREFIX
+       assert(argv0_path);
+       assert(is_absolute_path(argv0_path));
+
+       if (!prefix &&
+           !(prefix = strip_path_suffix(argv0_path, GIT_EXEC_PATH)) &&
+           !(prefix = strip_path_suffix(argv0_path, BINDIR)) &&
+           !(prefix = strip_path_suffix(argv0_path, "git"))) {
+               prefix = PREFIX;
+               trace_printf("RUNTIME_PREFIX requested, "
+                               "but prefix computation failed.  "
+                               "Using static fallback '%s'.\n", prefix);
+       }
+#endif
 
        strbuf_addf(&d, "%s/%s", prefix, path);
-       path = strbuf_detach(&d, NULL);
-       return path;
+       return strbuf_detach(&d, NULL);
 }
 
 const char *git_extract_argv0_path(const char *argv0)
@@ -42,6 +59,10 @@ const char *git_extract_argv0_path(const char *argv0)
 void git_set_argv_exec_path(const char *exec_path)
 {
        argv_exec_path = exec_path;
+       /*
+        * Propagate this setting to external programs.
+        */
+       setenv(EXEC_PATH_ENVIRONMENT, exec_path, 1);
 }
 
 
@@ -64,11 +85,7 @@ const char *git_exec_path(void)
 static void add_path(struct strbuf *out, const char *path)
 {
        if (path && *path) {
-               if (is_absolute_path(path))
-                       strbuf_addstr(out, path);
-               else
-                       strbuf_addstr(out, make_nonrelative_path(path));
-
+               strbuf_add_absolute_path(out, path);
                strbuf_addch(out, PATH_SEP);
        }
 }
@@ -84,7 +101,7 @@ void setup_path(void)
        if (old_path)
                strbuf_addstr(&new_path, old_path);
        else
-               strbuf_addstr(&new_path, "/usr/local/bin:/usr/bin:/bin");
+               strbuf_addstr(&new_path, _PATH_DEFPATH);
 
        setenv("PATH", new_path.buf, 1);
 
@@ -112,7 +129,7 @@ int execv_git_cmd(const char **argv) {
        trace_argv_printf(nargv, "trace: exec:");
 
        /* execvp() can only ever return if it fails */
-       execvp("git", (char **)nargv);
+       sane_execvp("git", (char **)nargv);
 
        trace_printf("trace: exec failed: %s\n", strerror(errno));