From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1Sbffi-0008Qp-4i for garchives@archives.gentoo.org; Mon, 04 Jun 2012 22:22:46 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id A680DE0996; Mon, 4 Jun 2012 22:22:38 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 7A121E0996 for ; Mon, 4 Jun 2012 22:22:38 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id DF5831B402F for ; Mon, 4 Jun 2012 22:22:37 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id A03AFE5404 for ; Mon, 4 Jun 2012 22:22:36 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1338848541.2c50bd9a82c3bb6dfbc63466ae8bfbd401fb3235.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: bin/ X-VCS-Repository: proj/portage X-VCS-Files: bin/helper-functions.sh X-VCS-Directories: bin/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 2c50bd9a82c3bb6dfbc63466ae8bfbd401fb3235 X-VCS-Branch: master Date: Mon, 4 Jun 2012 22:22:36 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: 729c904c-8f5e-46c0-8a80-690cf7e426f9 X-Archives-Hash: 33d60ca690599aed8856d9c0571c9e1d commit: 2c50bd9a82c3bb6dfbc63466ae8bfbd401fb3235 Author: Zac Medico gentoo org> AuthorDate: Mon Jun 4 22:22:21 2012 +0000 Commit: Zac Medico gentoo org> CommitDate: Mon Jun 4 22:22:21 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/portage.git;a= =3Dcommit;h=3D2c50bd9a helper-functions.sh: multijob support bash <4.1 The redirect_alloc_fd() compatibility function is borrowed from Mike Frysinger's proposed multiprocessing.eclass: http://archives.gentoo.org/gentoo-dev/msg_5ecd3b1dd0720522807c136d8fd2cd5= f.xml --- bin/helper-functions.sh | 30 +++++++++++++++++++++++++++++- 1 files changed, 29 insertions(+), 1 deletions(-) diff --git a/bin/helper-functions.sh b/bin/helper-functions.sh index afe14af..c7400fa 100644 --- a/bin/helper-functions.sh +++ b/bin/helper-functions.sh @@ -22,7 +22,7 @@ multijob_init() { mj_control_pipe=3D$(mktemp -t multijob.XXXXXX) rm "${mj_control_pipe}" mkfifo "${mj_control_pipe}" - exec {mj_control_fd}<>${mj_control_pipe} + redirect_alloc_fd mj_control_fd "${mj_control_pipe}" rm -f "${mj_control_pipe}" =20 # See how many children we can fork based on the user's settings. @@ -60,3 +60,31 @@ multijob_post_fork() { fi return $? } + +# @FUNCTION: redirect_alloc_fd +# @USAGE: [redirection] +# @DESCRIPTION: +# Find a free fd and redirect the specified file via it. Store the new +# fd in the specified variable. Useful for the cases where we don't car= e +# about the exact fd #. +redirect_alloc_fd() { + local var=3D$1 file=3D$2 redir=3D${3:-"<>"} + + if [[ $(( (BASH_VERSINFO[0] << 8) + BASH_VERSINFO[1] )) -ge $(( (4 << 8= ) + 1 )) ]] ; then + # Newer bash provides this functionality. + eval "exec {${var}}${redir}'${file}'" + else + # Need to provide the functionality ourselves. + local fd=3D10 + while :; do + # Make sure the fd isn't open. It could be a char device, + # or a symlink (possibly broken) to something else. + if [[ ! -e /dev/fd/${fd} ]] && [[ ! -L /dev/fd/${fd} ]] ; then + eval "exec ${fd}${redir}'${file}'" && break + fi + [[ ${fd} -gt 1024 ]] && die "redirect_alloc_fd failed" + : $(( ++fd )) + done + : $(( ${var} =3D fd )) + fi +}