exec_cmd: RUNTIME_PREFIX on z/OS systems

Enable Git to resolve its own binary location using __getprogramdir and getprogname. Since /proc is not a mandatory filesystem on z/OS, we cannot rely on the git_get_exec_path_procfs method to determine Git's executable path. To address this, we have implemented git_get_exec_path_zos, which resolves the executable path by extracting it from the current program's directory and filename. Signed-off-by: D Harithamma <harithamma.d@ibm.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

D Harithamma committed Aug 22, 2024 at 13:52 UTC 987bbcd088fc6274e21b4fac36e58a66c4ded460
3 files changed +32
Makefile
+8
@@ -385,6 +385,10 @@ include shared.mak
385 # supports calling _NSGetExecutablePath to retrieve the path of the running
386 # executable.
387 #
388 +# When using RUNTIME_PREFIX, define HAVE_ZOS_GET_EXECUTABLE_PATH if your platform
389 +# supports calling __getprogramdir and getprogname to retrieve the path of the
390 +# running executable.
391 +#
392 # When using RUNTIME_PREFIX, define HAVE_WPGMPTR if your platform offers
393 # the global variable _wpgmptr containing the absolute path of the current
394 # executable (this is the case on Windows).
@@ -2155,6 +2159,10 @@ ifdef HAVE_NS_GET_EXECUTABLE_PATH
2159 BASIC_CFLAGS += -DHAVE_NS_GET_EXECUTABLE_PATH
2160 endif
2161
2162 +ifdef HAVE_ZOS_GET_EXECUTABLE_PATH
2163 + BASIC_CFLAGS += -DHAVE_ZOS_GET_EXECUTABLE_PATH
2164 +endif
2165 +
2166 ifdef HAVE_WPGMPTR
2167 BASIC_CFLAGS += -DHAVE_WPGMPTR
2168 endif
config.mak.uname
+1
@@ -648,6 +648,7 @@ ifeq ($(uname_S),OS/390)
648 NO_GECOS_IN_PWENT = YesPlease
649 HAVE_STRINGS_H = YesPlease
650 NEEDS_MODE_TRANSLATION = YesPlease
651 + HAVE_ZOS_GET_EXECUTABLE_PATH = YesPlease
652 endif
653 ifeq ($(uname_S),MINGW)
654 ifeq ($(shell expr "$(uname_R)" : '1\.'),2)
exec-cmd.c
+23
@@ -150,6 +150,25 @@ static int git_get_exec_path_darwin(struct strbuf *buf)
150 }
151 #endif /* HAVE_NS_GET_EXECUTABLE_PATH */
152
153 +#ifdef HAVE_ZOS_GET_EXECUTABLE_PATH
154 +/*
155 + * Resolves the executable path from current program's directory and name.
156 + *
157 + * Returns 0 on success, -1 on failure.
158 + */
159 +static int git_get_exec_path_zos(struct strbuf *buf)
160 +{
161 + char *dir = __getprogramdir();
162 + char *exe = getprogname();
163 + if (dir && exe) {
164 + strbuf_addf(buf, "%s/%s", dir, exe);
165 + return 0;
166 + }
167 + return -1;
168 +}
169 +
170 +#endif /* HAVE_ZOS_GET_EXECUTABLE_PATH */
171 +
172 #ifdef HAVE_WPGMPTR
173 /*
174 * Resolves the executable path by using the global variable _wpgmptr.
@@ -206,6 +225,10 @@ static int git_get_exec_path(struct strbuf *buf, const char *argv0)
225 git_get_exec_path_wpgmptr(buf) &&
226 #endif /* HAVE_WPGMPTR */
227
228 +#ifdef HAVE_ZOS_GET_EXECUTABLE_PATH
229 + git_get_exec_path_zos(buf) &&
230 +#endif /*HAVE_ZOS_GET_EXECUTABLE_PATH */
231 +
232 git_get_exec_path_from_argv0(buf, argv0)) {
233 return -1;
234 }