Gentoo Logo
Gentoo Spaceship




Note: Due to technical difficulties, the Archives are currently not up to date. GMANE provides an alternative service for most mailing lists.
c.f. bug 424647
List Archive: gentoo-dev
Navigation:
Lists: gentoo-dev: < Prev By Thread Next > < Prev By Date Next >
Headers:
To: gentoo-dev@g.o
From: Zac Medico <zmedico@g.o>
Subject: Re: multiprocessing.eclass: doing parallel work in bash
Date: Sun, 03 Jun 2012 18:41:34 -0700
On 06/02/2012 10:08 PM, Mike Frysinger wrote:
> # @FUNCTION: redirect_alloc_fd
> # @USAGE: <var> <file> [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 care
> # about the exact fd #.
> 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}'"
> 	else
> 		# Need to provide the functionality ourselves.
> 		local fd=10
> 		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 ]] && return 1 # sanity
> 			: $(( ++fd ))
> 		done
> 		: $(( ${var} = fd ))
> 	fi
> }
> 
> fi

Where it returns 1 if [[ ${fd} -gt 1024 ]], maybe it would be best to
die there. It shouldn't fail there in practice, but if it does, it would
be really helpful to exactly where it failed.
-- 
Thanks,
Zac


References:
multiprocessing.eclass: doing parallel work in bash
-- Mike Frysinger
Re: multiprocessing.eclass: doing parallel work in bash
-- Mike Frysinger
Navigation:
Lists: gentoo-dev: < Prev By Thread Next > < Prev By Date Next >
Previous by thread:
Re: multiprocessing.eclass: doing parallel work in bash
Next by thread:
Re: multiprocessing.eclass: doing parallel work in bash
Previous by date:
Automated Package Removal and Addition Tracker, for the week ending 2012-06-03 23h59 UTC
Next by date:
Re: Git braindump: 2 of N: developer interaction (merge co-ordinators)


Updated Jun 29, 2012

Summary: Archive of the gentoo-dev mailing list.

Donate to support our development efforts.

Copyright 2001-2013 Gentoo Foundation, Inc. Questions, Comments? Contact us.