}
}
+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;
}
}
-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)