]> git.tue.mpg.de Git - paraslash.git/commitdiff
gui: Introduce status_post_select().
authorAndre Noll <maan@systemlinux.org>
Sun, 26 Jan 2014 17:14:34 +0000 (18:14 +0100)
committerAndre Noll <maan@systemlinux.org>
Sun, 4 May 2014 13:48:54 +0000 (15:48 +0200)
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

diff --git a/gui.c b/gui.c
index a20750f7f300800b7255b32a50120a0526b1ff58..318418ea1e7959ba2aeba35d7df7af01da779338 100644 (file)
--- 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: