Skip to content

Commit 49ea669

Browse files
brad0gitster
authored andcommitted
exec_cmd: RUNTIME_PREFIX on OpenBSD systems
Enable Git to resolve its own binary location using getexecpath(). Signed-off-by: Brad Smith <brad@comstyle.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent d38352c commit 49ea669

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

‎Makefile‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,9 @@ include shared.mak
378378
# Perl scripts to use a modified entry point header allowing them to resolve
379379
# support files at runtime.
380380
#
381+
# When using RUNTIME_PREFIX, define HAVE_GETEXECPATH if your platform supports
382+
# the getexecpath() function.
383+
#
381384
# When using RUNTIME_PREFIX, define HAVE_BSD_KERN_PROC_SYSCTL if your platform
382385
# supports the KERN_PROC BSD sysctl function.
383386
#
@@ -2356,6 +2359,10 @@ endif
23562359

23572360
ifdef RUNTIME_PREFIX
23582361

2362+
ifdef HAVE_GETEXECPATH
2363+
BASIC_CFLAGS += -DHAVE_GETEXECPATH
2364+
endif
2365+
23592366
ifdef HAVE_BSD_KERN_PROC_SYSCTL
23602367
BASIC_CFLAGS += -DHAVE_BSD_KERN_PROC_SYSCTL
23612368
endif

‎config.mak.uname‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,9 @@ ifeq ($(uname_S),OpenBSD)
343343
CSPRNG_METHOD = arc4random
344344
FREAD_READS_DIRECTORIES = UnfortunatelyYes
345345
FILENO_IS_A_MACRO = UnfortunatelyYes
346+
ifeq ($(shell test "`expr "$(uname_R)" : '\([0-9][0-9]*\)\.'`" -ge 8 && echo 1),1)
347+
HAVE_GETEXECPATH = YesPlease
348+
endif
346349
endif
347350
ifeq ($(uname_S),MirBSD)
348351
NO_STRCASESTR = YesPlease

‎exec-cmd.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,26 @@ static int git_get_exec_path_bsd_sysctl(struct strbuf *buf)
129129
}
130130
#endif /* HAVE_BSD_KERN_PROC_SYSCTL */
131131

132+
#ifdef HAVE_GETEXECPATH
133+
/*
134+
* Resolves the executable path using getexecpath(3).
135+
*
136+
* Returns 0 on success, -1 on failure.
137+
*/
138+
static int git_get_exec_path_getexecpath(struct strbuf *buf)
139+
{
140+
char path[PATH_MAX];
141+
if (getexecpath(path, sizeof(path)) == 0) {
142+
trace_printf(
143+
"trace: resolved executable path from getexecpath: %s\n",
144+
path);
145+
strbuf_addstr(buf, path);
146+
return 0;
147+
}
148+
return -1;
149+
}
150+
#endif /* HAVE_GETEXECPATH */
151+
132152
#ifdef HAVE_NS_GET_EXECUTABLE_PATH
133153
/*
134154
* Resolves the executable path by querying Darwin application stack.
@@ -209,6 +229,10 @@ static int git_get_exec_path(struct strbuf *buf, const char *argv0)
209229
* after the first successful method.
210230
*/
211231
if (
232+
#ifdef HAVE_GETEXECPATH
233+
git_get_exec_path_getexecpath(buf) &&
234+
#endif /* HAVE_GETEXECPATH */
235+
212236
#ifdef HAVE_BSD_KERN_PROC_SYSCTL
213237
git_get_exec_path_bsd_sysctl(buf) &&
214238
#endif /* HAVE_BSD_KERN_PROC_SYSCTL */

0 commit comments

Comments
 (0)