mirror of
https://github.com/uselessd/alcove.git
synced 2026-04-15 09:15:19 +00:00
Pass the process state into the pid iterator funs
This commit is contained in:
@@ -65,10 +65,10 @@ static alcove_msg_stdio_t * alcove_alloc_hdr_stdio(pid_t pid, u_int16_t type,
|
||||
static alcove_msg_call_t * alcove_alloc_hdr_call(u_int16_t type, ETERM *t,
|
||||
size_t *len);
|
||||
|
||||
static int exited_pid(alcove_child_t *c, void *arg1, void *arg2);
|
||||
static int set_pid(alcove_child_t *c, void *arg1, void *arg2);
|
||||
static int write_to_pid(alcove_child_t *c, void *arg1, void *arg2);
|
||||
static int read_from_pid(alcove_child_t *c, void *arg1, void *arg2);
|
||||
static int exited_pid(alcove_state_t *ap, alcove_child_t *c, void *arg1, void *arg2);
|
||||
static int set_pid(alcove_state_t *ap, alcove_child_t *c, void *arg1, void *arg2);
|
||||
static int write_to_pid(alcove_state_t *ap, alcove_child_t *c, void *arg1, void *arg2);
|
||||
static int read_from_pid(alcove_state_t *ap, alcove_child_t *c, void *arg1, void *arg2);
|
||||
|
||||
static int alcove_handle_signal(alcove_state_t *ap);
|
||||
|
||||
@@ -209,7 +209,7 @@ alcove_event_loop(alcove_state_t *ap)
|
||||
}
|
||||
}
|
||||
|
||||
pid_foreach(ap, 0, &rfds, &ap->depth, pid_not_equal, read_from_pid);
|
||||
pid_foreach(ap, 0, &rfds, NULL, pid_not_equal, read_from_pid);
|
||||
|
||||
if (ap->verbose > 1)
|
||||
alcove_stats(ap);
|
||||
@@ -522,7 +522,8 @@ alcove_read(int fd, void *buf, ssize_t len)
|
||||
|
||||
int
|
||||
pid_foreach(alcove_state_t *ap, pid_t pid, void *arg1, void *arg2,
|
||||
int (*comp)(pid_t, pid_t), int (*fp)(alcove_child_t *, void *, void *))
|
||||
int (*comp)(pid_t, pid_t),
|
||||
int (*fp)(alcove_state_t *ap, alcove_child_t *, void *, void *))
|
||||
{
|
||||
int i = 0;
|
||||
int rv = 0;
|
||||
@@ -531,7 +532,7 @@ pid_foreach(alcove_state_t *ap, pid_t pid, void *arg1, void *arg2,
|
||||
if ((*comp)(ap->child[i].pid, pid) == 0)
|
||||
continue;
|
||||
|
||||
rv = (*fp)(&(ap->child[i]), arg1, arg2);
|
||||
rv = (*fp)(ap, &(ap->child[i]), arg1, arg2);
|
||||
|
||||
if (rv <= 0)
|
||||
return rv;
|
||||
@@ -553,17 +554,16 @@ pid_not_equal(pid_t p1, pid_t p2)
|
||||
}
|
||||
|
||||
static int
|
||||
exited_pid(alcove_child_t *c, void *arg1, void *arg2)
|
||||
exited_pid(alcove_state_t *ap, alcove_child_t *c, void *arg1, void *arg2)
|
||||
{
|
||||
int *status = arg1;
|
||||
int *opt = arg2;
|
||||
ETERM *t = NULL;
|
||||
|
||||
c->exited = 1;
|
||||
(void)close(c->fdin);
|
||||
c->fdin = -1;
|
||||
|
||||
if (WIFEXITED(*status) && (*opt & alcove_opt_exit_status)) {
|
||||
if (WIFEXITED(*status) && (ap->opt & alcove_opt_exit_status)) {
|
||||
t = alcove_tuple2(
|
||||
erl_mk_atom("exit_status"),
|
||||
erl_mk_int(WEXITSTATUS(*status))
|
||||
@@ -573,7 +573,7 @@ exited_pid(alcove_child_t *c, void *arg1, void *arg2)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (WIFSIGNALED(*status) && (*opt & alcove_opt_termsig)) {
|
||||
if (WIFSIGNALED(*status) && (ap->opt & alcove_opt_termsig)) {
|
||||
t = alcove_tuple2(
|
||||
erl_mk_atom("termsig"),
|
||||
erl_mk_int(WTERMSIG(*status))
|
||||
@@ -587,7 +587,7 @@ exited_pid(alcove_child_t *c, void *arg1, void *arg2)
|
||||
}
|
||||
|
||||
static int
|
||||
set_pid(alcove_child_t *c, void *arg1, void *arg2)
|
||||
set_pid(alcove_state_t *ap, alcove_child_t *c, void *arg1, void *arg2)
|
||||
{
|
||||
fd_set *rfds = arg1;
|
||||
int *fdmax = arg2;
|
||||
@@ -616,7 +616,7 @@ set_pid(alcove_child_t *c, void *arg1, void *arg2)
|
||||
}
|
||||
|
||||
static int
|
||||
write_to_pid(alcove_child_t *c, void *arg1, void *arg2)
|
||||
write_to_pid(alcove_state_t *ap, alcove_child_t *c, void *arg1, void *arg2)
|
||||
{
|
||||
char *buf = arg1;
|
||||
u_int16_t *bufsz = arg2;
|
||||
@@ -631,10 +631,9 @@ write_to_pid(alcove_child_t *c, void *arg1, void *arg2)
|
||||
}
|
||||
|
||||
static int
|
||||
read_from_pid(alcove_child_t *c, void *arg1, void *arg2)
|
||||
read_from_pid(alcove_state_t *ap, alcove_child_t *c, void *arg1, void *arg2)
|
||||
{
|
||||
fd_set *rfds = arg1;
|
||||
u_int16_t *depth = arg2;
|
||||
|
||||
if (c->fdctl > -1 && FD_ISSET(c->fdctl, rfds)) {
|
||||
unsigned char buf;
|
||||
@@ -653,7 +652,8 @@ read_from_pid(alcove_child_t *c, void *arg1, void *arg2)
|
||||
}
|
||||
|
||||
if (c->fdout > -1 && FD_ISSET(c->fdout, rfds)) {
|
||||
switch (alcove_child_stdio(c->fdout, *depth, c, ALCOVE_MSG_TYPE(c))) {
|
||||
switch (alcove_child_stdio(c->fdout, ap->depth,
|
||||
c, ALCOVE_MSG_TYPE(c))) {
|
||||
case -1:
|
||||
case 0:
|
||||
(void)close(c->fdout);
|
||||
@@ -665,7 +665,8 @@ read_from_pid(alcove_child_t *c, void *arg1, void *arg2)
|
||||
}
|
||||
|
||||
if (c->fderr > -1 && FD_ISSET(c->fderr, rfds)) {
|
||||
switch (alcove_child_stdio(c->fderr, *depth, c, ALCOVE_MSG_STDERR)) {
|
||||
switch (alcove_child_stdio(c->fderr, ap->depth,
|
||||
c, ALCOVE_MSG_STDERR)) {
|
||||
case -1:
|
||||
case 0:
|
||||
(void)close(c->fderr);
|
||||
@@ -708,7 +709,7 @@ alcove_handle_signal(alcove_state_t *ap) {
|
||||
if (pid < 0)
|
||||
return -1;
|
||||
|
||||
(void)pid_foreach(ap, pid, &status, &ap->opt,
|
||||
(void)pid_foreach(ap, pid, &status, NULL,
|
||||
pid_equal, exited_pid);
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,8 @@ void sighandler(int sig);
|
||||
void alcove_event_loop(alcove_state_t *ap);
|
||||
|
||||
int pid_foreach(alcove_state_t *ap, pid_t pid, void *arg1, void *arg2,
|
||||
int (*comp)(pid_t, pid_t), int (*fp)(alcove_child_t *, void *, void *));
|
||||
int (*comp)(pid_t, pid_t),
|
||||
int (*fp)(alcove_state_t *, alcove_child_t *, void *, void *));
|
||||
int pid_equal(pid_t p1, pid_t p2);
|
||||
int pid_not_equal(pid_t p1, pid_t p2);
|
||||
|
||||
|
||||
@@ -26,7 +26,8 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
static int cons_pid(alcove_child_t *c, void *arg1, void *arg2);
|
||||
static int cons_pid(alcove_state_t *ap, alcove_child_t *c,
|
||||
void *arg1, void *arg2);
|
||||
|
||||
ETERM *
|
||||
alcove_call(alcove_state_t *ap, u_int32_t call, ETERM *arg)
|
||||
@@ -201,7 +202,7 @@ alcove_free_argv(char **argv)
|
||||
}
|
||||
|
||||
static int
|
||||
cons_pid(alcove_child_t *c, void *arg1, void *arg2)
|
||||
cons_pid(alcove_state_t *ap, alcove_child_t *c, void *arg1, void *arg2)
|
||||
{
|
||||
ETERM **t = arg1;
|
||||
*t = erl_cons(erl_mk_int(c->pid), *t);
|
||||
|
||||
@@ -41,8 +41,8 @@ static int alcove_set_cloexec(int fd);
|
||||
static void alcove_close_pipe(int fd[2]);
|
||||
static int alcove_child_fun(void *arg);
|
||||
static int alcove_parent_fd(alcove_state_t *ap, alcove_fd_t *fd, pid_t pid);
|
||||
static int avail_pid(alcove_child_t *c, void *arg1, void *arg2);
|
||||
static int stdio_pid(alcove_child_t *c, void *arg1, void *arg2);
|
||||
static int avail_pid(alcove_state_t *ap, alcove_child_t *c, void *arg1, void *arg2);
|
||||
static int stdio_pid(alcove_state_t *ap, alcove_child_t *c, void *arg1, void *arg2);
|
||||
|
||||
/*
|
||||
* fork(2)
|
||||
@@ -356,7 +356,7 @@ alcove_parent_fd(alcove_state_t *ap, alcove_fd_t *fd, pid_t pid)
|
||||
}
|
||||
|
||||
static int
|
||||
avail_pid(alcove_child_t *c, void *arg1, void *arg2)
|
||||
avail_pid(alcove_state_t *ap, alcove_child_t *c, void *arg1, void *arg2)
|
||||
{
|
||||
/* slot found */
|
||||
if (c->pid == 0)
|
||||
@@ -366,7 +366,7 @@ avail_pid(alcove_child_t *c, void *arg1, void *arg2)
|
||||
}
|
||||
|
||||
static int
|
||||
stdio_pid(alcove_child_t *c, void *arg1, void *arg2)
|
||||
stdio_pid(alcove_state_t *ap, alcove_child_t *c, void *arg1, void *arg2)
|
||||
{
|
||||
alcove_fd_t *fd = arg1;
|
||||
pid_t *pid = arg2;
|
||||
|
||||
Reference in New Issue
Block a user