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

Jules Maselbas jmaselbas at kalray.eu
Mon Aug 5 12:46:53 UTC 2019


On Fri, Aug 02, 2019 at 07:38:23PM +0300, Dmitry V. Levin wrote:
> On Fri, Aug 02, 2019 at 02:57:38PM +0200, Jules Maselbas wrote:
> > In some case wait can fail if PID has been already taken by a new process.
> > As the return status is not used it might be better to always return true.
> > 
> > Reviewed-by: Yann Sionneau <ysionneau at kalray.eu>
> > Signed-off-by: Jules Maselbas <jmaselbas at kalray.eu>
> > ---
> >  xlat/gen.sh | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/xlat/gen.sh b/xlat/gen.sh
> > index ceb0e8fd..d2dfdc8c 100755
> > --- a/xlat/gen.sh
> > +++ b/xlat/gen.sh
> > @@ -310,7 +310,7 @@ main()
> >  			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
> 
> I'm afraid this would break $jobs accounting.
I am not sure about this, I don't see how this can impact $jobs
accounting.

> What do you think about an alternative fix, e.g.
I think this patch will work, but I don't think it's neccessary
to wait for all processes to end.

I am sending a new version which I hope has a better explanation.


Best,
---
Jules

> 
> diff --git a/xlat/gen.sh b/xlat/gen.sh
> index 4d34b15c7..06004de99 100755
> --- a/xlat/gen.sh
> +++ b/xlat/gen.sh
> @@ -344,8 +344,13 @@ main()
>  			if [ "${jobs}" -gt "$(( ncpus * 2 ))" ]; then
>  				read wait_pid rest
>  				pids="$rest"
> -				wait -n 2>/dev/null || wait "$wait_pid"
> -				: $(( jobs -= 1 ))
> +				if wait -n 2>/dev/null ||
> +				   wait "$wait_pid" 2>/dev/null; then
> +					: $(( jobs -= 1 ))
> +				else
> +					wait
> +					jobs=0
> +				fi
>  			fi <<- EOF
>  			$pids
>  			EOF
> 
> -- 
> ldv


More information about the Strace-devel mailing list