From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id CED601381F3 for ; Wed, 16 Oct 2013 06:56:19 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 9668FE09B5; Wed, 16 Oct 2013 06:56:15 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 14F34E09B5 for ; Wed, 16 Oct 2013 06:56:15 +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 E88EE33EE7D for ; Wed, 16 Oct 2013 06:56:13 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 9B4E8E5308 for ; Wed, 16 Oct 2013 06:56:12 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1381906551.c651476c03a67e98054335b43e476c55bcab167f.vapier@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: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: c651476c03a67e98054335b43e476c55bcab167f X-VCS-Branch: master Date: Wed, 16 Oct 2013 06:56:12 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 7f49c0d5-f3d8-4284-a500-0775c99734c1 X-Archives-Hash: 9b4cf74e1bcff299c593a16b29973960 commit: c651476c03a67e98054335b43e476c55bcab167f Author: Mike Frysinger gentoo org> AuthorDate: Wed Oct 16 06:51:24 2013 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Wed Oct 16 06:55:51 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=c651476c helper-functions.sh: sync with multiprocessing.eclass This pulls in (among other thing) portability fixes. URL: https://bugs.gentoo.org/487056 --- bin/helper-functions.sh | 57 ++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/bin/helper-functions.sh b/bin/helper-functions.sh index ecd78c3..4a46278 100644 --- a/bin/helper-functions.sh +++ b/bin/helper-functions.sh @@ -10,7 +10,7 @@ source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/isolated-functions.sh # # API functions for doing parallel processing # -__numjobs() { +makeopts_jobs() { # Copied from eutils.eclass:makeopts_jobs() local jobs=$(echo " ${MAKEOPTS} " | \ sed -r -n 's:.*[[:space:]](-j|--jobs[=[:space:]])[[:space:]]*([0-9]+).*:\2:p') @@ -19,25 +19,28 @@ __numjobs() { __multijob_init() { # Setup a pipe for children to write their pids to when they finish. - mj_control_pipe=$(mktemp -t multijob.XXXXXX) - rm "${mj_control_pipe}" - mkfifo "${mj_control_pipe}" - __redirect_alloc_fd mj_control_fd "${mj_control_pipe}" - rm -f "${mj_control_pipe}" + # We have to allocate two fd's because POSIX has undefined behavior + # when you open a FIFO for simultaneous read/write. #487056 + local pipe=$(mktemp -t multijob.XXXXXX) + rm -f "${pipe}" + mkfifo -m 600 "${pipe}" + __redirect_alloc_fd mj_write_fd "${pipe}" + __redirect_alloc_fd mj_read_fd "${pipe}" + rm -f "${pipe}" # See how many children we can fork based on the user's settings. - mj_max_jobs=$(__numjobs) + mj_max_jobs=$(makeopts_jobs "$@") mj_num_jobs=0 } __multijob_child_init() { - trap 'echo ${BASHPID} $? >&'${mj_control_fd} EXIT + trap 'echo ${BASHPID} $? >&'${mj_write_fd} EXIT trap 'exit 1' INT TERM } __multijob_finish_one() { local pid ret - read -r -u ${mj_control_fd} pid ret + read -r -u ${mj_read_fd} pid ret : $(( --mj_num_jobs )) return ${ret} } @@ -71,24 +74,24 @@ __redirect_alloc_fd() { local var=$1 file=$2 redir=${3:-"<>"} if [[ $(( (BASH_VERSINFO[0] << 8) + BASH_VERSINFO[1] )) -ge $(( (4 << 8) + 1 )) ]] ; then - # Newer bash provides this functionality. - eval "exec {${var}}${redir}'${file}'" + # Newer bash provides this functionality. + eval "exec {${var}}${redir}'${file}'" else - # Need to provide the functionality ourselves. - local fd=10 - local fddir=/dev/fd - # Prefer /proc/self/fd if available (/dev/fd - # doesn't work on solaris, see bug #474536). - [[ -d /proc/self/fd ]] && fddir=/proc/self/fd - 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 ${fddir}/${fd} ]] && [[ ! -L ${fddir}/${fd} ]] ; then - eval "exec ${fd}${redir}'${file}'" && break - fi - [[ ${fd} -gt 1024 ]] && die "__redirect_alloc_fd failed" - : $(( ++fd )) - done - : $(( ${var} = fd )) + # Need to provide the functionality ourselves. + local fd=10 + local fddir=/dev/fd + # Prefer /proc/self/fd if available (/dev/fd + # doesn't work on solaris, see bug #474536). + [[ -d /proc/self/fd ]] && fddir=/proc/self/fd + 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 ${fddir}/${fd} ]] && [[ ! -L ${fddir}/${fd} ]] ; then + eval "exec ${fd}${redir}'${file}'" && break + fi + [[ ${fd} -gt 1024 ]] && die 'could not locate a free temp fd !?' + : $(( ++fd )) + done + : $(( ${var} = fd )) fi }