public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: antarus@gentoo.org, "Michał Górny" <mgorny@gentoo.org>
Subject: [gentoo-dev] [PATCH] Use bash redirection to run 'tee' rather than simple pipes.
Date: Thu, 28 Feb 2013 16:41:38 +0100	[thread overview]
Message-ID: <1362066098-11364-1-git-send-email-mgorny@gentoo.org> (raw)
In-Reply-To: <CAAr7Pr-5_sdMzHK=8_TpU+sADcy=w9KQ1HEE+ckFsE=aAkO=JA@mail.gmail.com>

This allows us to spawn 'tee' as separate process while keeping
the function code executed in the main shell.
---
 gx86/eclass/multibuild.eclass | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/gx86/eclass/multibuild.eclass b/gx86/eclass/multibuild.eclass
index 716d34f..d66d069 100644
--- a/gx86/eclass/multibuild.eclass
+++ b/gx86/eclass/multibuild.eclass
@@ -108,18 +108,20 @@ multibuild_foreach() {
 		local MULTIBUILD_VARIANT=${v}
 		local MULTIBUILD_ID=${prev_id}${v}
 		local BUILD_DIR=${bdir%%/}-${v}
-
-		einfo "${v}: running ${@}" \
-			| tee -a "${T}/build-${MULTIBUILD_ID}.log"
-
-		# _multibuild_parallel() does redirection internally.
-		# this is a hidden API to avoid writing multilib_foreach twice.
-		if [[ ${1} == _multibuild_parallel ]]; then
-			"${@}"
-		else
-			"${@}" 2>&1 | tee -a "${T}/build-${MULTIBUILD_ID}.log"
-		fi
-		lret=${?}
+		local log_fd
+
+		# redirect_alloc_fd accepts files only. so we need to open
+		# a random file and then reuse the fd for logger process.
+		redirect_alloc_fd log_fd /dev/null
+		# bash can't handle ${log_fd} in redirections,
+		# we need to use eval to pass fd numbers directly.
+		eval "
+			exec ${log_fd}> >(exec tee -a \"\${T}/build-\${MULTIBUILD_ID}.log\")
+			einfo \"\${v}: running \${@}\" >&${log_fd} 2>&1
+			\"\${@}\" >&${log_fd} 2>&1
+			lret=\${?}
+			exec ${log_fd}>&-
+		"
 	done
 	[[ ${ret} -eq 0 && ${lret} -ne 0 ]] && ret=${lret}
 
@@ -145,8 +147,7 @@ multibuild_parallel_foreach() {
 	_multibuild_parallel() {
 		(
 			multijob_child_init
-			"${@}" 2>&1 | tee -a "${T}/build-${MULTIBUILD_ID}.log"
-			exit ${PIPESTATUS[0]}
+			"${@}"
 		) &
 		multijob_post_fork
 	}
-- 
1.8.1.4



           reply	other threads:[~2013-02-28 15:41 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <CAAr7Pr-5_sdMzHK=8_TpU+sADcy=w9KQ1HEE+ckFsE=aAkO=JA@mail.gmail.com>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1362066098-11364-1-git-send-email-mgorny@gentoo.org \
    --to=mgorny@gentoo.org \
    --cc=antarus@gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox