Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 13 Feb 2012 20:59:20 +0000 (UTC)
From:      Dimitry Andric <dim@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r231612 - stable/9/usr.bin/rpcgen
Message-ID:  <201202132059.q1DKxKbP061669@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dim
Date: Mon Feb 13 20:59:20 2012
New Revision: 231612
URL: http://svn.freebsd.org/changeset/base/231612

Log:
  MFC r231079:
  
    Let rpcgen(1) support an environment variable RPCGEN_CPP to find the C
    preprocessor to run.  Previously, it always ran /usr/bin/cpp, unless you
    used the -Y option, and even then you could not set the basename.  It
    also attempted to run /usr/ccs/lib/cpp for SVR4 compatibility, but this
    is obsolete, and has been removed.
  
    Note that setting RPCGEN_CPP to a command with arguments is supported,
    though the command line parsing is simplistic.  However, setting it to
    e.g. "gcc46 -E" or "clang -E" will lead to problems, because both gcc
    and clang in -E mode will consider files with unknown extensions (such
    as .x) as object files, and attempt to link them.
  
    This could be worked around by also adding "-x c", but it is much safer
    to set RPCGEN_CPP to e.g. "cpp46" or "clang-cpp" instead.
  
  MFC r231080:
  
    Amend r231079 by properly shifting up the existing arguments in
    rpc_main.c's insarg() function.  I had forgotten to put this in my patch
    queue, sorry.
  
    Pointy hat to:	me
  
  MFC r231101:
  
    In usr.bin/rpcgen/rpc_main.c, use execvp(3) instead of execv(3), so
    rpcgen will search the current PATH for the preprocessor.  This makes it
    possible to run a preprocessor built during the cross-tools stage of
    buildworld.

Modified:
  stable/9/usr.bin/rpcgen/rpc_main.c
  stable/9/usr.bin/rpcgen/rpcgen.1
Directory Properties:
  stable/9/usr.bin/rpcgen/   (props changed)

Modified: stable/9/usr.bin/rpcgen/rpc_main.c
==============================================================================
--- stable/9/usr.bin/rpcgen/rpc_main.c	Mon Feb 13 19:52:18 2012	(r231611)
+++ stable/9/usr.bin/rpcgen/rpc_main.c	Mon Feb 13 20:59:20 2012	(r231612)
@@ -79,13 +79,8 @@ static void s_output(int, const char **,
 #define	EXTEND	1		/* alias for TRUE */
 #define	DONT_EXTEND	0		/* alias for FALSE */
 
-#define	SVR4_CPP "/usr/ccs/lib/cpp"
-#define SUNOS_CPP "/usr/bin/cpp"
-
-static int cppDefined = 0;	/* explicit path for C preprocessor */
-
 static const char *svcclosetime = "120";
-static const char *CPP = SVR4_CPP;
+static const char *CPP = NULL;
 static const char CPPFLAGS[] = "-C";
 static char pathbuf[MAXPATHLEN + 1];
 static const char *allv[] = {
@@ -101,7 +96,7 @@ static int allnc = sizeof (allnv)/sizeof
  * machinations for handling expanding argument list
  */
 static void addarg(const char *);	/* add another argument to the list */
-static void putarg(int, const char *);	/* put argument at specified location */
+static void insarg(int, const char *);	/* insert arg at specified location */
 static void clear_args(void);		/* clear argument list */
 static void checkfiles(const char *, const char *);
 					/* check if out file already exists */
@@ -109,7 +104,7 @@ static void checkfiles(const char *, con
 
 
 #define	ARGLISTLEN	20
-#define	FIXEDARGS	2
+#define	FIXEDARGS	0
 
 static char *arglist[ARGLISTLEN];
 static int argcount = FIXEDARGS;
@@ -292,24 +287,29 @@ clear_args(void)
 	argcount = FIXEDARGS;
 }
 
-/* make sure that a CPP exists */
+/* prepend C-preprocessor and flags before arguments */
 static void
-find_cpp(void)
+prepend_cpp(void)
 {
-	struct stat buf;
-
-	if (stat(CPP, &buf) < 0)  { /* SVR4 or explicit cpp does not exist */
-		if (cppDefined) {
-			warnx("cannot find C preprocessor: %s", CPP);
-			crash();
-		} else {	/* try the other one */
-			CPP = SUNOS_CPP;
-			if (stat(CPP, &buf) < 0) { /* can't find any cpp */
-				warnx("cannot find C preprocessor: %s", CPP);
-				crash();
-			}
+	int idx = 1;
+	const char *var;
+	char *dupvar, *s, *t;
+
+	if (CPP != NULL)
+		insarg(0, CPP);
+	else if ((var = getenv("RPCGEN_CPP")) == NULL)
+		insarg(0, "/usr/bin/cpp");
+	else {
+		/* Parse command line in a rudimentary way */
+		dupvar = xstrdup(var);
+		for (s = dupvar, idx = 0; (t = strsep(&s, " \t")) != NULL; ) {
+			if (t[0])
+				insarg(idx++, t);
 		}
+		free(dupvar);
 	}
+
+	insarg(idx, CPPFLAGS);
 }
 
 /*
@@ -324,9 +324,7 @@ open_input(const char *infile, const cha
 	(void) pipe(pd);
 	switch (childpid = fork()) {
 	case 0:
-		find_cpp();
-		putarg(0, CPP);
-		putarg(1, CPPFLAGS);
+		prepend_cpp();
 		addarg(define);
 		if (infile)
 			addarg(infile);
@@ -334,8 +332,8 @@ open_input(const char *infile, const cha
 		(void) close(1);
 		(void) dup2(pd[1], 1);
 		(void) close(pd[0]);
-		execv(arglist[0], arglist);
-		err(1, "execv");
+		execvp(arglist[0], arglist);
+		err(1, "execvp %s", arglist[0]);
 	case -1:
 		err(1, "fork");
 	}
@@ -938,18 +936,26 @@ addarg(const char *cp)
 
 }
 
+/*
+ * Insert an argument at the specified location
+ */
 static void
-putarg(int place, const char *cp)
+insarg(int place, const char *cp)
 {
-	if (place >= ARGLISTLEN) {
-		warnx("arglist coding error");
+	int i;
+
+	if (argcount >= ARGLISTLEN) {
+		warnx("too many defines");
 		crash();
 		/*NOTREACHED*/
 	}
-	if (cp != NULL)
-		arglist[place] = xstrdup(cp);
-	else
-		arglist[place] = NULL;
+
+	/* Move up existing arguments */
+	for (i = argcount - 1; i >= place; i--)
+		arglist[i + 1] = arglist[i];
+
+	arglist[place] = xstrdup(cp);
+	argcount++;
 }
 
 /*
@@ -1138,7 +1144,6 @@ parseargs(int argc, const char *argv[], 
 						return (0);
 					}
 					CPP = pathbuf;
-					cppDefined = 1;
 					goto nextarg;
 
 

Modified: stable/9/usr.bin/rpcgen/rpcgen.1
==============================================================================
--- stable/9/usr.bin/rpcgen/rpcgen.1	Mon Feb 13 19:52:18 2012	(r231611)
+++ stable/9/usr.bin/rpcgen/rpcgen.1	Mon Feb 13 20:59:20 2012	(r231612)
@@ -490,6 +490,11 @@ Give the name of the directory where
 .Nm
 will start looking for the C-preprocessor.
 .El
+.Sh ENVIRONMENT
+If the
+.Ev RPCGEN_CPP
+environment variable is set, its value is used as the command line of the
+C preprocessor to be run on the input file.
 .Sh EXAMPLES
 The following example:
 .Dl example% rpcgen -T prot.x



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201202132059.q1DKxKbP061669>