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;
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);
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("");
- }
}
/*
}
}
}
- 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: