On 05/16/2011 11:47 AM, Laine Stump wrote:
> This is in response to:
>
>
https://bugzilla.redhat.com/show_bug.cgi?id=616060
>
> but will also be useful in an upcoming patch which needs to retrieve
> the output of /etc/rc.d/init.d/netcf-transaction.
>
> Before forking, we now create a pipe, then after forking, the child
> dup2's both stdout and stderr to the write side of the pipe, and the
> parent calls fdopen() on the read side of the pipe and then calls
> gnulib's fread_file() before calling waitpid() to reap the process.
> ---
> src/dutil_linux.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++----
> src/dutil_linux.h | 2 +-
> 2 files changed, 75 insertions(+), 7 deletions(-)
>
> @@ -133,6 +153,18 @@ exec_program(struct netcf *ncf,
> _exit(126);
> }
>
> + if (pipeout[1]>= 0) {
> + /* direct stdout and stderr to the pipe */
> + if (dup2(pipeout[1], fileno(stdout))< 0
> + || dup2(pipeout[1], fileno(stderr))< 0) {
> + /* return a unique code and let the parent log the error */
> + _exit(125);
> + ERR_THROW(WEXITSTATUS(exitstatus) == 125, ncf, EEXEC,
> + "Running '%s' failed to dup2 child process
stdout/stderr",
> + argv_str);
Again, a symbolic name instead of hard-coded 125 would be nicer. ACK
with that change.