From: Andre Noll Date: Sun, 26 Jan 2014 17:14:34 +0000 (+0100) Subject: gui: Introduce status_post_select(). X-Git-Tag: v0.5.3~12^2~18 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=f840be8d 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. --- 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: