static pid_t cmd_pid;
static int command_fds[2] = {-1, -1};
-static int stat_pipe = -1;
static struct gui_args_info conf;
static int loglevel;
struct status_task {
struct task task;
+ char *buf;
+ int bufsize, loaded;
+ struct timeval next_exec;
+ int fd;
};
struct cmd_task {
}
}
-static struct timeval next_exec;
-
-static void status_pre_select(struct sched *s, __a_unused struct task *t)
+static void status_pre_select(struct sched *s, struct task *t)
{
- if (stat_pipe >= 0)
- return para_fd_set(stat_pipe, &s->rfds, &s->max_fileno);
- sched_request_barrier_or_min_delay(&next_exec, s);
+ struct status_task *st = container_of(t, struct status_task, task);
+
+ if (st->fd >= 0)
+ return para_fd_set(st->fd, &s->rfds, &s->max_fileno);
+ sched_request_barrier_or_min_delay(&st->next_exec, s);
}
-static int status_post_select(struct sched *s, __a_unused struct task *t)
+static int status_post_select(struct sched *s, struct task *t)
{
- static char *buf;
- static int bufsize, loaded;
+ struct status_task *st = container_of(t, struct status_task, task);
size_t sz;
pid_t pid;
int ret, ret2;
- if (stat_pipe < 0) {
+ if (st->fd < 0) {
int fds[3] = {0, 1, 0};
/* Avoid busy loop */
- if (tv_diff(&next_exec, now, NULL) > 0)
+ if (tv_diff(&st->next_exec, now, NULL) > 0)
return 0;
- next_exec.tv_sec = now->tv_sec + 2;
+ st->next_exec.tv_sec = now->tv_sec + 2;
ret = para_exec_cmdline_pid(&pid, conf.stat_cmd_arg, fds);
if (ret < 0)
return 0;
close(fds[1]);
return 0;
}
- stat_pipe = fds[1];
+ st->fd = fds[1];
return 0;
}
- if (loaded >= bufsize) {
- if (bufsize > 1000 * 1000) {
- loaded = 0;
+ if (st->loaded >= st->bufsize) {
+ if (st->bufsize > 1000 * 1000) {
+ st->loaded = 0;
return 0;
}
- bufsize += bufsize + 1000;
- buf = para_realloc(buf, bufsize);
+ st->bufsize += st->bufsize + 1000;
+ st->buf = para_realloc(st->buf, st->bufsize);
}
- assert(loaded < bufsize);
- ret = read_nonblock(stat_pipe, buf + loaded, bufsize - loaded,
- &s->rfds, &sz);
- loaded += sz;
- ret2 = for_each_stat_item(buf, loaded, update_item);
+ assert(st->loaded < st->bufsize);
+ ret = read_nonblock(st->fd, st->buf + st->loaded,
+ st->bufsize - st->loaded, &s->rfds, &sz);
+ st->loaded += sz;
+ ret2 = for_each_stat_item(st->buf, st->loaded, update_item);
if (ret < 0 || ret2 < 0) {
- loaded = 0;
+ st->loaded = 0;
PARA_NOTICE_LOG("closing stat pipe: %s\n", para_strerror(-ret));
- close(stat_pipe);
- stat_pipe = -1;
+ close(st->fd);
+ st->fd = -1;
clear_all_items();
free(stat_content[SI_BASENAME]);
stat_content[SI_BASENAME] =
return 0;
}
sz = ret2; /* what is left */
- if (sz > 0 && sz < loaded)
- memmove(buf, buf + loaded - sz, sz);
- loaded = sz;
+ if (sz > 0 && sz < st->loaded)
+ memmove(st->buf, st->buf + st->loaded - sz, sz);
+ st->loaded = sz;
return 0;
}
.pre_select = status_pre_select,
.post_select = status_post_select,
},
+ .fd = -1
};
struct input_task input_task = {
.task = {