[PATCH v2] xlat/gen.sh: prevent wait from failling upon PID reuse

Jules Maselbas jmaselbas at kalray.eu
Tue Sep 3 15:44:36 UTC 2019


In some cases a process id in the pids list might have already
terminated and the exact same id can be attributed to a new process
with a different parent. In such case wait will fail, and will say:
  wait: pid 18396 is not a child of this shell

Adding '|| true' will only make sure to skip such case. But it will
also skip cases were the child process exit with errors. To prevent
from loosing such event the child process will signal and terminate
the parent process.

If wait fails; after adding the kill signal; then it means that PID
has been re-used. Which means that PID we were waiting for is dead.
Therefore we can simply do jobs -= 1

Reviewed-by: Yann Sionneau <ysionneau at kalray.eu>
Signed-off-by: Jules Maselbas <jmaselbas at kalray.eu>
---
Changes in v2:
 - Add kill signal in sub process
---
 xlat/gen.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xlat/gen.sh b/xlat/gen.sh
index ceb0e8fd..7bdc3d7a 100755
--- a/xlat/gen.sh
+++ b/xlat/gen.sh
@@ -303,14 +303,14 @@ main()
 			[ -f "${f}" ] || continue
 			name=${f##*/}
 			name=${name%.in}
-			gen_header "${f}" "${output}/${name}.h" "${name}" &
+			(gen_header "${f}" "${output}/${name}.h" "${name}" || kill $$) &
 			pids="$pids $!"
 			names="${names} ${name}"
 			: $(( jobs += 1 ))
 			if [ "${jobs}" -gt "$(( ncpus * 2 ))" ]; then
 				read wait_pid rest
 				pids="$rest"
-				wait -n 2>/dev/null || wait "$wait_pid"
+				wait -n 2>/dev/null || wait "$wait_pid" || true
 				: $(( jobs -= 1 ))
 			fi <<- EOF
 			$pids
-- 
2.21.0.196.g041f5ea



More information about the Strace-devel mailing list