[ccache] [patch] allow distcc errors to be uncached

Martin Pool mbp at samba.org
Tue Jul 22 17:13:54 EST 2003


This patch makes ccache export a duplicate of stderr that is not
cached, by storing its file descriptor in $UNCACHED_ERR_FD.   This
allows distcc to avoid having its error messages cached, which makes
sense because they are mostly 'transient' and only relate to the first
time a file is compiled.  

For example, with this patch applied

$ export DISTCC_HOSTS=asdkajsdkjasd 
$ ~/work/ccache/head/ccache distcc -c ./cases/hello.c -O2
distcc[28049] (dcc_connect_by_name) ERROR: failed to look up host "asdkajsdkjasd": Unknown host
distcc[28049] (dcc_build_somewhere) Warning: failed to distribute to asdkajsdkjasd, running locally instead
$ ~/work/ccache/head/ccache distcc -c ./cases/hello.c -O2

This avoids the potential of getting an error message referring to a
host that you think distcc shouldn't be using.

The last few distcc releases have been ready to support this.  Please
merge it.




--- ccache.c.~1.80.~	2003-07-14 11:05:31.000000000 +1000
+++ ccache.c	2003-07-22 17:08:32.000000000 +1000
@@ -871,6 +871,29 @@ static int ccache_main(int argc, char *a
 	return 0;
 }
 
+
+/* Make a copy of stderr that will not be cached, so things like
+ * distcc can send networking errors to it. */
+int setup_uncached_err(void)
+{
+        char *buf;
+        int uncached_fd;
+
+        uncached_fd = dup(2);
+        if (uncached_fd == -1) {
+                fatal("dup(2) failed");
+        }
+
+        /* leak a pointer to the environment */
+        x_asprintf(&buf, "UNCACHED_ERR_FD=%d", uncached_fd);
+
+        if (putenv(buf) == -1)
+                fatal("putenv failed");
+
+        return 0;
+}
+
+
 int main(int argc, char *argv[])
 {
 	cache_dir = getenv("CCACHE_DIR");
@@ -880,6 +903,8 @@ int main(int argc, char *argv[])
 
 	cache_logfile = getenv("CCACHE_LOGFILE");
 
+        setup_uncached_err();
+
 	/* check if we are being invoked as "ccache" */
 	if (strlen(argv[0]) >= strlen(MYNAME) &&
 	    strcmp(argv[0] + strlen(argv[0]) - strlen(MYNAME), MYNAME) == 0) {


-- 
Martin 



More information about the ccache mailing list