summaryrefslogtreecommitdiff
path: root/ezjail.sh
diff options
context:
space:
mode:
Diffstat (limited to 'ezjail.sh')
-rwxr-xr-xezjail.sh34
1 files changed, 19 insertions, 15 deletions
diff --git a/ezjail.sh b/ezjail.sh
index a97129a..f9656c7 100755
--- a/ezjail.sh
+++ b/ezjail.sh
@@ -58,14 +58,14 @@ do_cmd()
58 # Read config file 58 # Read config file
59 . ${ezjail_prefix}/etc/ezjail/${ezjail} 59 . ${ezjail_prefix}/etc/ezjail/${ezjail}
60 60
61 eval ezjail_root=\"\$jail_${ezjail}_rootdir\" 61 eval ezjail_rootdir=\"\$jail_${ezjail}_rootdir\"
62 eval ezjail_image=\"\$jail_${ezjail}_image\" 62 eval ezjail_image=\"\$jail_${ezjail}_image\"
63 eval ezjail_imagetype=\"\$jail_${ezjail}_imagetype\" 63 eval ezjail_imagetype=\"\$jail_${ezjail}_imagetype\"
64 eval ezjail_attachparams=\"\$jail_${ezjail}_attachparams\" 64 eval ezjail_attachparams=\"\$jail_${ezjail}_attachparams\"
65 eval ezjail_attachblocking=\"\$jail_${ezjail}_attachblocking\" 65 eval ezjail_attachblocking=\"\$jail_${ezjail}_attachblocking\"
66 eval ezjail_forceblocking=\"\$jail_${ezjail}_forceblocking\" 66 eval ezjail_forceblocking=\"\$jail_${ezjail}_forceblocking\"
67 67
68 [ ${ezjail_attachblocking} = "YES" -o ${ezjail_forceblocking} = "YES" ] && ezjail_blocking="YES" || unset ezjail_blocking 68 [ "${ezjail_attachblocking}" = "YES" -o "${ezjail_forceblocking}" = "YES" ] && ezjail_blocking="YES" || unset ezjail_blocking
69 69
70 # Cannot auto mount blocking jails without interrupting boot process 70 # Cannot auto mount blocking jails without interrupting boot process
71 [ "${ezjail_fromrc}" = "YES" -a "${action}" = "start" -a "${ezjail_blocking}" = "YES" ] && continue 71 [ "${ezjail_fromrc}" = "YES" -a "${action}" = "start" -a "${ezjail_blocking}" = "YES" ] && continue
@@ -95,10 +95,10 @@ attach_detach_pre ()
95 # /etc/rc.d/jail does 95 # /etc/rc.d/jail does
96 [ -e /var/run/jail_${ezjail}.id ] && return 1 96 [ -e /var/run/jail_${ezjail}.id ] && return 1
97 97
98 if [ -L "${ezjail_root}.device" ]; then 98 if [ -L "${ezjail_rootdir}.device" ]; then
99 # Fetch destination of soft link 99 # Fetch destination of soft link
100 ezjail_device=`stat -f "%Y" ${ezjail_root}.device` 100 ezjail_device=`stat -f "%Y" ${ezjail_rootdir}.device`
101 [ -b "${ezjail_device}" ] && echo "Warning: Jail image file ${ezjail_name} already attached as ${ezjail_device}." && return 1 101 [ -e "${ezjail_device}" ] && echo "Jail image file ${ezjail} already attached as ${ezjail_device}. 'ezjail-admin config -i detach' it first." && return 1
102 fi 102 fi
103 103
104 # Create a memory disc from jail image 104 # Create a memory disc from jail image
@@ -110,8 +110,8 @@ attach_detach_pre ()
110 crypto|bde) 110 crypto|bde)
111 echo "Attaching bde device for image jail ${ezjail}..." 111 echo "Attaching bde device for image jail ${ezjail}..."
112 echo gbde attach /dev/${ezjail_device} ${ezjail_attachparams} | /bin/sh 112 echo gbde attach /dev/${ezjail_device} ${ezjail_attachparams} | /bin/sh
113 if [ $? -eq 0 ]; then 113 if [ $? -ne 0 ]; then
114 mdconfig -d -u ${ezjail_imagedevice} > /dev/null 114 mdconfig -d -u ${ezjail_device} > /dev/null
115 echo "Error: Attaching bde device failed."; return 1 115 echo "Error: Attaching bde device failed."; return 1
116 fi 116 fi
117 # Device to mount is not md anymore 117 # Device to mount is not md anymore
@@ -120,8 +120,8 @@ attach_detach_pre ()
120 eli) 120 eli)
121 echo "Attaching eli device for image jail ${ezjail}..." 121 echo "Attaching eli device for image jail ${ezjail}..."
122 echo geli attach ${ezjail_attachparams} /dev/${ezjail_device} | /bin/sh 122 echo geli attach ${ezjail_attachparams} /dev/${ezjail_device} | /bin/sh
123 if [ $? -eq 0 ]; then 123 if [ $? -ne 0 ]; then
124 mdconfig -d -u ${ezjail_imagedevice} > /dev/null 124 mdconfig -d -u ${ezjail_device} > /dev/null
125 echo "Error: Attaching eli device failed."; return 1 125 echo "Error: Attaching eli device failed."; return 1
126 fi 126 fi
127 # Device to mount is not md anymore 127 # Device to mount is not md anymore
@@ -130,17 +130,21 @@ attach_detach_pre ()
130 esac 130 esac
131 131
132 # Clean image 132 # Clean image
133 fsck_ufs -F -p ${ezjail_device} 133 fsck_ufs -F -p /dev/${ezjail_device}
134 134
135 # relink image device 135 # relink image device
136 rm -f ${ezjail_root}.device 136 rm -f ${ezjail_rootdir}.device
137 ln -s /dev/${ezjail_device} ${ezjail_root}.device 137 ln -s /dev/${ezjail_device} ${ezjail_rootdir}.device
138 else 138 else
139 # If jail is not running, do not unmount devices, this is the same check
140 # as /etc/rc.d/jail does
141 [ -e /var/run/jail_${ezjail}.id ] || return 1
142
139 # If soft link to device is not set, we cannot unmount 143 # If soft link to device is not set, we cannot unmount
140 [ -e ${ezjail_root}.device ] || return 144 [ -e ${ezjail_rootdir}.device ] || return
141 145
142 # Fetch destination of soft link 146 # Fetch destination of soft link
143 ezjail_device=`stat -f "%Y" ${ezjail_root}.device` 147 ezjail_device=`stat -f "%Y" ${ezjail_rootdir}.device`
144 148
145 # Add this device to the list of devices to be unmounted 149 # Add this device to the list of devices to be unmounted
146 case ${ezjail_imagetype} in 150 case ${ezjail_imagetype} in
@@ -149,7 +153,7 @@ attach_detach_pre ()
149 esac 153 esac
150 154
151 # Remove soft link (which acts as a lock) 155 # Remove soft link (which acts as a lock)
152 rm -f ${ezjail_root}.device 156 rm -f ${ezjail_rootdir}.device
153 fi 157 fi
154} 158}
155 159