From f840be8ddc43e321b07edf24eafeab5bc5bc57ef Mon Sep 17 00:00:00 2001
From: Andre Noll <maan@systemlinux.org>
Date: Sun, 26 Jan 2014 18:14:34 +0100
Subject: [PATCH] gui: Introduce status_post_select().

This moves stat pipe error handling into read_stat_pipe() and renames
the function to status_post_select(), which is more to the point. It
shortens do_select() a bit.

Since status_post_select() now calls print_all_items() and
clear_all_items() it had to be moved down to avoid a forward
declaration.
---
 gui.c | 69 ++++++++++++++++++++++++++++-------------------------------
 1 file changed, 33 insertions(+), 36 deletions(-)

diff --git a/gui.c b/gui.c
index a20750f7..318418ea 100644
--- a/gui.c
+++ b/gui.c
@@ -621,7 +621,27 @@ print:
 	return 1;
 }
 
-static int read_stat_pipe(fd_set *rfds)
+static void print_all_items(void)
+{
+	int i;
+
+	if (!curses_active())
+		return;
+	FOR_EACH_STATUS_ITEM(i)
+		print_stat_item(i);
+}
+
+static void clear_all_items(void)
+{
+	int i;
+
+	FOR_EACH_STATUS_ITEM(i) {
+		free(stat_content[i]);
+		stat_content[i] = para_strdup("");
+	}
+}
+
+static void status_post_select(fd_set *rfds)
 {
 	static char *buf;
 	static int bufsize, loaded;
@@ -629,11 +649,11 @@ static int read_stat_pipe(fd_set *rfds)
 	size_t sz;
 
 	if (stat_pipe < 0)
-		return 0;
+		return;
 	if (loaded >= bufsize) {
 		if (bufsize > 1000 * 1000) {
 			loaded = 0;
-			return 0;
+			return;
 		}
 		bufsize += bufsize + 1000;
 		buf = para_realloc(buf, bufsize);
@@ -645,33 +665,20 @@ static int read_stat_pipe(fd_set *rfds)
 	ret2 = for_each_stat_item(buf, loaded, update_item);
 	if (ret < 0 || ret2 < 0) {
 		loaded = 0;
-		return ret2 < 0? ret2 : ret;
+		PARA_NOTICE_LOG("closing stat pipe: %s\n", para_strerror(-ret));
+		close(stat_pipe);
+		stat_pipe = -1;
+		clear_all_items();
+		free(stat_content[SI_BASENAME]);
+		stat_content[SI_BASENAME] =
+			para_strdup("stat command terminated!?");
+		print_all_items();
+		return;
 	}
 	sz = ret2; /* what is left */
 	if (sz > 0 && sz < loaded)
 		memmove(buf, buf + loaded - sz, sz);
 	loaded = sz;
-	return 1;
-}
-
-static void print_all_items(void)
-{
-	int i;
-
-	if (!curses_active())
-		return;
-	FOR_EACH_STATUS_ITEM(i)
-		print_stat_item(i);
-}
-
-static void clear_all_items(void)
-{
-	int i;
-
-	FOR_EACH_STATUS_ITEM(i) {
-		free(stat_content[i]);
-		stat_content[i] = para_strdup("");
-	}
 }
 
 /*
@@ -1050,17 +1057,7 @@ repeat:
 			}
 		}
 	}
-	ret = read_stat_pipe(&rfds);
-	if (ret < 0) {
-		PARA_NOTICE_LOG("closing stat pipe: %s\n", para_strerror(-ret));
-		close(stat_pipe);
-		stat_pipe = -1;
-		clear_all_items();
-		free(stat_content[SI_BASENAME]);
-		stat_content[SI_BASENAME] =
-			para_strdup("stat command terminated!?");
-		print_all_items();
-	}
+	status_post_select(&rfds);
 check_return:
 	switch (mode) {
 	case COMMAND_MODE:
-- 
2.39.5