]> granicus.if.org Git - strace/commitdiff
xlat: avoid fork bombing the build system
authorMike Frysinger <vapier@gentoo.org>
Thu, 26 Feb 2015 23:06:16 +0000 (18:06 -0500)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 26 Feb 2015 23:14:04 +0000 (23:14 +0000)
When there were fewer xlat headers, this didn't matter as much.
But now with >200, trying to run them all in parallel can easily
fork bomb smaller systems.

* xlat/gen.sh (main): Do not more jobs than # of cpus.

xlat/gen.sh

index 1484fb59bdf1d515171c1d8d9cd96f7743c6d9f6..8754a032534af7bf435a783694e61a4082f2cfac 100755 (executable)
@@ -147,6 +147,10 @@ main()
        local input="$1"
        local output="$2"
        local name
+       local jobs=0
+       local ncpus="$(getconf _NPROCESSORS_ONLN)"
+       [ "${ncpus}" -ge 1 ] ||
+               ncpus=1
 
        if [ -d "${input}" ]; then
                local f names=
@@ -156,6 +160,11 @@ main()
                        name=${name%.in}
                        gen_header "${f}" "${output}/${name}.h" "${name}" &
                        names="${names} ${name}"
+                       : $(( jobs += 1 ))
+                       if [ ${jobs} -ge ${ncpus} ]; then
+                               jobs=0
+                               wait
+                       fi
                done
                gen_git "${output}/.gitignore" ${names}
                gen_make "${output}/Makemodule.am" ${names}