From d435cc730a0371429f9407d0cd428e4c2c3371e9 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Wed, 9 Jul 2008 10:37:11 +0000 Subject: Move image mount logic into a function Fix image jail size stat to follow symlink --- ezjail-admin | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'ezjail-admin') diff --git a/ezjail-admin b/ezjail-admin index 94cba9e..fef82cc 100755 --- a/ezjail-admin +++ b/ezjail-admin @@ -83,7 +83,22 @@ attach_images () { esac } -# define detach strategy for image jails +# generic mount routine for image jails +mount_images () { + rm -f "${ezjail_devicelink}" + + # Attach images by type + attach_images + + # Clean image + fsck -t ffs -p "/dev/${ezjail_device}" + + mount "/dev/${ezjail_device}" "${ezjail_rootdir}" || detach_images keep || exerr "Error: Could not mount /dev/${ezjail_device} to ${ezjail_rootdir}." + # relink image device + ln -s "/dev/${ezjail_device}" "${ezjail_devicelink}" +} + +# generic detach routine for image jails detach_images () { # Avoid ending up inside mount point cd / @@ -857,8 +872,8 @@ archive) echo " Use ezjail-admin config -i attach ${ezjail_name} to attach it first." continue fi - $0 config -i attach ${ezjail_name} || exerr "Error: Can not attach ${ezjail_image} for ${ezjail_name}" - ezjail_imagesize=-`stat -f %z ${ezjail_image}` + mount_images + ezjail_imagesize=-`stat -Lf %z ${ezjail_image}` fi # This one goes into archive to identify jail by name and restore date @@ -901,7 +916,7 @@ archive) ezjail_paxresult=$? # Detach previously attached jail - [ "${ezjail_imagesize}" ] && cd / && $0 config -i detach ${ezjail_name} + [ "${ezjail_imagesize}" ] && detach_images keep # An error on a jail not running is bad [ ${ezjail_paxresult} -eq 0 -o "${ezjail_force}" ] || exerr "Error: Archiving jail failed. You might want to check ${ezjail_archive}." @@ -1134,18 +1149,9 @@ config) attach) # Check, if image already attached [ "${ezjail_attached}" ] && exerr "Error: Jail image file ${ezjail_image} already attached as ${ezjail_device}." - rm -f "${ezjail_devicelink}" - - # Attach images by type - attach_images - - # Clean image - fsck -t ufs -p -B "/dev/${ezjail_device}" - - mount "/dev/${ezjail_device}" "${ezjail_rootdir}" || detach_images keep || exerr "Error: Could not mount /dev/${ezjail_device} to ${ezjail_rootdir}." - # relink image device - ln -s "/dev/${ezjail_device}" "${ezjail_devicelink}" + # Actually, just "attaching" is not enough, we need to mount + mount_images ;; detach) # Check, if image really attached or running -- cgit v1.2.3