From 8600ae82f0fa024ac39c48d3c44e784c5b2efeab Mon Sep 17 00:00:00 2001 From: Michael Santos Date: Sat, 29 Mar 2014 12:33:10 -0400 Subject: [PATCH] Always treat stderr as a stream Using exact reads for processes running the event loop broke stderr. --- c_src/alcove.c | 6 ++++-- test/alcove_tests.erl | 8 +++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/c_src/alcove.c b/c_src/alcove.c index 28557d0..9c22653 100644 --- a/c_src/alcove.c +++ b/c_src/alcove.c @@ -331,7 +331,8 @@ alcove_child_stdio(int fdin, alcove_child_t *c, u_int16_t type) * * Otherwise, read in the length header and do an exact read. */ - if (c->fdctl == ALCOVE_CHILD_EXEC) + if ( (c->fdctl == ALCOVE_CHILD_EXEC) + || type == ALCOVE_MSG_STDERR) read_len = MAXMSGLEN; n = read(fdin, buf, read_len); @@ -343,7 +344,8 @@ alcove_child_stdio(int fdin, alcove_child_t *c, u_int16_t type) return -1; } - if (c->fdctl != ALCOVE_CHILD_EXEC) { + if ( (c->fdctl != ALCOVE_CHILD_EXEC) + && (type != ALCOVE_MSG_STDERR)) { n = buf[0] << 8 | buf[1]; if (alcove_read(fdin, buf+2, n) != n) diff --git a/test/alcove_tests.erl b/test/alcove_tests.erl index a25e800..55a4412 100644 --- a/test/alcove_tests.erl +++ b/test/alcove_tests.erl @@ -123,13 +123,19 @@ setopt({_, Port, _Child}) -> Opt2 = alcove:getopt(Port, [], maxforkdepth), Opt3 = alcove:getopt(Port, [Fork], maxforkdepth), Reply = alcove:fork(Port, [Fork]), + + ok = alcove:setopt(Port, [Fork], verbose, 2), + Fork = alcove:getpid(Port, [Fork]), + Stderr = alcove:stderr(Port, [Fork]), + alcove:kill(Port, Fork, 9), [ ?_assertEqual(0, Opt1), ?_assertNotEqual(0, Opt2), ?_assertEqual(0, Opt3), - ?_assertEqual({error,eagain}, Reply) + ?_assertEqual({error,eagain}, Reply), + ?_assertNotEqual(false, Stderr) ]. sethostname({{unix,linux}, Port, Child}) ->