about summary refs log tree commit diff
path: root/sunrpc
diff options
context:
space:
mode:
Diffstat (limited to 'sunrpc')
-rw-r--r--sunrpc/Makefile4
-rw-r--r--sunrpc/rpc_main.c39
2 files changed, 34 insertions, 9 deletions
diff --git a/sunrpc/Makefile b/sunrpc/Makefile
index bde8cdc717..db5278ff5e 100644
--- a/sunrpc/Makefile
+++ b/sunrpc/Makefile
@@ -114,7 +114,9 @@ include ../Rules
 $(objpfx)rpcgen: $(addprefix $(objpfx),$(rpcgen-objs)) $(common-objpfx)libc.a
 	$(+link)
 
-rpcgen-cmd = $(built-program-cmd)
+# Tell rpcgen that it should unset LD_LIBRARY_PATH before executing the
+# preprocessor.
+rpcgen-cmd = $(built-program-cmd) -$$
 
 # The proper file name is longer than 14 chars, so we install it under
 # a shorter name.  But if the filesystem can handle it, we want to
diff --git a/sunrpc/rpc_main.c b/sunrpc/rpc_main.c
index ec990d1846..7d64e1b784 100644
--- a/sunrpc/rpc_main.c
+++ b/sunrpc/rpc_main.c
@@ -38,6 +38,7 @@ char main_rcsid[] =
  * rpc_main.c, Top level of the RPC protocol compiler.
  */
 
+#include <errno.h>
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
@@ -79,7 +80,7 @@ static const char *cmdname;
 static const char *svcclosetime = "120";
 static const char *CPP = SVR4_CPP;
 static char CPPFLAGS[] = "-C";
-static char pathbuf[FILENAME_MAX + 1];
+static char *pathbuf;
 static const char *allv[] = {
 	"rpcgen", "-s", "udp", "-s", "tcp",
 };
@@ -167,6 +168,10 @@ int tirpcflag = 0;       /* generating code for tirpc, by default */
 int tirpcflag = 1;       /* generating code for tirpc, by default */
 #endif
 
+#ifdef __GNU_LIBRARY__
+int building_libc = 0;	/* running as part of libc built process */
+#endif
+
 int
 main(int argc, const char *argv[])
 {
@@ -334,6 +339,13 @@ open_input(const char *infile, const char *define)
 	(void) pipe(pd);
 	switch (fork()) {
 	case 0:
+#ifdef __GNU_LIBRARY__
+		/* While building libc we don't want to use the libc from
+		   the build directory which may be incompatible with the
+		   installed dynamic linker.  */
+		if (building_libc)
+		  unsetenv ("LD_LIBRARY_PATH");
+#endif
 		find_cpp();
 		putarg(0, CPP);
 		putarg(1, CPPFLAGS);
@@ -939,7 +951,9 @@ parseargs(int argc, const char *argv[], struct commandline *cmd)
 					    */
 					tirpcflag = 1;
 					break;
-
+				case '$':
+					building_libc = 1;
+					break;
 #endif
 				case 'I':
 					inetdflag = 1;
@@ -998,12 +1012,21 @@ parseargs(int argc, const char *argv[], struct commandline *cmd)
 					if (++i == argc) {
 						return (0);
 					}
-					(void) strcpy(pathbuf, argv[i]);
-					(void) strcat(pathbuf, "/cpp");
-					CPP = pathbuf;
-					cppDefined = 1;
-					goto nextarg;
-
+					{
+						size_t len = strlen (argv[i]);
+						pathbuf = malloc (len + 5);
+						if (pathbuf == NULL) {
+							f_print(stderr, "%s\n",
+								strerror (errno));
+							crash();
+						}
+						stpcpy (stpcpy (pathbuf,
+								argv[i]),
+							"/cpp");
+						CPP = pathbuf;
+						cppDefined = 1;
+						goto nextarg;
+					}
 
 
 				default: