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