X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;ds=inline;f=mount-latest-subvol;h=be239ed139de5c2405125612ebeeaf374227224d;hb=3f437c0f6c11356451d5d739875eee2d4603d7ca;hp=b4bec8efe51c1aec7101d4aa78b84a219b8e1bec;hpb=3a5055dce8796a1946d9f75d8c74605eb73d19df;p=distro-setup diff --git a/mount-latest-subvol b/mount-latest-subvol index b4bec8e..be239ed 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 @@ -163,19 +188,12 @@ for vol in q a o i; do if e umount -R $dir; then unmounted+=($dir) else - echo "$0: failed to umount $dir" - # lsof will fail if it finds no pids - if ! e timeout 4 lsof $dir; then - umount_ret=false - ret=1 - continue - fi - pids=$(lsof -t $dir) ||: - kill $pids - sleep .5 + kill-dir || kill-dir INT || kill-dir HUP || ! $force || kill-dir KILL ||: + if e umount -R $dir; then unmounted+=($dir) else + echo "$0: failed to umount $dir" umount_ret=false ret=1 continue