Code

exec_cmd.c: replace hard-coded path list with one from <paths.h>
authorChris Webb <chris@arachsys.com>
Tue, 13 Apr 2010 09:07:13 +0000 (10:07 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 15 Apr 2010 19:07:51 +0000 (12:07 -0700)
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>
Makefile
exec_cmd.c
git-compat-util.h

index e57d9754e28f280cb3074094c800c97dbdb91d12..98ac6e1fed6c844a67ac0bb2aa7290fff295b995 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -31,6 +31,9 @@ all::
 # Define EXPATDIR=/foo/bar if your expat header and library files are in
 # /foo/bar/include and /foo/bar/lib directories.
 #
+# Define HAVE_PATHS_H if you have paths.h and want to use the default PATH
+# it specifies.
+#
 # Define NO_D_INO_IN_DIRENT if you don't have d_ino in your struct dirent.
 #
 # Define NO_D_TYPE_IN_DIRENT if your platform defines DT_UNKNOWN but lacks
@@ -702,10 +705,12 @@ EXTLIBS =
 ifeq ($(uname_S),Linux)
        NO_STRLCPY = YesPlease
        NO_MKSTEMPS = YesPlease
+       HAVE_PATHS_H = YesPlease
 endif
 ifeq ($(uname_S),GNU/kFreeBSD)
        NO_STRLCPY = YesPlease
        NO_MKSTEMPS = YesPlease
+       HAVE_PATHS_H = YesPlease
 endif
 ifeq ($(uname_S),UnixWare)
        CC = cc
@@ -832,6 +837,7 @@ ifeq ($(uname_S),FreeBSD)
                NO_STRTOUMAX = YesPlease
        endif
        PYTHON_PATH = /usr/local/bin/python
+       HAVE_PATHS_H = YesPlease
 endif
 ifeq ($(uname_S),OpenBSD)
        NO_STRCASESTR = YesPlease
@@ -840,6 +846,7 @@ ifeq ($(uname_S),OpenBSD)
        NEEDS_LIBICONV = YesPlease
        BASIC_CFLAGS += -I/usr/local/include
        BASIC_LDFLAGS += -L/usr/local/lib
+       HAVE_PATHS_H = YesPlease
 endif
 ifeq ($(uname_S),NetBSD)
        ifeq ($(shell expr "$(uname_R)" : '[01]\.'),2)
@@ -849,6 +856,7 @@ ifeq ($(uname_S),NetBSD)
        BASIC_LDFLAGS += -L/usr/pkg/lib $(CC_LD_DYNPATH)/usr/pkg/lib
        USE_ST_TIMESPEC = YesPlease
        NO_MKSTEMPS = YesPlease
+       HAVE_PATHS_H = YesPlease
 endif
 ifeq ($(uname_S),AIX)
        NO_STRCASESTR=YesPlease
@@ -869,6 +877,7 @@ ifeq ($(uname_S),GNU)
        # GNU/Hurd
        NO_STRLCPY=YesPlease
        NO_MKSTEMPS = YesPlease
+       HAVE_PATHS_H = YesPlease
 endif
 ifeq ($(uname_S),IRIX)
        NO_SETENV = YesPlease
@@ -1309,6 +1318,10 @@ else
        LIB_OBJS += thread-utils.o
 endif
 
+ifdef HAVE_PATHS_H
+       BASIC_CFLAGS += -DHAVE_PATHS_H
+endif
+
 ifdef DIR_HAS_BSD_GROUP_SEMANTICS
        COMPAT_CFLAGS += -DDIR_HAS_BSD_GROUP_SEMANTICS
 endif
index 408e4e55e1c58931444c772d35d23b505bf3e2ea..484d018e1975d15b61226e8b13cb932c5a141e72 100644 (file)
@@ -107,7 +107,7 @@ void setup_path(void)
        if (old_path)
                strbuf_addstr(&new_path, old_path);
        else
-               strbuf_addstr(&new_path, "/usr/local/bin:/usr/bin:/bin");
+               strbuf_addstr(&new_path, _PATH_DEFPATH);
 
        setenv("PATH", new_path.buf, 1);
 
index a3c45373669cd8482c04d5815862ed36a153572d..e215ce0dd9f19707cbec485e898ae829c6b3882e 100644 (file)
@@ -163,6 +163,13 @@ extern char *gitbasename(char *);
 #define PATH_SEP ':'
 #endif
 
+#ifdef HAVE_PATHS_H
+#include <paths.h>
+#endif
+#ifndef _PATH_DEFPATH
+#define _PATH_DEFPATH "/usr/local/bin:/usr/bin:/bin"
+#endif
+
 #ifndef STRIP_EXTENSION
 #define STRIP_EXTENSION ""
 #endif