diff --git a/c_src/alcove.c b/c_src/alcove.c index ebcd796..91e0b7b 100644 --- a/c_src/alcove.c +++ b/c_src/alcove.c @@ -24,6 +24,7 @@ enum { ALCOVE_MSG_PROXY, ALCOVE_MSG_CALL, ALCOVE_MSG_EVENT, + ALCOVE_MSG_CTL, }; #define ALCOVE_CHILD_EXEC -2 @@ -645,7 +646,7 @@ exited_pid(alcove_state_t *ap, alcove_child_t *c, void *arg1, void *arg2) if ( (c->fdin >= 0) && (ap->opt & alcove_opt_stdin_closed)) { index = alcove_mk_atom(t, sizeof(t), "stdin_closed"); - if (alcove_call_fake_reply(c->pid, ALCOVE_MSG_EVENT, t, index) < 0) + if (alcove_call_fake_reply(c->pid, ALCOVE_MSG_CTL, t, index) < 0) return -1; } @@ -756,7 +757,7 @@ read_from_pid(alcove_state_t *ap, alcove_child_t *c, void *arg1, void *arg2) c->fdctl = ALCOVE_CHILD_EXEC; len = alcove_mk_atom(t, sizeof(t), "fdctl_closed"); - if (alcove_call_fake_reply(c->pid, ALCOVE_MSG_EVENT, t, len) < 0) + if (alcove_call_fake_reply(c->pid, ALCOVE_MSG_CTL, t, len) < 0) return -1; } } @@ -768,7 +769,7 @@ read_from_pid(alcove_state_t *ap, alcove_child_t *c, void *arg1, void *arg2) case 0: if (ap->opt & alcove_opt_stdout_closed) { len = alcove_mk_atom(t, sizeof(t), "stdout_closed"); - if (alcove_call_fake_reply(c->pid, ALCOVE_MSG_EVENT, + if (alcove_call_fake_reply(c->pid, ALCOVE_MSG_CTL, t, len) < 0) return -1; } @@ -789,7 +790,7 @@ read_from_pid(alcove_state_t *ap, alcove_child_t *c, void *arg1, void *arg2) case 0: if (ap->opt & alcove_opt_stderr_closed) { len = alcove_mk_atom(t, sizeof(t), "stderr_closed"); - if (alcove_call_fake_reply(c->pid, ALCOVE_MSG_EVENT, + if (alcove_call_fake_reply(c->pid, ALCOVE_MSG_CTL, t, len) < 0) return -1; } diff --git a/include/alcove.hrl b/include/alcove.hrl index f2164c1..f64a6c0 100644 --- a/include/alcove.hrl +++ b/include/alcove.hrl @@ -36,3 +36,4 @@ -define(ALCOVE_MSG_PROXY, 3). -define(ALCOVE_MSG_CALL, 4). -define(ALCOVE_MSG_EVENT, 5). +-define(ALCOVE_MSG_CTL, 6). diff --git a/src/alcove_codec.erl b/src/alcove_codec.erl index 6f4f5cc..72369fa 100644 --- a/src/alcove_codec.erl +++ b/src/alcove_codec.erl @@ -80,4 +80,7 @@ decode(<>, Pids) when Len {alcove_call, lists:reverse(Pids), binary_to_term(Data)}; decode(<>, Pids) when Len =:= 2 + byte_size(Data) -> - {alcove_event, lists:reverse(Pids), binary_to_term(Data)}. + {alcove_event, lists:reverse(Pids), binary_to_term(Data)}; + +decode(<>, Pids) when Len =:= 2 + byte_size(Data) -> + {alcove_ctl, lists:reverse(Pids), binary_to_term(Data)}. diff --git a/src/alcove_drv.erl b/src/alcove_drv.erl index c01b306..ae25d55 100644 --- a/src/alcove_drv.erl +++ b/src/alcove_drv.erl @@ -190,7 +190,7 @@ handle_info(Info, State) -> %%-------------------------------------------------------------------- call_reply(Drv, Pids, false, Timeout) -> receive - {alcove_event, Drv, Pids, fdctl_closed} -> + {alcove_ctl, Drv, Pids, fdctl_closed} -> ok; {alcove_call, Drv, _Pids, badpid} -> exit(badpid); @@ -202,15 +202,12 @@ call_reply(Drv, Pids, false, Timeout) -> end; call_reply(Drv, Pids, true, Timeout) -> receive - {alcove_event, Drv, Pids, {termsig,_} = Signal} -> - exit(Signal); - {alcove_event, Drv, Pids, fdctl_closed} -> - receive - {alcove_event, Drv, Pids, {termsig,_} = Signal} -> - exit(Signal); - {alcove_event, Drv, Pids, {exit_status,_} = Status} -> - exit(Status) - end; + {alcove_ctl, Drv, Pids, fdctl_closed} -> + call_reply(Drv, Pids, true, Timeout); + {alcove_event, Drv, Pids, {termsig,_} = Event} -> + exit(Event); + {alcove_event, Drv, Pids, {exit_status,_} = Event} -> + exit(Event); {alcove_call, Drv, _Pids, badpid} -> exit(badpid); {alcove_call, Drv, Pids, Event} ->