From 36eb5a862f13c6f6d623e94edf98b651359a7d7e Mon Sep 17 00:00:00 2001
From: Alberto Bertogli <albertito@blitiri.com.ar>
Date: Thu, 23 Jul 2009 12:24:57 -0300
Subject: [PATCH 08/22] libfiu: Stop the remote control thread after too many (real) errors

Otherwise, we might just get into an infinite loop, when open() succeeds
but read() fails immediately.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
---
 libfiu/fiu-rc.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/libfiu/fiu-rc.c b/libfiu/fiu-rc.c
index 805021b..a0491de 100644
--- a/libfiu/fiu-rc.c
+++ b/libfiu/fiu-rc.c
@@ -180,14 +180,22 @@ static char npipe_path_out[PATH_MAX];
 
 static void *rc_fifo_thread(void *unused)
 {
-	int fdr, fdw, r;
+	int fdr, fdw, r, errcount;
 
 	/* increment the recursion count so we're not affected by libfiu,
 	 * otherwise we could make the remote control useless by enabling all
 	 * failure points */
 	rec_count++;
 
+	errcount = 0;
+
 reopen:
+	if (errcount > 10) {
+		fprintf(stderr, "libfiu: Too many errors in remote control "
+				"thread, shutting down\n");
+		return NULL;
+	}
+
 	fdr = open(npipe_path_in, O_RDONLY);
 	if (fdr < 0)
 		return NULL;
@@ -202,6 +210,7 @@ reopen:
 		r = rc_do_command(fdr, fdw);
 		if (r < 0 && errno != EPIPE) {
 			perror("libfiu: Error reading from remote control");
+			errcount++;
 			close(fdr);
 			close(fdw);
 			goto reopen;
-- 
1.6.2.2.646.gb214

