Skip to content

Commit a974ee5

Browse files
danjacquesdscho
authored andcommitted
exec_cmd: RUNTIME_PREFIX on some POSIX systems
Enable Git to resolve its own binary location using a variety of OS-specific and generic methods, including: - procfs via "/proc/self/exe" (Linux) - _NSGetExecutablePath (Darwin) - KERN_PROC_PATHNAME sysctl on BSDs. - argv0, if absolute (all, including Windows). This is used to enable RUNTIME_PREFIX support for non-Windows systems, notably Linux and Darwin. When configured with RUNTIME_PREFIX, Git will do a best-effort resolution of its executable path and automatically use this as its "exec_path" for relative helper and data lookups, unless explicitly overridden. Small incidental formatting cleanup of "exec_cmd.c". Signed-off-by: Dan Jacques <[email protected]> Thanks-to: Robbie Iannucci <[email protected]> Thanks-to: Junio C Hamano <[email protected]> Signed-off-by: Junio C Hamano <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 5ab215b commit a974ee5

File tree

9 files changed

+253
-39
lines changed

9 files changed

+253
-39
lines changed

Makefile

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,18 @@ all::
441441
# can be moved to arbitrary filesystem locations. RUNTIME_PREFIX also causes
442442
# Perl scripts to use a modified entry point header allowing them to resolve
443443
# support files at runtime.
444+
#
445+
# When using RUNTIME_PREFIX, define HAVE_BSD_KERN_PROC_SYSCTL if your platform
446+
# supports the KERN_PROC BSD sysctl function.
447+
#
448+
# When using RUNTIME_PREFIX, define PROCFS_EXECUTABLE_PATH if your platform
449+
# mounts a "procfs" filesystem capable of resolving the path of the current
450+
# executable. If defined, this must be the canonical path for the "procfs"
451+
# current executable path.
452+
#
453+
# When using RUNTIME_PREFIX, define HAVE_NS_GET_EXECUTABLE_PATH if your platform
454+
# supports calling _NSGetExecutablePath to retrieve the path of the running
455+
# executable.
444456

445457
GIT-VERSION-FILE: FORCE
446458
@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -1665,10 +1677,23 @@ ifdef HAVE_BSD_SYSCTL
16651677
BASIC_CFLAGS += -DHAVE_BSD_SYSCTL
16661678
endif
16671679

1680+
ifdef HAVE_BSD_KERN_PROC_SYSCTL
1681+
BASIC_CFLAGS += -DHAVE_BSD_KERN_PROC_SYSCTL
1682+
endif
1683+
16681684
ifdef HAVE_GETDELIM
16691685
BASIC_CFLAGS += -DHAVE_GETDELIM
16701686
endif
16711687

1688+
ifneq ($(PROCFS_EXECUTABLE_PATH),)
1689+
procfs_executable_path_SQ = $(subst ','\'',$(PROCFS_EXECUTABLE_PATH))
1690+
BASIC_CFLAGS += '-DPROCFS_EXECUTABLE_PATH="$(procfs_executable_path_SQ)"'
1691+
endif
1692+
1693+
ifdef HAVE_NS_GET_EXECUTABLE_PATH
1694+
BASIC_CFLAGS += -DHAVE_NS_GET_EXECUTABLE_PATH
1695+
endif
1696+
16721697
ifeq ($(TCLTK_PATH),)
16731698
NO_TCLTK = NoThanks
16741699
endif
@@ -2216,6 +2241,7 @@ endif
22162241
exec_cmd.sp exec_cmd.s exec_cmd.o: GIT-PREFIX
22172242
exec_cmd.sp exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
22182243
'-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \
2244+
'-DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \
22192245
'-DBINDIR="$(bindir_relative_SQ)"' \
22202246
'-DFALLBACK_RUNTIME_PREFIX="$(prefix_SQ)"'
22212247

@@ -2233,7 +2259,7 @@ attr.sp attr.s attr.o: EXTRA_CPPFLAGS = \
22332259

22342260
gettext.sp gettext.s gettext.o: GIT-PREFIX
22352261
gettext.sp gettext.s gettext.o: EXTRA_CPPFLAGS = \
2236-
-DGIT_LOCALE_PATH='"$(localedir_SQ)"'
2262+
-DGIT_LOCALE_PATH='"$(localedir_relative_SQ)"'
22372263

22382264
http-push.sp http.sp http-walker.sp remote-curl.sp imap-send.sp: SPARSE_FLAGS += \
22392265
-DCURL_DISABLE_TYPECHECK

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ static inline enum object_type object_type(unsigned int mode)
428428
#define GIT_ICASE_PATHSPECS_ENVIRONMENT "GIT_ICASE_PATHSPECS"
429429
#define GIT_QUARANTINE_ENVIRONMENT "GIT_QUARANTINE_PATH"
430430
#define GIT_OPTIONAL_LOCKS_ENVIRONMENT "GIT_OPTIONAL_LOCKS"
431+
#define GIT_TEXT_DOMAIN_DIR_ENVIRONMENT "GIT_TEXTDOMAINDIR"
431432

432433
/*
433434
* Environment variable used in handshaking the wire protocol.

common-main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ int main(int argc, const char **argv)
3232
*/
3333
sanitize_stdfds();
3434

35+
git_resolve_executable_dir(argv[0]);
36+
3537
git_setup_gettext();
3638

3739
attr_start();
3840

39-
git_extract_argv0_path(argv[0]);
40-
4141
restore_sigpipe_to_default();
4242

4343
return cmd_main(argc, argv);

config.mak.uname

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ ifeq ($(uname_S),Linux)
5656
HAVE_GETDELIM = YesPlease
5757
SANE_TEXT_GREP=-a
5858
FREAD_READS_DIRECTORIES = UnfortunatelyYes
59+
PROCFS_EXECUTABLE_PATH = /proc/self/exe
5960
endif
6061
ifeq ($(uname_S),GNU/kFreeBSD)
6162
HAVE_ALLOCA_H = YesPlease
@@ -130,6 +131,7 @@ ifeq ($(uname_S),Darwin)
130131
BASIC_CFLAGS += -DPROTECT_HFS_DEFAULT=1
131132
HAVE_BSD_SYSCTL = YesPlease
132133
FREAD_READS_DIRECTORIES = UnfortunatelyYes
134+
HAVE_NS_GET_EXECUTABLE_PATH = YesPlease
133135
endif
134136
ifeq ($(uname_S),SunOS)
135137
NEEDS_SOCKET = YesPlease
@@ -224,6 +226,7 @@ ifeq ($(uname_S),FreeBSD)
224226
HAVE_PATHS_H = YesPlease
225227
GMTIME_UNRELIABLE_ERRORS = UnfortunatelyYes
226228
HAVE_BSD_SYSCTL = YesPlease
229+
HAVE_BSD_KERN_PROC_SYSCTL = YesPlease
227230
PAGER_ENV = LESS=FRX LV=-c MORE=FRX
228231
FREAD_READS_DIRECTORIES = UnfortunatelyYes
229232
endif
@@ -236,6 +239,8 @@ ifeq ($(uname_S),OpenBSD)
236239
BASIC_LDFLAGS += -L/usr/local/lib
237240
HAVE_PATHS_H = YesPlease
238241
HAVE_BSD_SYSCTL = YesPlease
242+
HAVE_BSD_KERN_PROC_SYSCTL = YesPlease
243+
PROCFS_EXECUTABLE_PATH = /proc/curproc/file
239244
endif
240245
ifeq ($(uname_S),MirBSD)
241246
NO_STRCASESTR = YesPlease
@@ -254,6 +259,8 @@ ifeq ($(uname_S),NetBSD)
254259
USE_ST_TIMESPEC = YesPlease
255260
HAVE_PATHS_H = YesPlease
256261
HAVE_BSD_SYSCTL = YesPlease
262+
HAVE_BSD_KERN_PROC_SYSCTL = YesPlease
263+
PROCFS_EXECUTABLE_PATH = /proc/curproc/exe
257264
endif
258265
ifeq ($(uname_S),AIX)
259266
DEFAULT_PAGER = more

0 commit comments

Comments
 (0)