]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
gui: Execute stat command in status_post_select().
authorAndre Noll <maan@systemlinux.org>
Sat, 4 Jan 2014 05:38:23 +0000 (05:38 +0000)
committerAndre Noll <maan@systemlinux.org>
Sun, 4 May 2014 13:48:54 +0000 (15:48 +0200)
pre_select methods should only deal with fd sets and select timeouts,
so the part of status_pre_select() which restarts the status command
belongs to status_post_select().

Unfortunately, after this change both status_pre_select() and
status_post_select() need to know when to restart the stat command.
Therefore we had to add a new global variable next_exec.

The patch also moves status_pre_select() up so that the two functions
are close to each other.

gui.c

diff --git a/gui.c b/gui.c
index 40e93b0c392ee9d96a7dbef59869ecfd8ea52898..894fc2f87298962b7f4a8de7729f74f853b7c49c 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -644,15 +644,50 @@ static void clear_all_items(void)
        }
 }
 
+static struct timeval next_exec;
+
+static void status_pre_select(fd_set *rfds, int *max_fileno, struct timeval *tv)
+{
+       struct timeval atm, diff;
+
+       if (stat_pipe >= 0)
+               return para_fd_set(stat_pipe, rfds, max_fileno);
+       gettimeofday(&atm, NULL);
+       if (tv_diff(&next_exec, &atm, &diff) > 0) {
+               *tv = diff;
+               return;
+       }
+       tv->tv_sec = tv->tv_usec = 0; /* min delay */
+}
+
 static void status_post_select(fd_set *rfds)
 {
        static char *buf;
        static int bufsize, loaded;
-       int ret, ret2;
        size_t sz;
+       pid_t pid;
+       int ret, ret2;
 
-       if (stat_pipe < 0)
+       if (stat_pipe < 0) {
+               struct timeval atm;
+               int fds[3] = {0, 1, 0};
+               /* Avoid busy loop */
+               gettimeofday(&atm, NULL);
+               if (tv_diff(&next_exec, &atm, NULL) > 0)
+                       return;
+               next_exec.tv_sec = atm.tv_sec + 2;
+               ret = para_exec_cmdline_pid(&pid, conf.stat_cmd_arg, fds);
+               if (ret < 0)
+                       return;
+               ret = mark_fd_nonblocking(fds[1]);
+               if (ret < 0) {
+                       close(fds[1]);
+                       return;
+               }
+               stat_pipe = fds[1];
                return;
+       }
+
        if (loaded >= bufsize) {
                if (bufsize > 1000 * 1000) {
                        loaded = 0;
@@ -954,35 +989,6 @@ static void signal_post_select(fd_set *rfds)
        }
 }
 
-static void status_pre_select(fd_set *rfds, int *max_fileno, struct timeval *tv)
-{
-       static struct timeval next_exec, atm, diff;
-       int ret, fds[3] = {0, 1, 0};
-       pid_t pid;
-
-       if (stat_pipe >= 0)
-               goto success;
-       /* Avoid busy loop */
-       gettimeofday(&atm, NULL);
-       if (tv_diff(&next_exec, &atm, &diff) > 0) {
-               if (tv_diff(&diff, tv, NULL) < 0)
-                       *tv = diff;
-               return;
-       }
-       next_exec.tv_sec = atm.tv_sec + 2;
-       ret = para_exec_cmdline_pid(&pid, conf.stat_cmd_arg, fds);
-       if (ret < 0)
-               return;
-       ret = mark_fd_nonblocking(fds[1]);
-       if (ret < 0) {
-               close(fds[1]);
-               return;
-       }
-       stat_pipe = fds[1];
-success:
-       para_fd_set(stat_pipe, rfds, max_fileno);
-}
-
 #define COMMAND_BUF_SIZE 32768
 
 static enum cmd_status cmd_status(void)