Michal Ostrowski | 77cb17e | 2006-01-10 21:12:17 -0500 | [diff] [blame] | 1 | #include "cache.h" |
Stefan Beller | d807c4a | 2018-04-10 14:26:18 -0700 | [diff] [blame] | 2 | #include "exec-cmd.h" |
Matthias Lederhofer | 575ba9d | 2006-06-25 15:56:18 +0200 | [diff] [blame] | 3 | #include "quote.h" |
Jeff King | dbbcd44 | 2020-07-28 16:23:39 -0400 | [diff] [blame] | 4 | #include "strvec.h" |
Michal Ostrowski | 77cb17e | 2006-01-10 21:12:17 -0500 | [diff] [blame] | 5 | |
Dan Jacques | 226c0dd | 2018-04-10 11:05:44 -0400 | [diff] [blame] | 6 | #if defined(RUNTIME_PREFIX) |
| 7 | |
| 8 | #if defined(HAVE_NS_GET_EXECUTABLE_PATH) |
| 9 | #include <mach-o/dyld.h> |
| 10 | #endif |
| 11 | |
| 12 | #if defined(HAVE_BSD_KERN_PROC_SYSCTL) |
| 13 | #include <sys/param.h> |
| 14 | #include <sys/types.h> |
| 15 | #include <sys/sysctl.h> |
| 16 | #endif |
| 17 | |
| 18 | #endif /* RUNTIME_PREFIX */ |
| 19 | |
| 20 | #define MAX_ARGS 32 |
| 21 | |
| 22 | static const char *system_prefix(void); |
Michal Ostrowski | 77cb17e | 2006-01-10 21:12:17 -0500 | [diff] [blame] | 23 | |
Jeff King | 39b2f6a | 2017-09-06 08:30:28 -0400 | [diff] [blame] | 24 | #ifdef RUNTIME_PREFIX |
Dan Jacques | 226c0dd | 2018-04-10 11:05:44 -0400 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * When using a runtime prefix, Git dynamically resolves paths relative to its |
| 28 | * executable. |
| 29 | * |
| 30 | * The method for determining the path of the executable is highly |
| 31 | * platform-specific. |
| 32 | */ |
| 33 | |
| 34 | /** |
| 35 | * Path to the current Git executable. Resolved on startup by |
| 36 | * 'git_resolve_executable_dir'. |
| 37 | */ |
| 38 | static const char *executable_dirname; |
Jeff King | 39b2f6a | 2017-09-06 08:30:28 -0400 | [diff] [blame] | 39 | |
| 40 | static const char *system_prefix(void) |
Steffen Prohaska | 2de9de5 | 2008-07-13 22:31:18 +0200 | [diff] [blame] | 41 | { |
Steffen Prohaska | 35fb0e86 | 2009-01-18 13:00:14 +0100 | [diff] [blame] | 42 | static const char *prefix; |
Steffen Prohaska | 026fa0d | 2009-01-18 13:00:09 +0100 | [diff] [blame] | 43 | |
Dan Jacques | 226c0dd | 2018-04-10 11:05:44 -0400 | [diff] [blame] | 44 | assert(executable_dirname); |
| 45 | assert(is_absolute_path(executable_dirname)); |
Steffen Prohaska | 35fb0e86 | 2009-01-18 13:00:14 +0100 | [diff] [blame] | 46 | |
Johannes Schindelin | 024aa7d | 2009-02-19 20:10:53 +0100 | [diff] [blame] | 47 | if (!prefix && |
Dan Jacques | 226c0dd | 2018-04-10 11:05:44 -0400 | [diff] [blame] | 48 | !(prefix = strip_path_suffix(executable_dirname, GIT_EXEC_PATH)) && |
| 49 | !(prefix = strip_path_suffix(executable_dirname, BINDIR)) && |
| 50 | !(prefix = strip_path_suffix(executable_dirname, "git"))) { |
Philip Oakley | 4d5b4c2 | 2018-04-21 13:18:42 +0200 | [diff] [blame] | 51 | prefix = FALLBACK_RUNTIME_PREFIX; |
Johannes Sixt | aa09457 | 2010-02-23 12:42:56 +0100 | [diff] [blame] | 52 | trace_printf("RUNTIME_PREFIX requested, " |
Steffen Prohaska | 35fb0e86 | 2009-01-18 13:00:14 +0100 | [diff] [blame] | 53 | "but prefix computation failed. " |
| 54 | "Using static fallback '%s'.\n", prefix); |
| 55 | } |
Jeff King | 39b2f6a | 2017-09-06 08:30:28 -0400 | [diff] [blame] | 56 | return prefix; |
| 57 | } |
Jeff King | c1bb33c | 2017-09-06 08:32:10 -0400 | [diff] [blame] | 58 | |
Dan Jacques | 226c0dd | 2018-04-10 11:05:44 -0400 | [diff] [blame] | 59 | /* |
| 60 | * Resolves the executable path from argv[0], only if it is absolute. |
| 61 | * |
| 62 | * Returns 0 on success, -1 on failure. |
| 63 | */ |
| 64 | static int git_get_exec_path_from_argv0(struct strbuf *buf, const char *argv0) |
Jeff King | c1bb33c | 2017-09-06 08:32:10 -0400 | [diff] [blame] | 65 | { |
| 66 | const char *slash; |
| 67 | |
| 68 | if (!argv0 || !*argv0) |
Dan Jacques | 226c0dd | 2018-04-10 11:05:44 -0400 | [diff] [blame] | 69 | return -1; |
Jeff King | c1bb33c | 2017-09-06 08:32:10 -0400 | [diff] [blame] | 70 | |
| 71 | slash = find_last_dir_sep(argv0); |
Dan Jacques | 226c0dd | 2018-04-10 11:05:44 -0400 | [diff] [blame] | 72 | if (slash) { |
| 73 | trace_printf("trace: resolved executable path from argv0: %s\n", |
| 74 | argv0); |
| 75 | strbuf_add_absolute_path(buf, argv0); |
| 76 | return 0; |
| 77 | } |
| 78 | return -1; |
| 79 | } |
Jeff King | c1bb33c | 2017-09-06 08:32:10 -0400 | [diff] [blame] | 80 | |
Dan Jacques | 226c0dd | 2018-04-10 11:05:44 -0400 | [diff] [blame] | 81 | #ifdef PROCFS_EXECUTABLE_PATH |
| 82 | /* |
| 83 | * Resolves the executable path by examining a procfs symlink. |
| 84 | * |
| 85 | * Returns 0 on success, -1 on failure. |
| 86 | */ |
| 87 | static int git_get_exec_path_procfs(struct strbuf *buf) |
| 88 | { |
| 89 | if (strbuf_realpath(buf, PROCFS_EXECUTABLE_PATH, 0)) { |
| 90 | trace_printf( |
| 91 | "trace: resolved executable path from procfs: %s\n", |
| 92 | buf->buf); |
| 93 | return 0; |
| 94 | } |
| 95 | return -1; |
| 96 | } |
| 97 | #endif /* PROCFS_EXECUTABLE_PATH */ |
| 98 | |
| 99 | #ifdef HAVE_BSD_KERN_PROC_SYSCTL |
| 100 | /* |
| 101 | * Resolves the executable path using KERN_PROC_PATHNAME BSD sysctl. |
| 102 | * |
| 103 | * Returns 0 on success, -1 on failure. |
| 104 | */ |
| 105 | static int git_get_exec_path_bsd_sysctl(struct strbuf *buf) |
| 106 | { |
| 107 | int mib[4]; |
| 108 | char path[MAXPATHLEN]; |
| 109 | size_t cb = sizeof(path); |
| 110 | |
| 111 | mib[0] = CTL_KERN; |
| 112 | mib[1] = KERN_PROC; |
| 113 | mib[2] = KERN_PROC_PATHNAME; |
| 114 | mib[3] = -1; |
| 115 | if (!sysctl(mib, 4, path, &cb, NULL, 0)) { |
| 116 | trace_printf( |
| 117 | "trace: resolved executable path from sysctl: %s\n", |
| 118 | path); |
| 119 | strbuf_addstr(buf, path); |
| 120 | return 0; |
| 121 | } |
| 122 | return -1; |
| 123 | } |
| 124 | #endif /* HAVE_BSD_KERN_PROC_SYSCTL */ |
| 125 | |
| 126 | #ifdef HAVE_NS_GET_EXECUTABLE_PATH |
| 127 | /* |
| 128 | * Resolves the executable path by querying Darwin application stack. |
| 129 | * |
| 130 | * Returns 0 on success, -1 on failure. |
| 131 | */ |
| 132 | static int git_get_exec_path_darwin(struct strbuf *buf) |
| 133 | { |
| 134 | char path[PATH_MAX]; |
| 135 | uint32_t size = sizeof(path); |
| 136 | if (!_NSGetExecutablePath(path, &size)) { |
| 137 | trace_printf( |
| 138 | "trace: resolved executable path from Darwin stack: %s\n", |
| 139 | path); |
| 140 | strbuf_addstr(buf, path); |
| 141 | return 0; |
| 142 | } |
| 143 | return -1; |
| 144 | } |
| 145 | #endif /* HAVE_NS_GET_EXECUTABLE_PATH */ |
| 146 | |
Johannes Schindelin | c1be1cb | 2018-04-10 11:05:45 -0400 | [diff] [blame] | 147 | #ifdef HAVE_WPGMPTR |
| 148 | /* |
| 149 | * Resolves the executable path by using the global variable _wpgmptr. |
| 150 | * |
| 151 | * Returns 0 on success, -1 on failure. |
| 152 | */ |
| 153 | static int git_get_exec_path_wpgmptr(struct strbuf *buf) |
| 154 | { |
| 155 | int len = wcslen(_wpgmptr) * 3 + 1; |
| 156 | strbuf_grow(buf, len); |
| 157 | len = xwcstoutf(buf->buf, _wpgmptr, len); |
| 158 | if (len < 0) |
| 159 | return -1; |
| 160 | buf->len += len; |
| 161 | return 0; |
| 162 | } |
| 163 | #endif /* HAVE_WPGMPTR */ |
| 164 | |
Dan Jacques | 226c0dd | 2018-04-10 11:05:44 -0400 | [diff] [blame] | 165 | /* |
| 166 | * Resolves the absolute path of the current executable. |
| 167 | * |
| 168 | * Returns 0 on success, -1 on failure. |
| 169 | */ |
| 170 | static int git_get_exec_path(struct strbuf *buf, const char *argv0) |
| 171 | { |
| 172 | /* |
| 173 | * Identifying the executable path is operating system specific. |
| 174 | * Selectively employ all available methods in order of preference, |
| 175 | * preferring highly-available authoritative methods over |
| 176 | * selectively-available or non-authoritative methods. |
| 177 | * |
| 178 | * All cases fall back on resolving against argv[0] if there isn't a |
| 179 | * better functional method. However, note that argv[0] can be |
| 180 | * used-supplied on many operating systems, and is not authoritative |
| 181 | * in those cases. |
| 182 | * |
| 183 | * Each of these functions returns 0 on success, so evaluation will stop |
| 184 | * after the first successful method. |
| 185 | */ |
| 186 | if ( |
| 187 | #ifdef HAVE_BSD_KERN_PROC_SYSCTL |
| 188 | git_get_exec_path_bsd_sysctl(buf) && |
| 189 | #endif /* HAVE_BSD_KERN_PROC_SYSCTL */ |
| 190 | |
| 191 | #ifdef HAVE_NS_GET_EXECUTABLE_PATH |
| 192 | git_get_exec_path_darwin(buf) && |
| 193 | #endif /* HAVE_NS_GET_EXECUTABLE_PATH */ |
| 194 | |
| 195 | #ifdef PROCFS_EXECUTABLE_PATH |
| 196 | git_get_exec_path_procfs(buf) && |
| 197 | #endif /* PROCFS_EXECUTABLE_PATH */ |
| 198 | |
Johannes Schindelin | c1be1cb | 2018-04-10 11:05:45 -0400 | [diff] [blame] | 199 | #ifdef HAVE_WPGMPTR |
| 200 | git_get_exec_path_wpgmptr(buf) && |
| 201 | #endif /* HAVE_WPGMPTR */ |
| 202 | |
Dan Jacques | 226c0dd | 2018-04-10 11:05:44 -0400 | [diff] [blame] | 203 | git_get_exec_path_from_argv0(buf, argv0)) { |
| 204 | return -1; |
| 205 | } |
| 206 | |
| 207 | if (strbuf_normalize_path(buf)) { |
| 208 | trace_printf("trace: could not normalize path: %s\n", buf->buf); |
| 209 | return -1; |
| 210 | } |
| 211 | |
Jeff Hostetler | ee4512e | 2019-02-22 14:25:01 -0800 | [diff] [blame] | 212 | trace2_cmd_path(buf->buf); |
| 213 | |
Dan Jacques | 226c0dd | 2018-04-10 11:05:44 -0400 | [diff] [blame] | 214 | return 0; |
| 215 | } |
| 216 | |
| 217 | void git_resolve_executable_dir(const char *argv0) |
| 218 | { |
| 219 | struct strbuf buf = STRBUF_INIT; |
| 220 | char *resolved; |
| 221 | const char *slash; |
| 222 | |
| 223 | if (git_get_exec_path(&buf, argv0)) { |
| 224 | trace_printf( |
| 225 | "trace: could not determine executable path from: %s\n", |
| 226 | argv0); |
| 227 | strbuf_release(&buf); |
| 228 | return; |
| 229 | } |
| 230 | |
| 231 | resolved = strbuf_detach(&buf, NULL); |
| 232 | slash = find_last_dir_sep(resolved); |
Jeff King | c1bb33c | 2017-09-06 08:32:10 -0400 | [diff] [blame] | 233 | if (slash) |
Dan Jacques | 226c0dd | 2018-04-10 11:05:44 -0400 | [diff] [blame] | 234 | resolved[slash - resolved] = '\0'; |
| 235 | |
| 236 | executable_dirname = resolved; |
| 237 | trace_printf("trace: resolved executable dir: %s\n", |
| 238 | executable_dirname); |
Jeff King | c1bb33c | 2017-09-06 08:32:10 -0400 | [diff] [blame] | 239 | } |
| 240 | |
Jeff King | 39b2f6a | 2017-09-06 08:30:28 -0400 | [diff] [blame] | 241 | #else |
Steffen Prohaska | 35fb0e86 | 2009-01-18 13:00:14 +0100 | [diff] [blame] | 242 | |
Dan Jacques | 226c0dd | 2018-04-10 11:05:44 -0400 | [diff] [blame] | 243 | /* |
| 244 | * When not using a runtime prefix, Git uses a hard-coded path. |
| 245 | */ |
Jeff King | 39b2f6a | 2017-09-06 08:30:28 -0400 | [diff] [blame] | 246 | static const char *system_prefix(void) |
| 247 | { |
Philip Oakley | 4d5b4c2 | 2018-04-21 13:18:42 +0200 | [diff] [blame] | 248 | return FALLBACK_RUNTIME_PREFIX; |
Jeff King | 39b2f6a | 2017-09-06 08:30:28 -0400 | [diff] [blame] | 249 | } |
| 250 | |
Dan Jacques | 226c0dd | 2018-04-10 11:05:44 -0400 | [diff] [blame] | 251 | /* |
| 252 | * This is called during initialization, but No work needs to be done here when |
| 253 | * runtime prefix is not being used. |
| 254 | */ |
| 255 | void git_resolve_executable_dir(const char *argv0) |
Jeff King | c1bb33c | 2017-09-06 08:32:10 -0400 | [diff] [blame] | 256 | { |
| 257 | } |
| 258 | |
Jeff King | 39b2f6a | 2017-09-06 08:30:28 -0400 | [diff] [blame] | 259 | #endif /* RUNTIME_PREFIX */ |
| 260 | |
| 261 | char *system_path(const char *path) |
| 262 | { |
| 263 | struct strbuf d = STRBUF_INIT; |
| 264 | |
| 265 | if (is_absolute_path(path)) |
| 266 | return xstrdup(path); |
| 267 | |
| 268 | strbuf_addf(&d, "%s/%s", system_prefix(), path); |
Junio C Hamano | 59362e5 | 2014-11-24 11:33:54 -0800 | [diff] [blame] | 269 | return strbuf_detach(&d, NULL); |
Steffen Prohaska | 2de9de5 | 2008-07-13 22:31:18 +0200 | [diff] [blame] | 270 | } |
| 271 | |
Dan Jacques | 226c0dd | 2018-04-10 11:05:44 -0400 | [diff] [blame] | 272 | static const char *exec_path_value; |
| 273 | |
| 274 | void git_set_exec_path(const char *exec_path) |
Michal Ostrowski | 77cb17e | 2006-01-10 21:12:17 -0500 | [diff] [blame] | 275 | { |
Dan Jacques | 226c0dd | 2018-04-10 11:05:44 -0400 | [diff] [blame] | 276 | exec_path_value = exec_path; |
Johannes Sixt | c90d565 | 2009-03-21 23:21:18 +0100 | [diff] [blame] | 277 | /* |
| 278 | * Propagate this setting to external programs. |
| 279 | */ |
| 280 | setenv(EXEC_PATH_ENVIRONMENT, exec_path, 1); |
Michal Ostrowski | 77cb17e | 2006-01-10 21:12:17 -0500 | [diff] [blame] | 281 | } |
| 282 | |
Dan Jacques | 226c0dd | 2018-04-10 11:05:44 -0400 | [diff] [blame] | 283 | /* Returns the highest-priority location to look for git programs. */ |
Timo Hirvonen | 962554c | 2006-02-26 17:13:46 +0200 | [diff] [blame] | 284 | const char *git_exec_path(void) |
Michal Ostrowski | 77cb17e | 2006-01-10 21:12:17 -0500 | [diff] [blame] | 285 | { |
Dan Jacques | 226c0dd | 2018-04-10 11:05:44 -0400 | [diff] [blame] | 286 | if (!exec_path_value) { |
Jeff King | 007ac54 | 2017-01-09 01:00:12 -0500 | [diff] [blame] | 287 | const char *env = getenv(EXEC_PATH_ENVIRONMENT); |
| 288 | if (env && *env) |
Dan Jacques | 226c0dd | 2018-04-10 11:05:44 -0400 | [diff] [blame] | 289 | exec_path_value = xstrdup(env); |
Jeff King | 007ac54 | 2017-01-09 01:00:12 -0500 | [diff] [blame] | 290 | else |
Dan Jacques | 226c0dd | 2018-04-10 11:05:44 -0400 | [diff] [blame] | 291 | exec_path_value = system_path(GIT_EXEC_PATH); |
Michal Ostrowski | 77cb17e | 2006-01-10 21:12:17 -0500 | [diff] [blame] | 292 | } |
Dan Jacques | 226c0dd | 2018-04-10 11:05:44 -0400 | [diff] [blame] | 293 | return exec_path_value; |
Michal Ostrowski | 77cb17e | 2006-01-10 21:12:17 -0500 | [diff] [blame] | 294 | } |
| 295 | |
Scott R Parish | 511707d | 2007-10-28 04:17:20 -0700 | [diff] [blame] | 296 | static void add_path(struct strbuf *out, const char *path) |
| 297 | { |
| 298 | if (path && *path) { |
René Scharfe | 9610dec | 2014-07-28 20:34:42 +0200 | [diff] [blame] | 299 | strbuf_add_absolute_path(out, path); |
Johannes Sixt | 80ba074 | 2007-12-03 21:55:57 +0100 | [diff] [blame] | 300 | strbuf_addch(out, PATH_SEP); |
Scott R Parish | 511707d | 2007-10-28 04:17:20 -0700 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
Johannes Sixt | e1464ca | 2008-07-21 21:19:52 +0200 | [diff] [blame] | 304 | void setup_path(void) |
Scott R Parish | 511707d | 2007-10-28 04:17:20 -0700 | [diff] [blame] | 305 | { |
Dan Jacques | 226c0dd | 2018-04-10 11:05:44 -0400 | [diff] [blame] | 306 | const char *exec_path = git_exec_path(); |
Scott R Parish | 511707d | 2007-10-28 04:17:20 -0700 | [diff] [blame] | 307 | const char *old_path = getenv("PATH"); |
Brandon Casey | f285a2d | 2008-10-09 14:12:12 -0500 | [diff] [blame] | 308 | struct strbuf new_path = STRBUF_INIT; |
Scott R Parish | 511707d | 2007-10-28 04:17:20 -0700 | [diff] [blame] | 309 | |
Dan Jacques | 226c0dd | 2018-04-10 11:05:44 -0400 | [diff] [blame] | 310 | git_set_exec_path(exec_path); |
| 311 | add_path(&new_path, exec_path); |
Scott R Parish | 511707d | 2007-10-28 04:17:20 -0700 | [diff] [blame] | 312 | |
| 313 | if (old_path) |
| 314 | strbuf_addstr(&new_path, old_path); |
| 315 | else |
Chris Webb | cb6a22c | 2010-04-13 10:07:13 +0100 | [diff] [blame] | 316 | strbuf_addstr(&new_path, _PATH_DEFPATH); |
Scott R Parish | 511707d | 2007-10-28 04:17:20 -0700 | [diff] [blame] | 317 | |
| 318 | setenv("PATH", new_path.buf, 1); |
| 319 | |
| 320 | strbuf_release(&new_path); |
| 321 | } |
Michal Ostrowski | 77cb17e | 2006-01-10 21:12:17 -0500 | [diff] [blame] | 322 | |
Jeff King | ef8d7ac | 2020-07-28 16:24:53 -0400 | [diff] [blame] | 323 | const char **prepare_git_cmd(struct strvec *out, const char **argv) |
Michal Ostrowski | 77cb17e | 2006-01-10 21:12:17 -0500 | [diff] [blame] | 324 | { |
Jeff King | ef8d7ac | 2020-07-28 16:24:53 -0400 | [diff] [blame] | 325 | strvec_push(out, "git"); |
| 326 | strvec_pushv(out, argv); |
Jeff King | d70a9eb | 2020-07-28 20:37:20 -0400 | [diff] [blame] | 327 | return out->v; |
Steffen Prohaska | 4933e5e | 2008-07-28 07:50:27 +0200 | [diff] [blame] | 328 | } |
| 329 | |
Dan Jacques | 226c0dd | 2018-04-10 11:05:44 -0400 | [diff] [blame] | 330 | int execv_git_cmd(const char **argv) |
| 331 | { |
Jeff King | ef8d7ac | 2020-07-28 16:24:53 -0400 | [diff] [blame] | 332 | struct strvec nargv = STRVEC_INIT; |
Jeff King | 20574f5 | 2016-02-22 17:44:39 -0500 | [diff] [blame] | 333 | |
| 334 | prepare_git_cmd(&nargv, argv); |
Jeff King | d70a9eb | 2020-07-28 20:37:20 -0400 | [diff] [blame] | 335 | trace_argv_printf(nargv.v, "trace: exec:"); |
Michal Ostrowski | 77cb17e | 2006-01-10 21:12:17 -0500 | [diff] [blame] | 336 | |
Scott R Parish | 511707d | 2007-10-28 04:17:20 -0700 | [diff] [blame] | 337 | /* execvp() can only ever return if it fails */ |
Jeff King | d70a9eb | 2020-07-28 20:37:20 -0400 | [diff] [blame] | 338 | sane_execvp("git", (char **)nargv.v); |
Dmitry V. Levin | d685990 | 2006-05-30 18:58:52 +0400 | [diff] [blame] | 339 | |
Scott R Parish | 511707d | 2007-10-28 04:17:20 -0700 | [diff] [blame] | 340 | trace_printf("trace: exec failed: %s\n", strerror(errno)); |
Michal Ostrowski | 77cb17e | 2006-01-10 21:12:17 -0500 | [diff] [blame] | 341 | |
Jeff King | ef8d7ac | 2020-07-28 16:24:53 -0400 | [diff] [blame] | 342 | strvec_clear(&nargv); |
Michal Ostrowski | 77cb17e | 2006-01-10 21:12:17 -0500 | [diff] [blame] | 343 | return -1; |
Michal Ostrowski | 77cb17e | 2006-01-10 21:12:17 -0500 | [diff] [blame] | 344 | } |
| 345 | |
Dan Jacques | 226c0dd | 2018-04-10 11:05:44 -0400 | [diff] [blame] | 346 | int execl_git_cmd(const char *cmd, ...) |
Michal Ostrowski | 77cb17e | 2006-01-10 21:12:17 -0500 | [diff] [blame] | 347 | { |
| 348 | int argc; |
Junio C Hamano | 9201c70 | 2006-03-05 02:47:29 -0800 | [diff] [blame] | 349 | const char *argv[MAX_ARGS + 1]; |
| 350 | const char *arg; |
Michal Ostrowski | 77cb17e | 2006-01-10 21:12:17 -0500 | [diff] [blame] | 351 | va_list param; |
| 352 | |
| 353 | va_start(param, cmd); |
| 354 | argv[0] = cmd; |
| 355 | argc = 1; |
| 356 | while (argc < MAX_ARGS) { |
| 357 | arg = argv[argc++] = va_arg(param, char *); |
| 358 | if (!arg) |
| 359 | break; |
| 360 | } |
| 361 | va_end(param); |
| 362 | if (MAX_ARGS <= argc) |
Nguyễn Thái Ngọc Duy | 31a55e9 | 2018-07-21 09:49:32 +0200 | [diff] [blame] | 363 | return error(_("too many args to run %s"), cmd); |
Michal Ostrowski | 77cb17e | 2006-01-10 21:12:17 -0500 | [diff] [blame] | 364 | |
| 365 | argv[argc] = NULL; |
| 366 | return execv_git_cmd(argv); |
| 367 | } |