]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
- check that the compiler we find is executable (to cope with a
authorAndrew Tridgell <tridge@samba.org>
Tue, 26 Mar 2002 22:39:25 +0000 (23:39 +0100)
committerAndrew Tridgell <tridge@samba.org>
Tue, 26 Mar 2002 22:39:25 +0000 (23:39 +0100)
  directory called "gcc")
- make it work on non-Linux systems (though you do need CCACHE_PATH set)

ccache.c

index d0ed0193b3a408aa256a08c1bd2e06b3e184904f..d97f4f83fa952c91bc876ab0c07dcd1f2b1da575 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -223,17 +223,23 @@ static char *find_compiler(const char *argv0)
        char *path, *tok;
        struct stat st1, st2;
 
-       /* we compare size, device and inode */
-       if (stat("/proc/self/exe", &st1) != 0) {
-               cc_log("Can't stat ccache executable!?\n");
-               exit(1);
-       }
-
        p = strrchr(argv0, '/');
        if (p) {
-               base = p+1;
+               base = x_strdup(p+1);
        } else {
-               base = argv0;
+               base = x_strdup(argv0);
+       }
+
+       /* we compare size, device and inode. On non-Linux systems
+          we rely on CCACHE_PATH being set and end up just using the first 
+          executable we find in the path
+       */
+       if (stat("/proc/self/exe", &st1) != 0) {
+               if (!getenv("CCACHE_PATH")) {
+                       cc_log("You must set CCACHE_PATH\n");
+                       exit(1);
+               }
+               memset(&st1, 0, sizeof(st1));
        }
 
        path = getenv("CCACHE_PATH");
@@ -252,7 +258,10 @@ static char *find_compiler(const char *argv0)
        for (tok=strtok(path,":"); tok; tok = strtok(NULL, ":")) {
                char *fname;
                x_asprintf(&fname, "%s/%s", tok, base);
-               if (stat(fname, &st2) == 0) {
+               /* look for a normal executable file */
+               if (access(fname, X_OK) == 0 &&
+                   stat(fname, &st2) == 0 &&
+                   S_ISREG(st2.st_mode)) {
                        if (st1.st_size != st2.st_size ||
                            st1.st_dev != st2.st_dev ||
                            st1.st_ino != st2.st_ino) {