Fix potential mount/umount issue on FreeBSD

- In case the CD-ROM is not mounted "glabel status | grep CONTEXT | awk '{print $3}'"
  will have a null string which will eventually assign the value "/dev/" to "dev_context"
  variable. In later occasions while existence of "dev_context" is checked it will
  always return true and no elif conditions will be executed. Add additional glabel check
  for BSD.
- In case the CD-ROM is not mounted and used there is nothing to unmount and eventually
  trying to unmount will throw error. So add an additional check to see if "MOUNT_DIR" is
  used as any mount points or not.
pull/232/head
Moin 3 years ago committed by GitHub
parent 789ac3cf4b
commit 4238552798
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -156,7 +156,7 @@ function get_new_context {
blkid | grep "LABEL=['\"]CONTEXT['\"]" | cut -d: -f1; blkid | grep "LABEL=['\"]CONTEXT['\"]" | cut -d: -f1;
} | grep -v '^/dev/loop' | head -n1 } | grep -v '^/dev/loop' | head -n1
) )
elif [[ "$distro" == "BSD" ]]; then elif [[ "$distro" == "BSD" ]] && [[ $(glabel status | grep CONTEXT) ]]; then
local dev_context="/dev/"$(glabel status | grep CONTEXT | awk '{print $3}') local dev_context="/dev/"$(glabel status | grep CONTEXT | awk '{print $3}')
fi fi
@ -290,7 +290,7 @@ function acquire_lock {
function cleanup { function cleanup {
# unmount context # unmount context
if [ -d "${MOUNT_DIR}" ]; then if [ -d "${MOUNT_DIR}" ] && [ -n "$(mount | grep ${MOUNT_DIR})" ]; then
log debug "Unmounting ${MOUNT_DIR}" log debug "Unmounting ${MOUNT_DIR}"
if [[ "$distro" == "Linux" ]]; then if [[ "$distro" == "Linux" ]]; then
umount -l "${MOUNT_DIR}" umount -l "${MOUNT_DIR}"

Loading…
Cancel
Save