Improve slice and delay handling.

This commit is contained in:
Andreas B. Mundt 2023-09-16 11:29:08 +02:00
parent adb31d1e86
commit 2e0ffda273

View file

@ -7,6 +7,8 @@ set -eu
usr="$1"
uid="$2"
mtp="$3"
slce="system-virtiofs.slice"
slp=false
shutdownVMs(){
local VM
@ -19,6 +21,7 @@ shutdownVMs(){
XDG_CONFIG_HOME="/tmp/$uid/.config/" \
XDG_CACHE_HOME="/var/cache/user/$uid/" \
virsh destroy "$VM" 2>&1 | systemd-cat || true
slp=true
done
}
@ -27,10 +30,10 @@ shutdownVMs(){
## This is the first mount we need to get rid of:
if [[ "$mtp" =~ "/lmn/media/$usr/share" ]] ; then
shutdownVMs
sleep 5 # leave some time to write caches …
[[ "$slp" = true ]] && sleep 5 # leave some time to write caches …
sudo -u ${usr} killall gvfsd | systemd-cat
sudo -u ${usr} killall dbus-daemon | systemd-cat
systemctl kill system-virtiofs.slice || true
systemctl -q is-active "$slce" && systemctl kill "$slce"
# debug to find processes blocking umount:
# lsof >> /var/log/lsof.log
fi