X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=mount-latest-subvol;h=d7be613c763d122d0259b5a434ca4a161f599627;hb=15f043c2c297176bd623d8a8602e2dc5d67eacd6;hp=1b0a8e23123201182ac5eb0d7a99ca626f982652;hpb=86ebcd0416223ded297f6cbbcb0906b85793e359;p=distro-setup diff --git a/mount-latest-subvol b/mount-latest-subvol index 1b0a8e2..d7be613 100644 --- a/mount-latest-subvol +++ b/mount-latest-subvol @@ -81,6 +81,31 @@ fstab() { tu /etc/fstab <<<"$l" done } +kill-dir() { + found_pids=false + sig=${1:-TERM} + if pids=$(timeout 4 lsof -t $dir); then + found_pids=true + timeout 4 lsof -w $dir + kill -$sig $pids + fi + # fuser will find open sockets that lsof won't, for example from gpg-agent. + # note: -v shows kernel processes, which then doesn't return true when we want + if timeout 4 fuser -m $dir &>/dev/null; then + found_pids=true + fuser -$sig -mvk $dir + fi + if $found_pids; then + sleep .5 + return 0 + fi + return 1 +} + +force=false +if [[ $1 == -f ]]; then + force=true +fi ret=0 @@ -89,16 +114,29 @@ first_root_crypt=$(awk '$2 == "/" {print $1}' /etc/mtab) fstab <