scripts/sync_dev_uevents: Adjust termination of the udevadm

This is needed for newer Bash where $! becomes the PID of the
udevadm instead of being its child. Not killing udevadm properly
in this case may be problematic in case the script was run from
the ssh session - depending on the setup, if not all children
of said session are dead, ssh may block forever waiting for them
to terminate (which won't happen as udevadm gets attached to 1
process instead of being reaped).

Signed-off-by: Michal Berger <michal.berger@intel.com>
Change-Id: I3248d0937e9dd919c054a97473f9bb998aa8ca63
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15147
Reviewed-by: Pawel Piatek <pawelx.piatek@intel.com>
Reviewed-by: Kamil Godzwon <kamilx.godzwon@intel.com>
Reviewed-by: Karol Latecki <karol.latecki@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Michal Berger 2022-10-26 12:04:03 +02:00 committed by Tomasz Zawadzki
parent 008139c8de
commit d88f8ed409

View File

@ -113,8 +113,12 @@ if [[ -S /run/udev/control ]]; then
# This trap targets a subshell which forks udevadm monitor. Since
# process substitution works in an async fashion, $$ won't wait
# for it, leaving it's child unattended after the main loop breaks
# (udevadm won't exit on its own either).
trap '[[ -e /proc/$!/status ]] && pkill -P $!' EXIT
# (udevadm won't exit on its own either). UPDATE: This is not true
# anymore for Bash >= 5.2 where executing process replaces the
# actual subshell so $! becomes the PID of the udevadm instance.
# To accommodate that, attempt to signal $! directly in case pkill
# fails.
trap '[[ ! -e /proc/$!/status ]] || pkill -P $! || kill $!' EXIT
# Also, this will block while reading through a pipe with a timeout
# after not receiving any input. stdbuf is used since udevadm always
# line buffers the monitor output.