From 4ca42f075c40a30544f3776fae11debbdc026330 Mon Sep 17 00:00:00 2001 From: Karl Isenberg Date: Mon, 4 Jan 2016 15:41:12 -0800 Subject: [PATCH] Fix buffer_output --- cluster/mesos/docker/util.sh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/cluster/mesos/docker/util.sh b/cluster/mesos/docker/util.sh index 3470a397d5e..0c6a7ba25a2 100644 --- a/cluster/mesos/docker/util.sh +++ b/cluster/mesos/docker/util.sh @@ -438,15 +438,20 @@ function cluster::mesos::docker::create_basic_user { echo "${password},${user_name},${user_name}" } -# Buffers command output to memory, prints on failure. +# Buffers command output to file, prints output on failure. function cluster::mesos::docker::buffer_output { local cmd="$@" - - # buffer output until failure - local output=$((${cmd} || exit $?) 2>&1) + local tempfile="$(mktemp "${TMPDIR}/buffer.XXXXXX")" + trap "kill -TERM \${PID}; rm '${tempfile}'" TERM INT + ${cmd} &> "${tempfile}" & + PID=$! + wait ${PID} + trap - TERM INT + wait ${PID} local exit_status="$?" if [ "${exit_status}" != 0 ]; then - echo "${output}" 1>&2 - return "${exit_status}" + cat "${tempfile}" 1>&2 fi + rm "${tempfile}" + return "${exit_status}" }