int fd;
};
+#define COMMAND_BUF_SIZE 32768
+
struct cmd_task {
struct task task;
+ char command_buf[2][COMMAND_BUF_SIZE]; /* stdout/stderr of command */
+ int cbo[2]; /* command buf offsets */
+ unsigned flags[2]; /* passed to for_each_line() */
};
static int find_cmd_byname(char *name)
return 1;
}
-#define COMMAND_BUF_SIZE 32768
-
static enum cmd_status cmd_status(void)
{
if (command_fds[0] >= 0 || command_fds[1] >= 0)
para_fd_set(command_fds[1], &s->rfds, &s->max_fileno);
}
-static int command_post_select(struct sched *s, __a_unused struct task *t)
+static int command_post_select(struct sched *s, struct task *t)
{
+ struct cmd_task *ct = container_of(t, struct cmd_task, task);
int i, ret;
- static char command_buf[2][COMMAND_BUF_SIZE];
- static int cbo[2]; /* command buf offsets */
- static unsigned flags[2]; /* for for_each_line() */
enum cmd_status cmds = cmd_status();
if (cmds != CMDS_DCMD)
if (command_fds[i] < 0)
continue;
ret = read_nonblock(command_fds[i],
- command_buf[i] + cbo[i],
- COMMAND_BUF_SIZE - 1 - cbo[i], &s->rfds, &sz);
- cbo[i] += sz;
- sz = cbo[i];
- cbo[i] = for_each_line(flags[i], command_buf[i], cbo[i],
- add_output_line, &i);
- if (sz != cbo[i]) { /* at least one line found */
+ ct->command_buf[i] + ct->cbo[i],
+ COMMAND_BUF_SIZE - 1 - ct->cbo[i], &s->rfds, &sz);
+ ct->cbo[i] += sz;
+ sz = ct->cbo[i];
+ ct->cbo[i] = for_each_line(ct->flags[i], ct->command_buf[i],
+ ct->cbo[i], add_output_line, &i);
+ if (sz != ct->cbo[i]) { /* at least one line found */
wrefresh(bot.win);
- flags[i] = 0;
+ ct->flags[i] = 0;
}
if (ret < 0 || cmd_pid == 0) {
if (ret < 0)
i, para_strerror(-ret));
close(command_fds[i]);
command_fds[i] = -1;
- flags[i] = 0;
- cbo[i] = 0;
+ ct->flags[i] = 0;
+ ct->cbo[i] = 0;
if (command_fds[!i] < 0) /* both fds closed */
return 1;
}
- if (cbo[i] == COMMAND_BUF_SIZE - 1) {
+ if (ct->cbo[i] == COMMAND_BUF_SIZE - 1) {
PARA_NOTICE_LOG("discarding overlong line");
- cbo[i] = 0;
- flags[i] = FELF_DISCARD_FIRST;
+ ct->cbo[i] = 0;
+ ct->flags[i] = FELF_DISCARD_FIRST;
}
}
return 0;