Skip to content

Commit 226c0dd

Browse files
danjacquesgitster
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]>
1 parent 07d90ea commit 226c0dd

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
@@ -448,6 +448,18 @@ all::
448448
# can be moved to arbitrary filesystem locations. RUNTIME_PREFIX also causes
449449
# Perl scripts to use a modified entry point header allowing them to resolve
450450
# support files at runtime.
451+
#
452+
# When using RUNTIME_PREFIX, define HAVE_BSD_KERN_PROC_SYSCTL if your platform
453+
# supports the KERN_PROC BSD sysctl function.
454+
#
455+
# When using RUNTIME_PREFIX, define PROCFS_EXECUTABLE_PATH if your platform
456+
# mounts a "procfs" filesystem capable of resolving the path of the current
457+
# executable. If defined, this must be the canonical path for the "procfs"
458+
# current executable path.
459+
#
460+
# When using RUNTIME_PREFIX, define HAVE_NS_GET_EXECUTABLE_PATH if your platform
461+
# supports calling _NSGetExecutablePath to retrieve the path of the running
462+
# executable.
451463

452464
GIT-VERSION-FILE: FORCE
453465
@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -1674,10 +1686,23 @@ ifdef HAVE_BSD_SYSCTL
16741686
BASIC_CFLAGS += -DHAVE_BSD_SYSCTL
16751687
endif
16761688

1689+
ifdef HAVE_BSD_KERN_PROC_SYSCTL
1690+
BASIC_CFLAGS += -DHAVE_BSD_KERN_PROC_SYSCTL
1691+
endif
1692+
16771693
ifdef HAVE_GETDELIM
16781694
BASIC_CFLAGS += -DHAVE_GETDELIM
16791695
endif
16801696

1697+
ifneq ($(PROCFS_EXECUTABLE_PATH),)
1698+
procfs_executable_path_SQ = $(subst ','\'',$(PROCFS_EXECUTABLE_PATH))
1699+
BASIC_CFLAGS += '-DPROCFS_EXECUTABLE_PATH="$(procfs_executable_path_SQ)"'
1700+
endif
1701+
1702+
ifdef HAVE_NS_GET_EXECUTABLE_PATH
1703+
BASIC_CFLAGS += -DHAVE_NS_GET_EXECUTABLE_PATH
1704+
endif
1705+
16811706
ifeq ($(TCLTK_PATH),)
16821707
NO_TCLTK = NoThanks
16831708
endif
@@ -2226,6 +2251,7 @@ endif
22262251
exec_cmd.sp exec_cmd.s exec_cmd.o: GIT-PREFIX
22272252
exec_cmd.sp exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
22282253
'-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \
2254+
'-DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \
22292255
'-DBINDIR="$(bindir_relative_SQ)"' \
22302256
'-DPREFIX="$(prefix_SQ)"'
22312257

@@ -2243,7 +2269,7 @@ attr.sp attr.s attr.o: EXTRA_CPPFLAGS = \
22432269

22442270
gettext.sp gettext.s gettext.o: GIT-PREFIX
22452271
gettext.sp gettext.s gettext.o: EXTRA_CPPFLAGS = \
2246-
-DGIT_LOCALE_PATH='"$(localedir_SQ)"'
2272+
-DGIT_LOCALE_PATH='"$(localedir_relative_SQ)"'
22472273

22482274
http-push.sp http.sp http-walker.sp remote-curl.sp imap-send.sp: SPARSE_FLAGS += \
22492275
-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,14 +32,14 @@ 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
initialize_the_repository();
3840

3941
attr_start();
4042

41-
git_extract_argv0_path(argv[0]);
42-
4343
restore_sigpipe_to_default();
4444

4545
return cmd_main(argc, argv);

config.mak.uname

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ ifeq ($(uname_S),Linux)
3737
HAVE_GETDELIM = YesPlease
3838
SANE_TEXT_GREP=-a
3939
FREAD_READS_DIRECTORIES = UnfortunatelyYes
40+
PROCFS_EXECUTABLE_PATH = /proc/self/exe
4041
endif
4142
ifeq ($(uname_S),GNU/kFreeBSD)
4243
HAVE_ALLOCA_H = YesPlease
@@ -111,6 +112,7 @@ ifeq ($(uname_S),Darwin)
111112
BASIC_CFLAGS += -DPROTECT_HFS_DEFAULT=1
112113
HAVE_BSD_SYSCTL = YesPlease
113114
FREAD_READS_DIRECTORIES = UnfortunatelyYes
115+
HAVE_NS_GET_EXECUTABLE_PATH = YesPlease
114116
endif
115117
ifeq ($(uname_S),SunOS)
116118
NEEDS_SOCKET = YesPlease
@@ -205,6 +207,7 @@ ifeq ($(uname_S),FreeBSD)
205207
HAVE_PATHS_H = YesPlease
206208
GMTIME_UNRELIABLE_ERRORS = UnfortunatelyYes
207209
HAVE_BSD_SYSCTL = YesPlease
210+
HAVE_BSD_KERN_PROC_SYSCTL = YesPlease
208211
PAGER_ENV = LESS=FRX LV=-c MORE=FRX
209212
FREAD_READS_DIRECTORIES = UnfortunatelyYes
210213
endif
@@ -217,6 +220,8 @@ ifeq ($(uname_S),OpenBSD)
217220
BASIC_LDFLAGS += -L/usr/local/lib
218221
HAVE_PATHS_H = YesPlease
219222
HAVE_BSD_SYSCTL = YesPlease
223+
HAVE_BSD_KERN_PROC_SYSCTL = YesPlease
224+
PROCFS_EXECUTABLE_PATH = /proc/curproc/file
220225
endif
221226
ifeq ($(uname_S),MirBSD)
222227
NO_STRCASESTR = YesPlease
@@ -235,6 +240,8 @@ ifeq ($(uname_S),NetBSD)
235240
USE_ST_TIMESPEC = YesPlease
236241
HAVE_PATHS_H = YesPlease
237242
HAVE_BSD_SYSCTL = YesPlease
243+
HAVE_BSD_KERN_PROC_SYSCTL = YesPlease
244+
PROCFS_EXECUTABLE_PATH = /proc/curproc/exe
238245
endif
239246
ifeq ($(uname_S),AIX)
240247
DEFAULT_PAGER = more

0 commit comments

Comments
 (0)