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>
Chris Webb committed
Apr 13, 2010 at 10:07 UTC
cb6a22c0760f30ff8050b508b9fabbe13ffba1ae
3 files changed
+21
-1
Makefile
+13
@@ -31,6 +31,9 @@ all::
31
# Define EXPATDIR=/foo/bar if your expat header and library files are in
32
# /foo/bar/include and /foo/bar/lib directories.
33
#
34
+# Define HAVE_PATHS_H if you have paths.h and want to use the default PATH
35
+# it specifies.
36
+#
37
# Define NO_D_INO_IN_DIRENT if you don't have d_ino in your struct dirent.
38
#
39
# Define NO_D_TYPE_IN_DIRENT if your platform defines DT_UNKNOWN but lacks
@@ -702,10 +705,12 @@ EXTLIBS =
705
ifeq ($(uname_S),Linux)
706
NO_STRLCPY = YesPlease
707
NO_MKSTEMPS = YesPlease
708
+ HAVE_PATHS_H = YesPlease
709
endif
710
ifeq ($(uname_S),GNU/kFreeBSD)
711
NO_STRLCPY = YesPlease
712
NO_MKSTEMPS = YesPlease
713
+ HAVE_PATHS_H = YesPlease
714
endif
715
ifeq ($(uname_S),UnixWare)
716
CC = cc
@@ -832,6 +837,7 @@ ifeq ($(uname_S),FreeBSD)
837
NO_STRTOUMAX = YesPlease
838
endif
839
PYTHON_PATH = /usr/local/bin/python
840
+ HAVE_PATHS_H = YesPlease
841
endif
842
ifeq ($(uname_S),OpenBSD)
843
NO_STRCASESTR = YesPlease
@@ -840,6 +846,7 @@ ifeq ($(uname_S),OpenBSD)
846
NEEDS_LIBICONV = YesPlease
847
BASIC_CFLAGS += -I/usr/local/include
848
BASIC_LDFLAGS += -L/usr/local/lib
849
+ HAVE_PATHS_H = YesPlease
850
endif
851
ifeq ($(uname_S),NetBSD)
852
ifeq ($(shell expr "$(uname_R)" : '[01]\.'),2)
@@ -849,6 +856,7 @@ ifeq ($(uname_S),NetBSD)
856
BASIC_LDFLAGS += -L/usr/pkg/lib $(CC_LD_DYNPATH)/usr/pkg/lib
857
USE_ST_TIMESPEC = YesPlease
858
NO_MKSTEMPS = YesPlease
859
+ HAVE_PATHS_H = YesPlease
860
endif
861
ifeq ($(uname_S),AIX)
862
NO_STRCASESTR=YesPlease
@@ -869,6 +877,7 @@ ifeq ($(uname_S),GNU)
877
# GNU/Hurd
878
NO_STRLCPY=YesPlease
879
NO_MKSTEMPS = YesPlease
880
+ HAVE_PATHS_H = YesPlease
881
endif
882
ifeq ($(uname_S),IRIX)
883
NO_SETENV = YesPlease
@@ -1309,6 +1318,10 @@ else
1318
LIB_OBJS += thread-utils.o
1319
endif
1320
1321
+ifdef HAVE_PATHS_H
1322
+ BASIC_CFLAGS += -DHAVE_PATHS_H
1323
+endif
1324
+
1325
ifdef DIR_HAS_BSD_GROUP_SEMANTICS
1326
COMPAT_CFLAGS += -DDIR_HAS_BSD_GROUP_SEMANTICS
1327
endif
exec_cmd.c
+1
-1
@@ -107,7 +107,7 @@ void setup_path(void)
107
if (old_path)
108
strbuf_addstr(&new_path, old_path);
109
else
110
- strbuf_addstr(&new_path, "/usr/local/bin:/usr/bin:/bin");
110
+ strbuf_addstr(&new_path, _PATH_DEFPATH);
111
112
setenv("PATH", new_path.buf, 1);
113
git-compat-util.h
+7
@@ -163,6 +163,13 @@ extern char *gitbasename(char *);
163
#define PATH_SEP ':'
164
#endif
165
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
+
173
#ifndef STRIP_EXTENSION
174
#define STRIP_EXTENSION ""
175
#endif