diff mbox series

exec_cmd: RUNTIME_PREFIX on z/OS systems

Message ID pull.1769.git.git.1724334732249.gitgitgadget@gmail.com (mailing list archive)
State Accepted
Commit 987bbcd088fc6274e21b4fac36e58a66c4ded460
Headers show
Series exec_cmd: RUNTIME_PREFIX on z/OS systems | expand

Commit Message

Haritha D Aug. 22, 2024, 1:52 p.m. UTC
From: D Harithamma <harithamma.d@ibm.com>

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>
---
    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.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1769%2FHarithaIBM%2FexecmdFix-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1769/HarithaIBM/execmdFix-v1
Pull-Request: https://github.com/git/git/pull/1769

 Makefile         |  8 ++++++++
 config.mak.uname |  1 +
 exec-cmd.c       | 23 +++++++++++++++++++++++
 3 files changed, 32 insertions(+)


base-commit: 3a7362eb9fad0c4838f5cfaa95ed3c51a4c18d93

Comments

Junio C Hamano Aug. 22, 2024, 3:58 p.m. UTC | #1
"Haritha  via GitGitGadget" <gitgitgadget@gmail.com> writes:

>  Makefile         |  8 ++++++++
>  config.mak.uname |  1 +
>  exec-cmd.c       | 23 +++++++++++++++++++++++
>  3 files changed, 32 insertions(+)
>
> diff --git a/Makefile b/Makefile
> index a87e18b317d..bdc68234823 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -385,6 +385,10 @@ include shared.mak
>  # supports calling _NSGetExecutablePath to retrieve the path of the running
>  # executable.
>  #
> +# When using RUNTIME_PREFIX, define HAVE_ZOS_GET_EXECUTABLE_PATH if your platform
> +# supports calling __getprogramdir and getprogname to retrieve the path of the
> +# running executable.
> +#
>  # When using RUNTIME_PREFIX, define HAVE_WPGMPTR if your platform offers
>  # the global variable _wpgmptr containing the absolute path of the current
>  # executable (this is the case on Windows).

It is a bit puzzling why this new thing is not added after the last
existing one in the same family of "When using RUNTIME_PREFIX".  Our
usual convention to order things that have no inherent logical order
among them is either to add the new one at the end or order them
alphabetically.  This comment applies to the other additions to an
existing list (e.g. cascade of git_get_exec_$SYSTEM() calls in
git_get_exec_path() function).

In any case, we should reorganize this section a bit to make it more
obvious that the options from HAVE_BSD_KERN_PROC_SYSCTL to
HAVE_WPGMPTR are the ones that affect how RUNTIME_PREFIX finds the
program location, but that is outside the scope of this topic.

The remainder of the patch looked perfectly in line with the
existing practice (except for where the new thing is added, which I
already mentioned); I do not do zos so I'll have to take your word
for the implementation of git_get_exec_path_zos(), though ;-)

The following shows how I would fix what I found annoying while
studying the existing code to prepare this review.  None of it
should be part of this topic (even though it could become a
preliminary clean-up step if we wanted to), but since I wrote it
already, I'll record it here on the list as #leftoverbits.

Thanks.

 Makefile   | 26 ++++++++++++++------------
 exec-cmd.c | 20 +++++++++-----------
 2 files changed, 23 insertions(+), 23 deletions(-)

diff --git c/Makefile w/Makefile
index 41dfa0bad2..910aec0973 100644
--- c/Makefile
+++ w/Makefile
@@ -373,21 +373,23 @@ 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_BSD_KERN_PROC_SYSCTL if your platform
-# supports the KERN_PROC BSD sysctl function.
+# When using RUNTIME_PREFIX:
 #
-# When using RUNTIME_PREFIX, define PROCFS_EXECUTABLE_PATH if your platform
-# mounts a "procfs" filesystem capable of resolving the path of the current
-# executable. If defined, this must be the canonical path for the "procfs"
-# current executable path.
+# - define HAVE_BSD_KERN_PROC_SYSCTL if your platform supports the
+#   KERN_PROC BSD sysctl function.
 #
-# When using RUNTIME_PREFIX, define HAVE_NS_GET_EXECUTABLE_PATH if your platform
-# supports calling _NSGetExecutablePath to retrieve the path of the running
-# executable.
+# - define PROCFS_EXECUTABLE_PATH if your platform mounts a "procfs"
+#   filesystem capable of resolving the path of the current
+#   executable. If defined, this must be the canonical path for the
+#   "procfs" current executable path.
 #
-# When using RUNTIME_PREFIX, define HAVE_WPGMPTR if your platform offers
-# the global variable _wpgmptr containing the absolute path of the current
-# executable (this is the case on Windows).
+# - define HAVE_NS_GET_EXECUTABLE_PATH if your platform supports
+#   calling _NSGetExecutablePath to retrieve the path of the running
+#   executable.
+#
+# - define HAVE_WPGMPTR if your platform offers the global variable
+#   _wpgmptr containing the absolute path of the current executable
+#   (this is the case on Windows).
 #
 # INSTALL_STRIP can be set to "-s" to strip binaries during installation,
 # if your $(INSTALL) command supports the option.
diff --git c/exec-cmd.c w/exec-cmd.c
index 909777f61f..54bc7ed304 100644
--- c/exec-cmd.c
+++ w/exec-cmd.c
@@ -100,6 +100,8 @@ static int git_get_exec_path_procfs(struct strbuf *buf)
 	}
 	return -1;
 }
+#else
+# define git_get_exec_path_procfs(ignore) 1
 #endif /* PROCFS_EXECUTABLE_PATH */
 
 #ifdef HAVE_BSD_KERN_PROC_SYSCTL
@@ -127,6 +129,8 @@ static int git_get_exec_path_bsd_sysctl(struct strbuf *buf)
 	}
 	return -1;
 }
+#else
+# define git_get_exec_path_bsd_sysctl(ignore) 1
 #endif /* HAVE_BSD_KERN_PROC_SYSCTL */
 
 #ifdef HAVE_NS_GET_EXECUTABLE_PATH
@@ -148,6 +152,8 @@ static int git_get_exec_path_darwin(struct strbuf *buf)
 	}
 	return -1;
 }
+#else
+# define git_get_exec_path_darwin(ignore) 1
 #endif /* HAVE_NS_GET_EXECUTABLE_PATH */
 
 #ifdef HAVE_WPGMPTR
@@ -166,6 +172,8 @@ static int git_get_exec_path_wpgmptr(struct strbuf *buf)
 	buf->len += len;
 	return 0;
 }
+#else
+# define git_get_exec_path_wpgmptr(ignore) 1
 #endif /* HAVE_WPGMPTR */
 
 /*
@@ -190,22 +198,12 @@ static int git_get_exec_path(struct strbuf *buf, const char *argv0)
 	 * after the first successful method.
 	 */
 	if (
-#ifdef HAVE_BSD_KERN_PROC_SYSCTL
 		git_get_exec_path_bsd_sysctl(buf) &&
-#endif /* HAVE_BSD_KERN_PROC_SYSCTL */
-
-#ifdef HAVE_NS_GET_EXECUTABLE_PATH
 		git_get_exec_path_darwin(buf) &&
-#endif /* HAVE_NS_GET_EXECUTABLE_PATH */
-
-#ifdef PROCFS_EXECUTABLE_PATH
 		git_get_exec_path_procfs(buf) &&
-#endif /* PROCFS_EXECUTABLE_PATH */
-
-#ifdef HAVE_WPGMPTR
 		git_get_exec_path_wpgmptr(buf) &&
-#endif /* HAVE_WPGMPTR */
 
+		/* fallback -- must be at the end */
 		git_get_exec_path_from_argv0(buf, argv0)) {
 		return -1;
 	}
Junio C Hamano Aug. 23, 2024, 4:57 p.m. UTC | #2
Junio C Hamano <gitster@pobox.com> writes:

> The following shows how I would fix what I found annoying while
> studying the existing code to prepare this review.  None of it
> should be part of this topic (even though it could become a
> preliminary clean-up step if we wanted to), but since I wrote it
> already, I'll record it here on the list as #leftoverbits.
>
> Thanks.

I'll take your patch as-is and merge it down to 'next'.

Once the dust settles from this topic, I'll see if we want to do
further clean-ups (the "how-about" patch below, possibly also
reorder them alphabetically) so for now, I'd leave #leftoverbits
mark here.


>  Makefile   | 26 ++++++++++++++------------
>  exec-cmd.c | 20 +++++++++-----------
>  2 files changed, 23 insertions(+), 23 deletions(-)
>
> diff --git c/Makefile w/Makefile
> index 41dfa0bad2..910aec0973 100644
> --- c/Makefile
> +++ w/Makefile
> @@ -373,21 +373,23 @@ 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_BSD_KERN_PROC_SYSCTL if your platform
> -# supports the KERN_PROC BSD sysctl function.
> +# When using RUNTIME_PREFIX:
>  #
> -# When using RUNTIME_PREFIX, define PROCFS_EXECUTABLE_PATH if your platform
> -# mounts a "procfs" filesystem capable of resolving the path of the current
> -# executable. If defined, this must be the canonical path for the "procfs"
> -# current executable path.
> +# - define HAVE_BSD_KERN_PROC_SYSCTL if your platform supports the
> +#   KERN_PROC BSD sysctl function.
>  #
> -# When using RUNTIME_PREFIX, define HAVE_NS_GET_EXECUTABLE_PATH if your platform
> -# supports calling _NSGetExecutablePath to retrieve the path of the running
> -# executable.
> +# - define PROCFS_EXECUTABLE_PATH if your platform mounts a "procfs"
> +#   filesystem capable of resolving the path of the current
> +#   executable. If defined, this must be the canonical path for the
> +#   "procfs" current executable path.
>  #
> -# When using RUNTIME_PREFIX, define HAVE_WPGMPTR if your platform offers
> -# the global variable _wpgmptr containing the absolute path of the current
> -# executable (this is the case on Windows).
> +# - define HAVE_NS_GET_EXECUTABLE_PATH if your platform supports
> +#   calling _NSGetExecutablePath to retrieve the path of the running
> +#   executable.
> +#
> +# - define HAVE_WPGMPTR if your platform offers the global variable
> +#   _wpgmptr containing the absolute path of the current executable
> +#   (this is the case on Windows).
>  #
>  # INSTALL_STRIP can be set to "-s" to strip binaries during installation,
>  # if your $(INSTALL) command supports the option.
> diff --git c/exec-cmd.c w/exec-cmd.c
> index 909777f61f..54bc7ed304 100644
> --- c/exec-cmd.c
> +++ w/exec-cmd.c
> @@ -100,6 +100,8 @@ static int git_get_exec_path_procfs(struct strbuf *buf)
>  	}
>  	return -1;
>  }
> +#else
> +# define git_get_exec_path_procfs(ignore) 1
>  #endif /* PROCFS_EXECUTABLE_PATH */
>  
>  #ifdef HAVE_BSD_KERN_PROC_SYSCTL
> @@ -127,6 +129,8 @@ static int git_get_exec_path_bsd_sysctl(struct strbuf *buf)
>  	}
>  	return -1;
>  }
> +#else
> +# define git_get_exec_path_bsd_sysctl(ignore) 1
>  #endif /* HAVE_BSD_KERN_PROC_SYSCTL */
>  
>  #ifdef HAVE_NS_GET_EXECUTABLE_PATH
> @@ -148,6 +152,8 @@ static int git_get_exec_path_darwin(struct strbuf *buf)
>  	}
>  	return -1;
>  }
> +#else
> +# define git_get_exec_path_darwin(ignore) 1
>  #endif /* HAVE_NS_GET_EXECUTABLE_PATH */
>  
>  #ifdef HAVE_WPGMPTR
> @@ -166,6 +172,8 @@ static int git_get_exec_path_wpgmptr(struct strbuf *buf)
>  	buf->len += len;
>  	return 0;
>  }
> +#else
> +# define git_get_exec_path_wpgmptr(ignore) 1
>  #endif /* HAVE_WPGMPTR */
>  
>  /*
> @@ -190,22 +198,12 @@ static int git_get_exec_path(struct strbuf *buf, const char *argv0)
>  	 * after the first successful method.
>  	 */
>  	if (
> -#ifdef HAVE_BSD_KERN_PROC_SYSCTL
>  		git_get_exec_path_bsd_sysctl(buf) &&
> -#endif /* HAVE_BSD_KERN_PROC_SYSCTL */
> -
> -#ifdef HAVE_NS_GET_EXECUTABLE_PATH
>  		git_get_exec_path_darwin(buf) &&
> -#endif /* HAVE_NS_GET_EXECUTABLE_PATH */
> -
> -#ifdef PROCFS_EXECUTABLE_PATH
>  		git_get_exec_path_procfs(buf) &&
> -#endif /* PROCFS_EXECUTABLE_PATH */
> -
> -#ifdef HAVE_WPGMPTR
>  		git_get_exec_path_wpgmptr(buf) &&
> -#endif /* HAVE_WPGMPTR */
>  
> +		/* fallback -- must be at the end */
>  		git_get_exec_path_from_argv0(buf, argv0)) {
>  		return -1;
>  	}
Haritha D Aug. 27, 2024, 6:18 a.m. UTC | #3
Hi Junio,

I was away for a few days and, therefore, couldn’t respond sooner. Thank you for reviewing and accepting the changes.

Best regards,
Haritha

On 23/08/24, 10:28 PM, "Junio C Hamano" <gitster@pobox.com <mailto:gitster@pobox.com>> wrote:


Junio C Hamano <gitster@pobox.com <mailto:gitster@pobox.com>> writes:


> The following shows how I would fix what I found annoying while
> studying the existing code to prepare this review. None of it
> should be part of this topic (even though it could become a
> preliminary clean-up step if we wanted to), but since I wrote it
> already, I'll record it here on the list as #leftoverbits.
>
> Thanks.


I'll take your patch as-is and merge it down to 'next'.


Once the dust settles from this topic, I'll see if we want to do
further clean-ups (the "how-about" patch below, possibly also
reorder them alphabetically) so for now, I'd leave #leftoverbits
mark here.




> Makefile | 26 ++++++++++++++------------
> exec-cmd.c | 20 +++++++++-----------
> 2 files changed, 23 insertions(+), 23 deletions(-)
>
> diff --git c/Makefile w/Makefile
> index 41dfa0bad2..910aec0973 100644
> --- c/Makefile
> +++ w/Makefile
> @@ -373,21 +373,23 @@ 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_BSD_KERN_PROC_SYSCTL if your platform
> -# supports the KERN_PROC BSD sysctl function.
> +# When using RUNTIME_PREFIX:
> #
> -# When using RUNTIME_PREFIX, define PROCFS_EXECUTABLE_PATH if your platform
> -# mounts a "procfs" filesystem capable of resolving the path of the current
> -# executable. If defined, this must be the canonical path for the "procfs"
> -# current executable path.
> +# - define HAVE_BSD_KERN_PROC_SYSCTL if your platform supports the
> +# KERN_PROC BSD sysctl function.
> #
> -# When using RUNTIME_PREFIX, define HAVE_NS_GET_EXECUTABLE_PATH if your platform
> -# supports calling _NSGetExecutablePath to retrieve the path of the running
> -# executable.
> +# - define PROCFS_EXECUTABLE_PATH if your platform mounts a "procfs"
> +# filesystem capable of resolving the path of the current
> +# executable. If defined, this must be the canonical path for the
> +# "procfs" current executable path.
> #
> -# When using RUNTIME_PREFIX, define HAVE_WPGMPTR if your platform offers
> -# the global variable _wpgmptr containing the absolute path of the current
> -# executable (this is the case on Windows).
> +# - define HAVE_NS_GET_EXECUTABLE_PATH if your platform supports
> +# calling _NSGetExecutablePath to retrieve the path of the running
> +# executable.
> +#
> +# - define HAVE_WPGMPTR if your platform offers the global variable
> +# _wpgmptr containing the absolute path of the current executable
> +# (this is the case on Windows).
> #
> # INSTALL_STRIP can be set to "-s" to strip binaries during installation,
> # if your $(INSTALL) command supports the option.
> diff --git c/exec-cmd.c w/exec-cmd.c
> index 909777f61f..54bc7ed304 100644
> --- c/exec-cmd.c
> +++ w/exec-cmd.c
> @@ -100,6 +100,8 @@ static int git_get_exec_path_procfs(struct strbuf *buf)
> }
> return -1;
> }
> +#else
> +# define git_get_exec_path_procfs(ignore) 1
> #endif /* PROCFS_EXECUTABLE_PATH */
> 
> #ifdef HAVE_BSD_KERN_PROC_SYSCTL
> @@ -127,6 +129,8 @@ static int git_get_exec_path_bsd_sysctl(struct strbuf *buf)
> }
> return -1;
> }
> +#else
> +# define git_get_exec_path_bsd_sysctl(ignore) 1
> #endif /* HAVE_BSD_KERN_PROC_SYSCTL */
> 
> #ifdef HAVE_NS_GET_EXECUTABLE_PATH
> @@ -148,6 +152,8 @@ static int git_get_exec_path_darwin(struct strbuf *buf)
> }
> return -1;
> }
> +#else
> +# define git_get_exec_path_darwin(ignore) 1
> #endif /* HAVE_NS_GET_EXECUTABLE_PATH */
> 
> #ifdef HAVE_WPGMPTR
> @@ -166,6 +172,8 @@ static int git_get_exec_path_wpgmptr(struct strbuf *buf)
> buf->len += len;
> return 0;
> }
> +#else
> +# define git_get_exec_path_wpgmptr(ignore) 1
> #endif /* HAVE_WPGMPTR */
> 
> /*
> @@ -190,22 +198,12 @@ static int git_get_exec_path(struct strbuf *buf, const char *argv0)
> * after the first successful method.
> */
> if (
> -#ifdef HAVE_BSD_KERN_PROC_SYSCTL
> git_get_exec_path_bsd_sysctl(buf) &&
> -#endif /* HAVE_BSD_KERN_PROC_SYSCTL */
> -
> -#ifdef HAVE_NS_GET_EXECUTABLE_PATH
> git_get_exec_path_darwin(buf) &&
> -#endif /* HAVE_NS_GET_EXECUTABLE_PATH */
> -
> -#ifdef PROCFS_EXECUTABLE_PATH
> git_get_exec_path_procfs(buf) &&
> -#endif /* PROCFS_EXECUTABLE_PATH */
> -
> -#ifdef HAVE_WPGMPTR
> git_get_exec_path_wpgmptr(buf) &&
> -#endif /* HAVE_WPGMPTR */
> 
> + /* fallback -- must be at the end */
> git_get_exec_path_from_argv0(buf, argv0)) {
> return -1;
> }
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index a87e18b317d..bdc68234823 100644
--- a/Makefile
+++ b/Makefile
@@ -385,6 +385,10 @@  include shared.mak
 # supports calling _NSGetExecutablePath to retrieve the path of the running
 # executable.
 #
+# When using RUNTIME_PREFIX, define HAVE_ZOS_GET_EXECUTABLE_PATH if your platform
+# supports calling __getprogramdir and getprogname to retrieve the path of the
+# running executable.
+#
 # When using RUNTIME_PREFIX, define HAVE_WPGMPTR if your platform offers
 # the global variable _wpgmptr containing the absolute path of the current
 # executable (this is the case on Windows).
@@ -2155,6 +2159,10 @@  ifdef HAVE_NS_GET_EXECUTABLE_PATH
 	BASIC_CFLAGS += -DHAVE_NS_GET_EXECUTABLE_PATH
 endif
 
+ifdef HAVE_ZOS_GET_EXECUTABLE_PATH
+        BASIC_CFLAGS += -DHAVE_ZOS_GET_EXECUTABLE_PATH
+endif
+
 ifdef HAVE_WPGMPTR
 	BASIC_CFLAGS += -DHAVE_WPGMPTR
 endif
diff --git a/config.mak.uname b/config.mak.uname
index aa0fd26bd53..904bcf35987 100644
--- a/config.mak.uname
+++ b/config.mak.uname
@@ -648,6 +648,7 @@  ifeq ($(uname_S),OS/390)
 	NO_GECOS_IN_PWENT = YesPlease
 	HAVE_STRINGS_H = YesPlease
 	NEEDS_MODE_TRANSLATION = YesPlease
+	HAVE_ZOS_GET_EXECUTABLE_PATH = YesPlease
 endif
 ifeq ($(uname_S),MINGW)
         ifeq ($(shell expr "$(uname_R)" : '1\.'),2)
diff --git a/exec-cmd.c b/exec-cmd.c
index 909777f61f4..507e67d528b 100644
--- a/exec-cmd.c
+++ b/exec-cmd.c
@@ -150,6 +150,25 @@  static int git_get_exec_path_darwin(struct strbuf *buf)
 }
 #endif /* HAVE_NS_GET_EXECUTABLE_PATH */
 
+#ifdef HAVE_ZOS_GET_EXECUTABLE_PATH
+/*
+ * Resolves the executable path from current program's directory and name.
+ *
+ * Returns 0 on success, -1 on failure.
+ */
+static int git_get_exec_path_zos(struct strbuf *buf)
+{
+	char *dir = __getprogramdir();
+	char *exe = getprogname();
+	if (dir && exe) {
+		strbuf_addf(buf, "%s/%s", dir, exe);
+		return 0;
+	}
+	return -1;
+}
+
+#endif /* HAVE_ZOS_GET_EXECUTABLE_PATH */
+
 #ifdef HAVE_WPGMPTR
 /*
  * 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)
 		git_get_exec_path_wpgmptr(buf) &&
 #endif /* HAVE_WPGMPTR */
 
+#ifdef HAVE_ZOS_GET_EXECUTABLE_PATH
+		git_get_exec_path_zos(buf) &&
+#endif /*HAVE_ZOS_GET_EXECUTABLE_PATH */
+
 		git_get_exec_path_from_argv0(buf, argv0)) {
 		return -1;
 	}