make /usr/libexec/security-misc/apt-get-update more reliable

This commit is contained in:
Patrick Schleizer 2025-04-19 13:17:28 -04:00
parent c4f0e1d16f
commit 4799f3ce02
No known key found for this signature in database
GPG key ID: CB8D50BB77BB3C48

View file

@ -11,34 +11,28 @@ set -o pipefail
export LC_ALL=C export LC_ALL=C
pidfile="/run/helper-scripts/security-misc-apt-get-update-pid" pidfile="/run/helper-scripts/security-misc-apt-get-update-pid"
write_pid_file() {
safe-rm -r -f -- "$pidfile"
install -m644 /dev/null "$pidfile"
echo "$$" | sponge -- "$pidfile"
}
sigterm_trap() { sigterm_trap() {
if [ "$lastpid" = "" ]; then /usr/libexec/helper-scripts/apt-get-update-kill-helper
exit 143
fi
if ! kill -0 -- "$lastpid" &>/dev/null ; then
exit 143
fi
kill -s sigterm -- "$lastpid"
exit 143 exit 143
} }
## terminate potential previous invocations.
/usr/libexec/helper-scripts/apt-get-update-kill-helper
trap "sigterm_trap" SIGTERM SIGINT trap "sigterm_trap" SIGTERM SIGINT
[[ -v timeout_after ]] || timeout_after="600" [[ -v timeout_after ]] || timeout_after="600"
[[ -v kill_after ]] || kill_after="10" [[ -v kill_after ]] || kill_after="10"
write_pid_file start-stop-daemon \
--make-pidfile \
timeout \ --pidfile "$pidfile" \
--kill-after="$kill_after" \ --exec /usr/bin/timeout \
"$timeout_after" \ --start \
apt-get update --error-on=any "$@" & -- \
--kill-after="$kill_after" \
"$timeout_after" \
apt-get update --error-on=any "$@" &
lastpid="$!" lastpid="$!"
wait "$lastpid" wait "$lastpid"