]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
- fixed the output of cpp warnings with the cpp trick
authorAndrew Tridgell <tridge@samba.org>
Sun, 12 May 2002 09:51:36 +0000 (11:51 +0200)
committerAndrew Tridgell <tridge@samba.org>
Sun, 12 May 2002 09:51:36 +0000 (11:51 +0200)
- handle close() failure on out of space on NFS

ccache.c
ccache.h
util.c

index 49668dd14b01fe255a9b9eb620408626e8ddd00f..14908c9cbd1a8f615ab4c63ceeef15698f5e9692 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -49,6 +49,9 @@ static char *i_extension;
 /* the name of the temporary pre-processor file */
 static char *i_tmpfile;
 
+/* the name of the cpp stderr file */
+static char *cpp_stderr;
+
 /* the name of the statistics file */
 char *stats_file = NULL;
 
@@ -86,6 +89,14 @@ static void failed(void)
                free(i_tmpfile);
                i_tmpfile = NULL;
        }
+
+       /* delete the cpp stderr file if necessary */
+       if (cpp_stderr) {
+               unlink(cpp_stderr);
+               free(cpp_stderr);
+               cpp_stderr = NULL;
+       }
+
        execv(orig_args->argv[0], orig_args->argv);
        cc_log("execv returned (%s)!\n", strerror(errno));
        perror(orig_args->argv[0]);
@@ -134,7 +145,19 @@ static void to_cache(ARGS *args)
                if (fd != -1) {
                        if (strcmp(output_file, "/dev/null") == 0 ||
                            rename(tmp_hashname, output_file) == 0 || errno == ENOENT) {
-                               /* we can use a quick method of getting the failed output */
+                               if (cpp_stderr) {
+                                       /* we might have some stderr from cpp */
+                                       int fd2 = open(cpp_stderr, O_RDONLY);
+                                       if (fd2 != -1) {
+                                               copy_fd(fd2, 2);
+                                               close(fd2);
+                                               unlink(cpp_stderr);
+                                               cpp_stderr = NULL;
+                                       }
+                               }
+
+                               /* we can use a quick method of
+                                   getting the failed output */
                                copy_fd(fd, 2);
                                close(fd);
                                unlink(tmp_stderr);
@@ -244,7 +267,7 @@ static void find_hash(ARGS *args)
        /* now the run */
        x_asprintf(&path_stdout, "%s/tmp.stdout.%d.%s", cache_dir, getpid(), 
                   i_extension);
-       x_asprintf(&path_stderr, "%s/tmp.stderr.%d", cache_dir, getpid());
+       x_asprintf(&path_stderr, "%s/tmp.cpp_stderr.%d", cache_dir, getpid());
 
        args_add(args, "-E");
        args_add(args, input_file);
@@ -278,8 +301,16 @@ static void find_hash(ARGS *args)
        hash_file(path_stderr);
 
        i_tmpfile = path_stdout;
-       unlink(path_stderr);
-       free(path_stderr);
+
+       if (!getenv("CCACHE_CPP2")) {
+               /* if we are using the CPP trick then we need to remember this stderr
+                  data and output it just before the main stderr from the compiler
+                  pass */
+               cpp_stderr = path_stderr;
+       } else {        
+               unlink(path_stderr);
+               free(path_stderr);
+       }
 
        /* we use a N level subdir for the cache path to reduce the impact
           on filesystems which are slow for large directories
@@ -312,7 +343,7 @@ static void find_hash(ARGS *args)
    otherwise it returns */
 static void from_cache(int first)
 {
-       int fd_stderr;
+       int fd_stderr, fd_cpp_stderr;
        char *stderr_file;
        int ret;
        struct stat st;
@@ -377,6 +408,16 @@ static void from_cache(int first)
                i_tmpfile = NULL;
        }
 
+       /* send the cpp stderr, if applicable */
+       fd_cpp_stderr = open(cpp_stderr, O_RDONLY);
+       if (fd_cpp_stderr != -1) {
+               copy_fd(fd_cpp_stderr, 2);
+               close(fd_cpp_stderr);
+               unlink(cpp_stderr);
+               free(cpp_stderr);
+               cpp_stderr = NULL;
+       }
+
        /* send the stderr */
        copy_fd(fd_stderr, 2);
        close(fd_stderr);
@@ -699,7 +740,7 @@ static void ccache(int argc, char *argv[])
        /* if we can return from cache at this point then do */
        from_cache(1);
        
-       /* run real compiler, semding output to cache */
+       /* run real compiler, sending output to cache */
        to_cache(stripped_args);
 
        /* return from cache */
index f7b4f80e9762c70b56ac583a09178d16aaf3e180..5206f46dda73450053de7c174749c1d44d9405eb 100644 (file)
--- a/ccache.h
+++ b/ccache.h
@@ -1,4 +1,4 @@
-#define CCACHE_VERSION "1.8"
+#define CCACHE_VERSION "1.9"
 
 #include "config.h"
 
diff --git a/util.c b/util.c
index 5066f25a6f5b0ab1de18977671964e9b8acd5f99..c42a792878b7fccc2faf40659315f08210b7a877 100644 (file)
--- a/util.c
+++ b/util.c
@@ -83,8 +83,14 @@ int copy_file(const char *src, const char *dest)
                }
        }
 
-       close(fd2);
        close(fd1);
+
+       /* the close can fail on NFS if out of space */
+       if (close(fd2) == -1) {
+               unlink(dest);
+               return -1;
+       }
+
        return 0;
 }