]>
git.ipfire.org Git - thirdparty/git.git/blob - exec_cmd.c
7 static const char *argv_exec_path
;
9 static const char *builtin_exec_path(void)
14 void git_set_argv_exec_path(const char *exec_path
)
16 argv_exec_path
= exec_path
;
20 /* Returns the highest-priority, location to look for git programs. */
21 const char *git_exec_path(void)
26 return argv_exec_path
;
28 env
= getenv(EXEC_PATH_ENVIRONMENT
);
33 return builtin_exec_path();
36 static void add_path(struct strbuf
*out
, const char *path
)
39 if (is_absolute_path(path
))
40 strbuf_addstr(out
, path
);
42 strbuf_addstr(out
, make_absolute_path(path
));
44 strbuf_addch(out
, PATH_SEP
);
48 void setup_path(const char *cmd_path
)
50 const char *old_path
= getenv("PATH");
51 struct strbuf new_path
;
53 strbuf_init(&new_path
, 0);
55 add_path(&new_path
, argv_exec_path
);
56 add_path(&new_path
, getenv(EXEC_PATH_ENVIRONMENT
));
57 add_path(&new_path
, builtin_exec_path());
58 add_path(&new_path
, cmd_path
);
61 strbuf_addstr(&new_path
, old_path
);
63 strbuf_addstr(&new_path
, "/usr/local/bin:/usr/bin:/bin");
65 setenv("PATH", new_path
.buf
, 1);
67 strbuf_release(&new_path
);
70 int execv_git_cmd(const char **argv
)
76 strbuf_addf(&cmd
, "git-%s", argv
[0]);
79 * argv[0] must be the git command, but the argv array
80 * belongs to the caller, and may be reused in
81 * subsequent loop iterations. Save argv[0] and
82 * restore it on error.
87 trace_argv_printf(argv
, "trace: exec:");
89 /* execvp() can only ever return if it fails */
90 execvp(cmd
.buf
, (char **)argv
);
92 trace_printf("trace: exec failed: %s\n", strerror(errno
));
102 int execl_git_cmd(const char *cmd
,...)
105 const char *argv
[MAX_ARGS
+ 1];
109 va_start(param
, cmd
);
112 while (argc
< MAX_ARGS
) {
113 arg
= argv
[argc
++] = va_arg(param
, char *);
118 if (MAX_ARGS
<= argc
)
119 return error("too many args to run %s", cmd
);
122 return execv_git_cmd(argv
);