* [PATCH] exec_cmd: RUNTIME_PREFIX on OpenBSD systems
@ 2026-09-17 3:40 Brad Smith
2026-09-17 13:45 ` Junio C Hamano
0 siblings, 1 reply; 7+ messages in thread
From: Brad Smith @ 2026-09-17 3:40 UTC (permalink / raw)
To: git
Enable Git to resolve its own binary location using getexecpath().
Signed-off-by: Brad Smith <brad@comstyle.com>
---
Makefile | 7 +++++++
config.mak.uname | 3 +++
exec-cmd.c | 24 ++++++++++++++++++++++++
3 files changed, 34 insertions(+)
diff --git a/Makefile b/Makefile
index d4b775953d..9e3d37b5b4 100644
--- a/Makefile
+++ b/Makefile
@@ -378,6 +378,9 @@ include shared.mak
# Perl scripts to use a modified entry point header allowing them to resolve
# support files at runtime.
#
+# When using RUNTIME_PREFIX, define HAVE_GETEXECPATH if your platform supports
+# the getexecpath() function.
+#
# When using RUNTIME_PREFIX, define HAVE_BSD_KERN_PROC_SYSCTL if your platform
# supports the KERN_PROC BSD sysctl function.
#
@@ -2356,6 +2359,10 @@ endif
ifdef RUNTIME_PREFIX
+ ifdef HAVE_GETEXECPATH
+ BASIC_CFLAGS += -DHAVE_GETEXECPATH
+ endif
+
ifdef HAVE_BSD_KERN_PROC_SYSCTL
BASIC_CFLAGS += -DHAVE_BSD_KERN_PROC_SYSCTL
endif
diff --git a/config.mak.uname b/config.mak.uname
index e28870434d..270aff1772 100644
--- a/config.mak.uname
+++ b/config.mak.uname
@@ -343,6 +343,9 @@ ifeq ($(uname_S),OpenBSD)
CSPRNG_METHOD = arc4random
FREAD_READS_DIRECTORIES = UnfortunatelyYes
FILENO_IS_A_MACRO = UnfortunatelyYes
+ ifeq ($(shell test "`expr "$(uname_R)" : '\([0-9][0-9]*\)\.'`" -ge 8 && echo 1),1)
+ HAVE_GETEXECPATH = YesPlease
+ endif
endif
ifeq ($(uname_S),MirBSD)
NO_STRCASESTR = YesPlease
diff --git a/exec-cmd.c b/exec-cmd.c
index 507e67d528..5251da4229 100644
--- a/exec-cmd.c
+++ b/exec-cmd.c
@@ -129,6 +129,26 @@ static int git_get_exec_path_bsd_sysctl(struct strbuf *buf)
}
#endif /* HAVE_BSD_KERN_PROC_SYSCTL */
+#ifdef HAVE_GETEXECPATH
+/*
+ * Resolves the executable path using getexecpath(3).
+ *
+ * Returns 0 on success, -1 on failure.
+ */
+static int git_get_exec_path_getexecpath(struct strbuf *buf)
+{
+ char path[PATH_MAX];
+ if (getexecpath(path, sizeof(path)) == 0) {
+ trace_printf(
+ "trace: resolved executable path from getexecpath: %s\n",
+ path);
+ strbuf_addstr(buf, path);
+ return 0;
+ }
+ return -1;
+}
+#endif /* HAVE_GETEXECPATH */
+
#ifdef HAVE_NS_GET_EXECUTABLE_PATH
/*
* 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)
* after the first successful method.
*/
if (
+#ifdef HAVE_GETEXECPATH
+ git_get_exec_path_getexecpath(buf) &&
+#endif /* HAVE_GETEXECPATH */
+
#ifdef HAVE_BSD_KERN_PROC_SYSCTL
git_get_exec_path_bsd_sysctl(buf) &&
#endif /* HAVE_BSD_KERN_PROC_SYSCTL */
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] exec_cmd: RUNTIME_PREFIX on OpenBSD systems
2026-09-17 3:40 [PATCH] exec_cmd: RUNTIME_PREFIX on OpenBSD systems Brad Smith
@ 2026-09-17 13:45 ` Junio C Hamano
2026-09-21 2:10 ` Brad Smith
0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2026-09-17 13:45 UTC (permalink / raw)
To: Brad Smith; +Cc: git
Brad Smith <brad@comstyle.com> writes:
> Enable Git to resolve its own binary location using getexecpath().
That may not be incorrect information per-se, but lacks critical
bits. Natural initial questions that come to my mind are...
Why would one want to use getexecpath() over whatever OpenBSD
ports of Git have been using happily? Is the old way being
removed? Is the new way being more accurate? In what
situations does the difference matter? Is everybody on OpenBSD
able to use this new function? Do only certain, and/or
presumably later, verions of OpenBSD have it? How widely is it
available? How long has it been available?
Your proposed commit log messages do not answer any of these
questions, but it should. The title can also use a bit of tweak to
identify which versions of OpenBSD this patch is relevant.
> Signed-off-by: Brad Smith <brad@comstyle.com>
> ---
> Makefile | 7 +++++++
> config.mak.uname | 3 +++
> exec-cmd.c | 24 ++++++++++++++++++++++++
> 3 files changed, 34 insertions(+)
>
> diff --git a/Makefile b/Makefile
> index d4b775953d..9e3d37b5b4 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -378,6 +378,9 @@ include shared.mak
> # Perl scripts to use a modified entry point header allowing them to resolve
> # support files at runtime.
> #
> +# When using RUNTIME_PREFIX, define HAVE_GETEXECPATH if your platform supports
> +# the getexecpath() function.
> +#
> # When using RUNTIME_PREFIX, define HAVE_BSD_KERN_PROC_SYSCTL if your platform
> # supports the KERN_PROC BSD sysctl function.
> #
> @@ -2356,6 +2359,10 @@ endif
>
> ifdef RUNTIME_PREFIX
>
> + ifdef HAVE_GETEXECPATH
> + BASIC_CFLAGS += -DHAVE_GETEXECPATH
> + endif
> +
> ifdef HAVE_BSD_KERN_PROC_SYSCTL
> BASIC_CFLAGS += -DHAVE_BSD_KERN_PROC_SYSCTL
> endif
> diff --git a/config.mak.uname b/config.mak.uname
> index e28870434d..270aff1772 100644
> --- a/config.mak.uname
> +++ b/config.mak.uname
> @@ -343,6 +343,9 @@ ifeq ($(uname_S),OpenBSD)
> CSPRNG_METHOD = arc4random
> FREAD_READS_DIRECTORIES = UnfortunatelyYes
> FILENO_IS_A_MACRO = UnfortunatelyYes
> + ifeq ($(shell test "`expr "$(uname_R)" : '\([0-9][0-9]*\)\.'`" -ge 8 && echo 1),1)
> + HAVE_GETEXECPATH = YesPlease
> + endif
> endif
> ifeq ($(uname_S),MirBSD)
> NO_STRCASESTR = YesPlease
> diff --git a/exec-cmd.c b/exec-cmd.c
> index 507e67d528..5251da4229 100644
> --- a/exec-cmd.c
> +++ b/exec-cmd.c
> @@ -129,6 +129,26 @@ static int git_get_exec_path_bsd_sysctl(struct strbuf *buf)
> }
> #endif /* HAVE_BSD_KERN_PROC_SYSCTL */
>
> +#ifdef HAVE_GETEXECPATH
> +/*
> + * Resolves the executable path using getexecpath(3).
> + *
> + * Returns 0 on success, -1 on failure.
> + */
> +static int git_get_exec_path_getexecpath(struct strbuf *buf)
> +{
> + char path[PATH_MAX];
> + if (getexecpath(path, sizeof(path)) == 0) {
> + trace_printf(
> + "trace: resolved executable path from getexecpath: %s\n",
> + path);
> + strbuf_addstr(buf, path);
> + return 0;
> + }
> + return -1;
> +}
> +#endif /* HAVE_GETEXECPATH */
> +
> #ifdef HAVE_NS_GET_EXECUTABLE_PATH
> /*
> * 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)
> * after the first successful method.
> */
> if (
> +#ifdef HAVE_GETEXECPATH
> + git_get_exec_path_getexecpath(buf) &&
> +#endif /* HAVE_GETEXECPATH */
> +
> #ifdef HAVE_BSD_KERN_PROC_SYSCTL
> git_get_exec_path_bsd_sysctl(buf) &&
> #endif /* HAVE_BSD_KERN_PROC_SYSCTL */
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] exec_cmd: RUNTIME_PREFIX on OpenBSD systems
2026-09-17 13:45 ` Junio C Hamano
@ 2026-09-21 2:10 ` Brad Smith
2026-09-21 16:57 ` Junio C Hamano
0 siblings, 1 reply; 7+ messages in thread
From: Brad Smith @ 2026-09-21 2:10 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
On 2026-09-17 9:45 a.m., Junio C Hamano wrote:
> Brad Smith <brad@comstyle.com> writes:
>
>> Enable Git to resolve its own binary location using getexecpath().
> That may not be incorrect information per-se, but lacks critical
> bits. Natural initial questions that come to my mind are...
>
> Why would one want to use getexecpath() over whatever OpenBSD
> ports of Git have been using happily? Is the old way being
> removed? Is the new way being more accurate? In what
> situations does the difference matter? Is everybody on OpenBSD
> able to use this new function? Do only certain, and/or
> presumably later, verions of OpenBSD have it? How widely is it
> available? How long has it been available?
It's a long awaited API for such functionality on OpenBSD. Otherwise there
hasn't really been a means of doing so and one which has been using happily.
The proper API I would say is one which works and is more accurate. One
which works the same everywhere where as the pile of hacks has different
results and not happily either.
The API is new. The config.mak.uname check looks for 8.0 and newer.
> Your proposed commit log messages do not answer any of these
> questions, but it should. The title can also use a bit of tweak to
> identify which versions of OpenBSD this patch is relevant.
>
>> Signed-off-by: Brad Smith <brad@comstyle.com>
>> ---
>> Makefile | 7 +++++++
>> config.mak.uname | 3 +++
>> exec-cmd.c | 24 ++++++++++++++++++++++++
>> 3 files changed, 34 insertions(+)
>>
>> diff --git a/Makefile b/Makefile
>> index d4b775953d..9e3d37b5b4 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -378,6 +378,9 @@ include shared.mak
>> # Perl scripts to use a modified entry point header allowing them to resolve
>> # support files at runtime.
>> #
>> +# When using RUNTIME_PREFIX, define HAVE_GETEXECPATH if your platform supports
>> +# the getexecpath() function.
>> +#
>> # When using RUNTIME_PREFIX, define HAVE_BSD_KERN_PROC_SYSCTL if your platform
>> # supports the KERN_PROC BSD sysctl function.
>> #
>> @@ -2356,6 +2359,10 @@ endif
>>
>> ifdef RUNTIME_PREFIX
>>
>> + ifdef HAVE_GETEXECPATH
>> + BASIC_CFLAGS += -DHAVE_GETEXECPATH
>> + endif
>> +
>> ifdef HAVE_BSD_KERN_PROC_SYSCTL
>> BASIC_CFLAGS += -DHAVE_BSD_KERN_PROC_SYSCTL
>> endif
>> diff --git a/config.mak.uname b/config.mak.uname
>> index e28870434d..270aff1772 100644
>> --- a/config.mak.uname
>> +++ b/config.mak.uname
>> @@ -343,6 +343,9 @@ ifeq ($(uname_S),OpenBSD)
>> CSPRNG_METHOD = arc4random
>> FREAD_READS_DIRECTORIES = UnfortunatelyYes
>> FILENO_IS_A_MACRO = UnfortunatelyYes
>> + ifeq ($(shell test "`expr "$(uname_R)" : '\([0-9][0-9]*\)\.'`" -ge 8 && echo 1),1)
>> + HAVE_GETEXECPATH = YesPlease
>> + endif
>> endif
>> ifeq ($(uname_S),MirBSD)
>> NO_STRCASESTR = YesPlease
>> diff --git a/exec-cmd.c b/exec-cmd.c
>> index 507e67d528..5251da4229 100644
>> --- a/exec-cmd.c
>> +++ b/exec-cmd.c
>> @@ -129,6 +129,26 @@ static int git_get_exec_path_bsd_sysctl(struct strbuf *buf)
>> }
>> #endif /* HAVE_BSD_KERN_PROC_SYSCTL */
>>
>> +#ifdef HAVE_GETEXECPATH
>> +/*
>> + * Resolves the executable path using getexecpath(3).
>> + *
>> + * Returns 0 on success, -1 on failure.
>> + */
>> +static int git_get_exec_path_getexecpath(struct strbuf *buf)
>> +{
>> + char path[PATH_MAX];
>> + if (getexecpath(path, sizeof(path)) == 0) {
>> + trace_printf(
>> + "trace: resolved executable path from getexecpath: %s\n",
>> + path);
>> + strbuf_addstr(buf, path);
>> + return 0;
>> + }
>> + return -1;
>> +}
>> +#endif /* HAVE_GETEXECPATH */
>> +
>> #ifdef HAVE_NS_GET_EXECUTABLE_PATH
>> /*
>> * 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)
>> * after the first successful method.
>> */
>> if (
>> +#ifdef HAVE_GETEXECPATH
>> + git_get_exec_path_getexecpath(buf) &&
>> +#endif /* HAVE_GETEXECPATH */
>> +
>> #ifdef HAVE_BSD_KERN_PROC_SYSCTL
>> git_get_exec_path_bsd_sysctl(buf) &&
>> #endif /* HAVE_BSD_KERN_PROC_SYSCTL */
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] exec_cmd: RUNTIME_PREFIX on OpenBSD systems
[not found] <1789994808-30642-mlmmj-3f9f948b@vger.kernel.org>
@ 2026-09-21 13:00 ` Chris Torek
2026-09-21 16:43 ` Johannes Sixt
0 siblings, 1 reply; 7+ messages in thread
From: Chris Torek @ 2026-09-21 13:00 UTC (permalink / raw)
To: Git List, brad
[Ugh, somehow plain text mode got turned off, re-sending]
On Wed, Sep 16, 2026 at 8:41 PM Brad Smith <brad@comstyle.com> wrote:
>
> @@ -209,6 +229,10 @@ static int git_get_exec_path(struct strbuf *buf, const char *argv0)
> * after the first successful method.
> */
> if (
> +#ifdef HAVE_GETEXECPATH
> + git_get_exec_path_getexecpath(buf) &&
> +#endif /* HAVE_GETEXECPATH */
> +
> #ifdef HAVE_BSD_KERN_PROC_SYSCTL
> git_get_exec_path_bsd_sysctl(buf) &&
> #endif /* HAVE_BSD_KERN_PROC_SYSCTL */
> --
> 2.55.0
Sort of a minor nit, but given this code construct, there should probably be
instructions saying to define only one of these.
Chris
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] exec_cmd: RUNTIME_PREFIX on OpenBSD systems
2026-09-21 13:00 ` Chris Torek
@ 2026-09-21 16:43 ` Johannes Sixt
2026-09-22 1:17 ` Chris Torek
0 siblings, 1 reply; 7+ messages in thread
From: Johannes Sixt @ 2026-09-21 16:43 UTC (permalink / raw)
To: Chris Torek; +Cc: Git List, brad
Am 21.09.26 um 15:00 schrieb Chris Torek:
> [Ugh, somehow plain text mode got turned off, re-sending]
>
> On Wed, Sep 16, 2026 at 8:41 PM Brad Smith <brad@comstyle.com> wrote:
>>
>> @@ -209,6 +229,10 @@ static int git_get_exec_path(struct strbuf *buf, const char *argv0)
>> * after the first successful method.
>> */
>> if (
>> +#ifdef HAVE_GETEXECPATH
>> + git_get_exec_path_getexecpath(buf) &&
>> +#endif /* HAVE_GETEXECPATH */
>> +
>> #ifdef HAVE_BSD_KERN_PROC_SYSCTL
>> git_get_exec_path_bsd_sysctl(buf) &&
>> #endif /* HAVE_BSD_KERN_PROC_SYSCTL */
>> --
>> 2.55.0
>
> Sort of a minor nit, but given this code construct, there should probably be
> instructions saying to define only one of these.
This caught me too. But notice that the calls are chained by && so that
the first successful call determines the outcome.
-- Hannes
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] exec_cmd: RUNTIME_PREFIX on OpenBSD systems
2026-09-21 2:10 ` Brad Smith
@ 2026-09-21 16:57 ` Junio C Hamano
0 siblings, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2026-09-21 16:57 UTC (permalink / raw)
To: Brad Smith; +Cc: git
Brad Smith <brad@comstyle.com> writes:
> On 2026-09-17 9:45 a.m., Junio C Hamano wrote:
>> Brad Smith <brad@comstyle.com> writes:
>>
>>> Enable Git to resolve its own binary location using getexecpath().
>> That may not be incorrect information per-se, but lacks critical
>> bits. Natural initial questions that come to my mind are...
>>
>> Why would one want to use getexecpath() over whatever OpenBSD
>> ports of Git have been using happily? Is the old way being
>> removed? Is the new way being more accurate? In what
>> situations does the difference matter? Is everybody on OpenBSD
>> able to use this new function? Do only certain, and/or
>> presumably later, verions of OpenBSD have it? How widely is it
>> available? How long has it been available?
>
> It's a long awaited API for such functionality on OpenBSD. Otherwise there
> hasn't really been a means of doing so and one which has been using happily.
> The proper API I would say is one which works and is more accurate. One
> which works the same everywhere where as the pile of hacks has different
> results and not happily either.
>
> The API is new. The config.mak.uname check looks for 8.0 and newer.
OK, all of the above were missing from the proposed log message that
should be placed when v2 patch is prepared. They've happily been
using argv[0] as an approximate (which may be OK as long as we do
not lie to ourselves but not as nice), and now they are going to
have a proper syscall for the information, finally. You would also
need to answer the last few questions I asked in the proposed log
message of v2, but I thought 8.0 is not yet released?
Thanks.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] exec_cmd: RUNTIME_PREFIX on OpenBSD systems
2026-09-21 16:43 ` Johannes Sixt
@ 2026-09-22 1:17 ` Chris Torek
0 siblings, 0 replies; 7+ messages in thread
From: Chris Torek @ 2026-09-22 1:17 UTC (permalink / raw)
To: Johannes Sixt; +Cc: Git List, brad
On Mon, Sep 21, 2026 at 9:43 AM Johannes Sixt <j6t@kdbg.org> wrote:
[re the multiple get exec path call sequence]
> This caught me too. But notice that the calls are chained by && so that
> the first successful call determines the outcome.
I noticed the &&'s but I somehow thought that successful
return was nonzero instead of zero.
(It didn't help when gmail went a little wonky on me,
either, hence the accidental rejected HTML email)
Chris
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-09-22 1:18 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-17 3:40 [PATCH] exec_cmd: RUNTIME_PREFIX on OpenBSD systems Brad Smith
2026-09-17 13:45 ` Junio C Hamano
2026-09-21 2:10 ` Brad Smith
2026-09-21 16:57 ` Junio C Hamano
[not found] <1789994808-30642-mlmmj-3f9f948b@vger.kernel.org>
2026-09-21 13:00 ` Chris Torek
2026-09-21 16:43 ` Johannes Sixt
2026-09-22 1:17 ` Chris Torek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox