[ccache] patch: abs. filenames in CCACHE_PREFIX & CCACHE_CC

Davlet Panech davlet_panech at yahoo.ca
Sat Feb 28 00:07:58 GMT 2004


Hi,

Ccache doesn't allow absolute pathnames in CCACHE_PREFIX and CCACHE_CC. Is that
intentional? A patch follows.

Thanks,
D.



--- ccache-2.3/execute.c	2003-09-28 00:48:17.000000000 -0400
+++ ccache-2.3-new/execute.c	2004-02-27 18:49:59.000000000 -0500
@@ -66,6 +66,36 @@
 	return WEXITSTATUS(status);
 }
 
+static int is_executable(const char *fname, const char *exclude_name)
+{
+	struct stat st1, st2;
+	/* look for a normal executable file */
+	if (access(fname, X_OK) == 0 &&
+	    lstat(fname, &st1) == 0 &&
+	    stat(fname, &st2) == 0 &&
+	    S_ISREG(st2.st_mode)) {
+		/* if its a symlink then ensure it doesn't
+                   point at something called exclude_name */
+		if (S_ISLNK(st1.st_mode)) {
+			char *buf = x_realpath(fname);
+			if (buf) {
+				char *p = str_basename(buf);
+				if (strcmp(p, exclude_name) == 0) {
+					/* its a link to "ccache" ! */
+					free(p);
+					free(buf);
+					return 0;
+				}
+				free(buf);
+				free(p);
+			}
+		}
+
+		/* found it! */
+		return 1;
+	}
+	return 0;
+}
 
 /*
   find an executable by name in $PATH. Exclude any that are links to exclude_name 
@@ -74,7 +104,13 @@
 {
 	char *path;
 	char *tok;
-	struct stat st1, st2;
+	
+	if (strchr(name, '/')) {
+		if (is_executable(name, exclude_name)) {
+			return x_strdup(name);
+		}
+		return NULL;
+	}
 
 	path = getenv("CCACHE_PATH");
 	if (!path) {
@@ -92,34 +128,13 @@
 	for (tok=strtok(path,":"); tok; tok = strtok(NULL, ":")) {
 		char *fname;
 		x_asprintf(&fname, "%s/%s", tok, name);
-		/* look for a normal executable file */
-		if (access(fname, X_OK) == 0 &&
-		    lstat(fname, &st1) == 0 &&
-		    stat(fname, &st2) == 0 &&
-		    S_ISREG(st2.st_mode)) {
-			/* if its a symlink then ensure it doesn't
-                           point at something called exclude_name */
-			if (S_ISLNK(st1.st_mode)) {
-				char *buf = x_realpath(fname);
-				if (buf) {
-					char *p = str_basename(buf);
-					if (strcmp(p, exclude_name) == 0) {
-						/* its a link to "ccache" ! */
-						free(p);
-						free(buf);
-						continue;
-					}
-					free(buf);
-					free(p);
-				}
-			}
-
-			/* found it! */
+		if (is_executable(fname, exclude_name)) {
 			free(path);
 			return fname;
 		}
 		free(fname);
 	}
-
+	
+	free(path);
 	return NULL;
 }
--- ccache-2.3/ccache.c	2003-09-28 00:48:17.000000000 -0400
+++ ccache-2.3-new/ccache.c	2004-02-27 18:53:59.000000000 -0500
@@ -544,6 +544,7 @@
    same name that isn't a link to ourselves */
 static void find_compiler(int argc, char **argv)
 {
+	char *cc;
 	char *base;
 	char *path;
 
@@ -555,24 +556,26 @@
 	if (strcmp(base, MYNAME) == 0) {
 		args_remove_first(orig_args);
 		free(base);
-		if (strchr(argv[1],'/')) {
-			/* a full path was given */
-			return;
-		}
-		base = str_basename(argv[1]);
+		cc = x_strdup(argv[1]);
+	} else {
+		/* we are a link, look for another executable with the same
+		   basename */
+		cc = base;
 	}
 
 	/* support user override of the compiler */
 	if ((path=getenv("CCACHE_CC"))) {
-		base = strdup(path);
+		free(cc);
+		cc = strdup(path);
 	}
 
-	orig_args->argv[0] = find_executable(base, MYNAME);
+	free(orig_args->argv[0]);
+	orig_args->argv[0] = find_executable(cc, MYNAME);
 
 	/* can't find the compiler! */
 	if (!orig_args->argv[0]) {
 		stats_update(STATS_COMPILER);
-		perror(base);
+		perror(cc);
 		exit(1);
 	}
 }


______________________________________________________________________ 
Post your free ad now! http://personals.yahoo.ca


More information about the ccache mailing list