client_ldflags=""
gui_cmdline_objs="add_cmdline(gui)"
-gui_errlist_objs="exec signal string stat ringbuffer fd gui gui_theme"
+gui_errlist_objs="exec signal string stat ringbuffer fd gui gui_theme time"
gui_objs="$gui_cmdline_objs $gui_errlist_objs"
play_errlist_objs="play fd sched ggo buffer_tree time string net
afh_recv afh_common
#include <signal.h>
#include <sys/types.h>
#include <curses.h>
+#include <sys/time.h>
#include "gui.cmdline.h"
#include "para.h"
}
}
-static int open_stat_pipe(void)
+static void status_pre_select(fd_set *rfds, int *max_fileno, struct timeval *tv)
{
- static int init = 1;
+ static struct timeval next_exec, atm, diff;
int ret, fds[3] = {0, 1, 0};
pid_t pid;
- if (init)
- init = 0;
- else
- /*
- * Sleep a bit to avoid a busy loop. As the call to sleep() may
- * be interrupted by SIGCHLD, we simply wait until the call
- * succeeds.
- */
- while (sleep(2))
- ; /* nothing */
+ 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;
+ return;
ret = mark_fd_nonblocking(fds[1]);
- if (ret >= 0)
- return fds[1];
- close(fds[1]);
- return ret;
+ 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
// ret = refresh_status();
FD_ZERO(&rfds);
max_fileno = 0;
- if (stat_pipe < 0)
- stat_pipe = open_stat_pipe();
- if (stat_pipe >= 0)
- para_fd_set(stat_pipe, &rfds, &max_fileno);
+ status_pre_select(&rfds, &max_fileno, &tv);
/* signal pipe */
para_fd_set(signal_pipe, &rfds, &max_fileno);
/* command pipe only for COMMAND_MODE */