/[gentoo-x86]/eclass/multiprocessing.eclass
Gentoo

Diff of /eclass/multiprocessing.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.2 Revision 1.3
1# Copyright 1999-2012 Gentoo Foundation 1# Copyright 1999-2013 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/multiprocessing.eclass,v 1.2 2012/07/30 14:52:18 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/multiprocessing.eclass,v 1.3 2013/10/12 21:12:48 vapier Exp $
4 4
5# @ECLASS: multiprocessing.eclass 5# @ECLASS: multiprocessing.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# base-system@gentoo.org 7# base-system@gentoo.org
8# @AUTHOR: 8# @AUTHOR:
64 # When something goes wrong, try to wait for all the children so we 64 # When something goes wrong, try to wait for all the children so we
65 # don't leave any zombies around. 65 # don't leave any zombies around.
66 has wait ${EBUILD_DEATH_HOOKS} || EBUILD_DEATH_HOOKS+=" wait " 66 has wait ${EBUILD_DEATH_HOOKS} || EBUILD_DEATH_HOOKS+=" wait "
67 67
68 # Setup a pipe for children to write their pids to when they finish. 68 # Setup a pipe for children to write their pids to when they finish.
69 # We have to allocate two fd's because POSIX has undefined behavior
70 # when you open a FIFO for simultaneous read/write. #487056
69 local pipe="${T}/multijob.pipe" 71 local pipe="${T}/multijob.pipe"
70 mkfifo "${pipe}" 72 mkfifo -m 600 "${pipe}"
73 redirect_alloc_fd mj_write_fd "${pipe}"
71 redirect_alloc_fd mj_control_fd "${pipe}" 74 redirect_alloc_fd mj_read_fd "${pipe}"
72 rm -f "${pipe}" 75 rm -f "${pipe}"
73 76
74 # See how many children we can fork based on the user's settings. 77 # See how many children we can fork based on the user's settings.
75 mj_max_jobs=$(makeopts_jobs "$@") 78 mj_max_jobs=$(makeopts_jobs "$@")
76 mj_num_jobs=0 79 mj_num_jobs=0
118 --pre) mode="pre" ; shift ;; 121 --pre) mode="pre" ; shift ;;
119 --post) mode="post"; shift ;; 122 --post) mode="post"; shift ;;
120 esac 123 esac
121 124
122 if [[ $# -eq 0 ]] ; then 125 if [[ $# -eq 0 ]] ; then
123 trap 'echo ${BASHPID} $? >&'${mj_control_fd} EXIT 126 trap 'echo ${BASHPID} $? >&'${mj_write_fd} EXIT
124 trap 'exit 1' INT TERM 127 trap 'exit 1' INT TERM
125 else 128 else
126 local ret 129 local ret
127 [[ ${mode} == "pre" ]] && { multijob_pre_fork; ret=$?; } 130 [[ ${mode} == "pre" ]] && { multijob_pre_fork; ret=$?; }
128 ( multijob_child_init ; "$@" ) & 131 ( multijob_child_init ; "$@" ) &
167# Wait for a single process to exit and return its exit code. 170# Wait for a single process to exit and return its exit code.
168multijob_finish_one() { 171multijob_finish_one() {
169 [[ $# -eq 0 ]] || die "${FUNCNAME} takes no arguments" 172 [[ $# -eq 0 ]] || die "${FUNCNAME} takes no arguments"
170 173
171 local pid ret 174 local pid ret
172 read -r -u ${mj_control_fd} pid ret || die 175 read -r -u ${mj_read_fd} pid ret || die
173 : $(( --mj_num_jobs )) 176 : $(( --mj_num_jobs ))
174 return ${ret} 177 return ${ret}
175} 178}
176 179
177# @FUNCTION: multijob_finish 180# @FUNCTION: multijob_finish

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.20