root/build-tools/yum-builddep-wrapper
Davlet Panech 3ef97d279c centos7: delete yum.pid after yum-builddep
Pre-dnf yum-builddep leaves a stale yum.pid file behind with its own
process ID. If that PID happens to be reused and match an existing
process, a subsequent yum & co invocation hangs.

Solution: create a wrapper script that deletes the pid file if
necessary.

Change-Id: I821643f576645d78ab1c29cdccefa12740bbc12f
Closes-Bug: 1920805
Signed-off-by: Davlet Panech <davlet.panech@windriver.com>
2021-03-25 18:25:23 -04:00

67 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# Old versions of yum-builddep leave a stale yum.pid file behind.
# Remove that file if necessary after yum-builddep exits
# find yum-builddep
YUM_BUILDDEP=$(which yum-builddep 2>/dev/null)
# dnf: call it directly
if [[ -z $YUM_BUILDDEP ]] || grep -q -F dnf.cli "$YUM_BUILDDEP" ; then
yum-builddep "$@"
exit $?
fi
# old yum: scan command line for --installroot
ROOT_PREFIX=
YUM_CONF=/etc/yum.conf
find_root_prefix() {
while [[ "$#" -gt 0 ]] ; do
case "$1" in
--installroot)
ROOT_PREFIX="$2"
shift
;;
--installroot=*)
ROOT_PREFIX="${1#*=}"
;;
-c|--config)
YUM_CONF="$2"
shift
;;
--config=*)
YUM_CONF="${1#*=}"
;;
esac
shift
done
if [[ -z "$ROOT_PREFIX" ]] && [[ -f "$YUM_CONF" ]] ; then
ROOT_PREFIX=$(sed -rn 's/^\s*installroot\s*=\s*(\S+)\s*$/\1/p' $YUM_CONF)
fi
}
find_root_prefix "$@"
# ignore signals -- always wait for yum-builddep
trap "" INT TERM HUP PIPE
# run it in the background to get its PID
"$YUM_BUILDDEP" "$@" &
pid="$!"
# wait for it
wait "$pid"
res="$?"
# if yum.pid remains and contains yum-builddep's PID, delete it
if [[ -f "${ROOT_PREFIX}/run/yum.pid" ]] ; then
lock_owner=
read lock_owner <"${ROOT_PREFIX}/run/yum.pid" || :
if [[ -n $lock_owner && $lock_owner == $pid ]] ; then
rm -f "${ROOT_PREFIX}/run/yum.pid"
fi
fi
# done
exit $res