From 46a69d58e7e9ad3af24b735c9078853d81914e1a Mon Sep 17 00:00:00 2001 From: Alberto Salvia Novella Date: Thu, 18 Jan 2024 02:15:09 +0100 Subject: [PATCH 1/2] umount lazily to avoid race conditions --- common | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/common b/common index 0e5ab19..b05ca21 100644 --- a/common +++ b/common @@ -39,9 +39,22 @@ chroot_setup() { chroot_teardown() { if (( ${#CHROOT_ACTIVE_MOUNTS[@]} )); then - umount "${CHROOT_ACTIVE_MOUNTS[@]}" + local mount + local attempt + + umount -l "${CHROOT_ACTIVE_MOUNTS[@]}" + + for mount in "${CHROOT_ACTIVE_MOUNTS[@]}"; do + attempt=1 + + while grep --quiet "${mount}" "/proc/mounts" && [[ "${attempt}" -le 50 ]]; do + sleep 0.1 + attempt="$((attempt + 1))" + done + done + + unset CHROOT_ACTIVE_MOUNTS fi - unset CHROOT_ACTIVE_MOUNTS } chroot_add_mount_lazy() { From c2065454b46a3a9f0a0ab34c671fcc304e58c24a Mon Sep 17 00:00:00 2001 From: Alberto Salvia Novella Date: Fri, 16 Feb 2024 18:14:23 +0100 Subject: [PATCH 2/2] umount without sleep, as umount -l detaches inmediately --- common | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/common b/common index b05ca21..b1dafc7 100644 --- a/common +++ b/common @@ -39,22 +39,10 @@ chroot_setup() { chroot_teardown() { if (( ${#CHROOT_ACTIVE_MOUNTS[@]} )); then - local mount - local attempt - umount -l "${CHROOT_ACTIVE_MOUNTS[@]}" - - for mount in "${CHROOT_ACTIVE_MOUNTS[@]}"; do - attempt=1 - - while grep --quiet "${mount}" "/proc/mounts" && [[ "${attempt}" -le 50 ]]; do - sleep 0.1 - attempt="$((attempt + 1))" - done - done - - unset CHROOT_ACTIVE_MOUNTS fi + + unset CHROOT_ACTIVE_MOUNTS } chroot_add_mount_lazy() {