Skip to content

Commit cb6a22c

Browse files
arachsysgitster
authored andcommitted
exec_cmd.c: replace hard-coded path list with one from <paths.h>
The default executable path list used by exec_cmd.c is hard-coded to be "/usr/local/bin:/usr/bin:/bin". Use an appropriate value for the system from <paths.h> when available. Add HAVE_PATHS_H make variables and enable it on Linux, FreeBSD, NetBSD, OpenBSD and GNU where it is known to exist for now. Somebody else may want to do an autoconf support later. Signed-off-by: Chris Webb <chris@arachsys.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent adda3c3 commit cb6a22c

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ all::
3131
# Define EXPATDIR=/foo/bar if your expat header and library files are in
3232
# /foo/bar/include and /foo/bar/lib directories.
3333
#
34+
# Define HAVE_PATHS_H if you have paths.h and want to use the default PATH
35+
# it specifies.
36+
#
3437
# Define NO_D_INO_IN_DIRENT if you don't have d_ino in your struct dirent.
3538
#
3639
# Define NO_D_TYPE_IN_DIRENT if your platform defines DT_UNKNOWN but lacks
@@ -702,10 +705,12 @@ EXTLIBS =
702705
ifeq ($(uname_S),Linux)
703706
NO_STRLCPY = YesPlease
704707
NO_MKSTEMPS = YesPlease
708+
HAVE_PATHS_H = YesPlease
705709
endif
706710
ifeq ($(uname_S),GNU/kFreeBSD)
707711
NO_STRLCPY = YesPlease
708712
NO_MKSTEMPS = YesPlease
713+
HAVE_PATHS_H = YesPlease
709714
endif
710715
ifeq ($(uname_S),UnixWare)
711716
CC = cc
@@ -832,6 +837,7 @@ ifeq ($(uname_S),FreeBSD)
832837
NO_STRTOUMAX = YesPlease
833838
endif
834839
PYTHON_PATH = /usr/local/bin/python
840+
HAVE_PATHS_H = YesPlease
835841
endif
836842
ifeq ($(uname_S),OpenBSD)
837843
NO_STRCASESTR = YesPlease
@@ -840,6 +846,7 @@ ifeq ($(uname_S),OpenBSD)
840846
NEEDS_LIBICONV = YesPlease
841847
BASIC_CFLAGS += -I/usr/local/include
842848
BASIC_LDFLAGS += -L/usr/local/lib
849+
HAVE_PATHS_H = YesPlease
843850
endif
844851
ifeq ($(uname_S),NetBSD)
845852
ifeq ($(shell expr "$(uname_R)" : '[01]\.'),2)
@@ -849,6 +856,7 @@ ifeq ($(uname_S),NetBSD)
849856
BASIC_LDFLAGS += -L/usr/pkg/lib $(CC_LD_DYNPATH)/usr/pkg/lib
850857
USE_ST_TIMESPEC = YesPlease
851858
NO_MKSTEMPS = YesPlease
859+
HAVE_PATHS_H = YesPlease
852860
endif
853861
ifeq ($(uname_S),AIX)
854862
NO_STRCASESTR=YesPlease
@@ -869,6 +877,7 @@ ifeq ($(uname_S),GNU)
869877
# GNU/Hurd
870878
NO_STRLCPY=YesPlease
871879
NO_MKSTEMPS = YesPlease
880+
HAVE_PATHS_H = YesPlease
872881
endif
873882
ifeq ($(uname_S),IRIX)
874883
NO_SETENV = YesPlease
@@ -1309,6 +1318,10 @@ else
13091318
LIB_OBJS += thread-utils.o
13101319
endif
13111320

1321+
ifdef HAVE_PATHS_H
1322+
BASIC_CFLAGS += -DHAVE_PATHS_H
1323+
endif
1324+
13121325
ifdef DIR_HAS_BSD_GROUP_SEMANTICS
13131326
COMPAT_CFLAGS += -DDIR_HAS_BSD_GROUP_SEMANTICS
13141327
endif

exec_cmd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void setup_path(void)
107107
if (old_path)
108108
strbuf_addstr(&new_path, old_path);
109109
else
110-
strbuf_addstr(&new_path, "/usr/local/bin:/usr/bin:/bin");
110+
strbuf_addstr(&new_path, _PATH_DEFPATH);
111111

112112
setenv("PATH", new_path.buf, 1);
113113

git-compat-util.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ extern char *gitbasename(char *);
163163
#define PATH_SEP ':'
164164
#endif
165165

166+
#ifdef HAVE_PATHS_H
167+
#include <paths.h>
168+
#endif
169+
#ifndef _PATH_DEFPATH
170+
#define _PATH_DEFPATH "/usr/local/bin:/usr/bin:/bin"
171+
#endif
172+
166173
#ifndef STRIP_EXTENSION
167174
#define STRIP_EXTENSION ""
168175
#endif

0 commit comments

Comments
 (0)