--- nfs-utils-1.3.0/utils/mountd/cache.c	2014-03-25 16:12:07.000000000 +0100
+++ src/utils/mountd/cache.c	2014-06-23 15:48:37.372872732 +0200
@@ -69,7 +69,7 @@
 int lbuflen = 0;
 extern int use_ipaddr;
 
-static void auth_unix_ip(FILE *f)
+static void auth_unix_ip(FILE *ifile, FILE *ofile)
 {
 	/* requests are
 	 *  class IP-ADDR
@@ -83,7 +83,7 @@
 	char ipaddr[INET6_ADDRSTRLEN + 1];
 	char *client = NULL;
 	struct addrinfo *tmp = NULL;
-	if (readline(fileno(f), &lbuf, &lbuflen) != 1)
+	if (readline(fileno(ifile), &lbuf, &lbuflen) != 1)
 		return;
 
 	xlog(D_CALL, "auth_unix_ip: inbuf '%s'", lbuf);
@@ -113,16 +113,16 @@
 			freeaddrinfo(ai);
 		}
 	}
-	qword_print(f, "nfsd");
-	qword_print(f, ipaddr);
-	qword_printtimefrom(f, DEFAULT_TTL);
+	qword_print(ofile, "nfsd");
+	qword_print(ofile, ipaddr);
+	qword_printtimefrom(ofile, DEFAULT_TTL);
 	if (use_ipaddr) {
 		memmove(ipaddr + 1, ipaddr, strlen(ipaddr) + 1);
 		ipaddr[0] = '$';
-		qword_print(f, ipaddr);
+		qword_print(ofile, ipaddr);
 	} else if (client)
-		qword_print(f, *client?client:"DEFAULT");
-	qword_eol(f);
+		qword_print(ofile, *client?client:"DEFAULT");
+	qword_eol(ofile);
 	xlog(D_CALL, "auth_unix_ip: client %p '%s'", client, client?client: "DEFAULT");
 
 	free(client);
@@ -130,7 +130,7 @@
 
 }
 
-static void auth_unix_gid(FILE *f)
+static void auth_unix_gid(FILE *ifile, FILE *ofile)
 {
 	/* Request are
 	 *  uid
@@ -156,7 +156,7 @@
 
 	ngroups = groups_len;
 
-	if (readline(fileno(f), &lbuf, &lbuflen) != 1)
+	if (readline(fileno(ifile), &lbuf, &lbuflen) != 1)
 		return;
 
 	cp = lbuf;
@@ -180,15 +180,15 @@
 			}
 		}
 	}
-	qword_printuint(f, uid);
-	qword_printtimefrom(f, DEFAULT_TTL);
+	qword_printuint(ofile, uid);
+	qword_printtimefrom(ofile, DEFAULT_TTL);
 	if (rv >= 0) {
-		qword_printuint(f, ngroups);
+		qword_printuint(ofile, ngroups);
 		for (i=0; i<ngroups; i++)
-			qword_printuint(f, groups[i]);
+			qword_printuint(ofile, groups[i]);
 	} else
-		qword_printuint(f, 0);
-	qword_eol(f);
+		qword_printuint(ofile, 0);
+	qword_eol(ofile);
 }
 
 #if USE_BLKID
@@ -579,7 +579,7 @@
 	return ret;
 }
 
-static void nfsd_fh(FILE *f)
+static void nfsd_fh(FILE *ifile, FILE *ofile)
 {
 	/* request are:
 	 *  domain fsidtype fsid
@@ -599,7 +599,7 @@
 	int i;
 	int dev_missing = 0;
 
-	if (readline(fileno(f), &lbuf, &lbuflen) != 1)
+	if (readline(fileno(ifile), &lbuf, &lbuflen) != 1)
 		return;
 
 	xlog(D_CALL, "nfsd_fh: inbuf '%s'", lbuf);
@@ -719,9 +719,9 @@
 		if (cache_export_ent(dom, found, found_path) < 0)
 			found = 0;
 
-	qword_print(f, dom);
-	qword_printint(f, fsidtype);
-	qword_printhex(f, fsid, fsidlen);
+	qword_print(ofile, dom);
+	qword_printint(ofile, fsidtype);
+	qword_printhex(ofile, fsid, fsidlen);
 	/* The fsid -> path lookup can be quite expensive as it
 	 * potentially stats and reads lots of devices, and some of those
 	 * might have spun-down.  The Answer is not likely to
@@ -730,10 +730,10 @@
 	 * timeout.  Maybe this should be configurable on the command
 	 * line.
 	 */
-	qword_printint(f, 0x7fffffff);
+	qword_printint(ofile, 0x7fffffff);
 	if (found)
-		qword_print(f, found_path);
-	qword_eol(f);
+		qword_print(ofile, found_path);
+	qword_eol(ofile);
  out:
 	if (found_path)
 		free(found_path);
@@ -1185,7 +1185,7 @@
 }
 #endif	/* !HAVE_NFS_PLUGIN_H */
 
-static void nfsd_export(FILE *f)
+static void nfsd_export(FILE *ifile, FILE *ofile)
 {
 	/* requests are:
 	 *  domain path
@@ -1198,7 +1198,7 @@
 	nfs_export *found = NULL;
 	struct addrinfo *ai = NULL;
 
-	if (readline(fileno(f), &lbuf, &lbuflen) != 1)
+	if (readline(fileno(ifile), &lbuf, &lbuflen) != 1)
 		return;
 
 	xlog(D_CALL, "nfsd_export: inbuf '%s'", lbuf);
@@ -1226,14 +1226,14 @@
 	found = lookup_export(dom, path, ai);
 
 	if (found) {
-		if (dump_to_cache(f, dom, path, &found->m_export) < 0) {
+		if (dump_to_cache(ofile, dom, path, &found->m_export) < 0) {
 			xlog(L_WARNING,
 			     "Cannot export %s, possibly unsupported filesystem"
 			     " or fsid= required", path);
-			dump_to_cache(f, dom, path, NULL);
+			dump_to_cache(ofile, dom, path, NULL);
 		}
 	} else
-		lookup_nonexport(f, dom, path, ai);
+		lookup_nonexport(ofile, dom, path, ai);
 
  out:
 	xlog(D_CALL, "nfsd_export: found %p path %s", found, path ? path : NULL);
@@ -1245,7 +1245,7 @@
 
 struct {
 	char *cache_name;
-	void (*cache_handle)(FILE *f);
+	void (*cache_handle)(FILE *ifile, FILE *ofile);
 	FILE *f;
 	char vbuf[RPC_CHAN_BUF_SIZE];
 } cachelist[] = {
@@ -1303,8 +1303,23 @@
 		if (cachelist[i].f != NULL &&
 		    FD_ISSET(fileno(cachelist[i].f), readfds)) {
 			cnt++;
-			cachelist[i].cache_handle(cachelist[i].f);
+			char *obuf = calloc(1, RPC_CHAN_BUF_SIZE);
+			FILE *ofile;
+
+			if (!obuf)
+				continue ;
+			ofile = fmemopen(obuf, RPC_CHAN_BUF_SIZE, "w");
+			if (!ofile) {
+				free(obuf);
+				continue ;
+			}
+			cachelist[i].cache_handle(cachelist[i].f, ofile);
 			FD_CLR(fileno(cachelist[i].f), readfds);
+
+			fflush(ofile);
+			write(fileno(cachelist[i].f), obuf, ftell(ofile));
+			fclose(ofile);
+			free(obuf);
 		}
 	}
 	return cnt;
