summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/session.sh146
1 files changed, 73 insertions, 73 deletions
diff --git a/src/session.sh b/src/session.sh
index 3dbf875..b843e19 100644
--- a/src/session.sh
+++ b/src/session.sh
@@ -26,6 +26,79 @@ session_mountdir=
session_atexit=
session_sigs=
+session_mount()
+{
+ local fs=
+ local dir=
+ local fstype=
+ local options=
+
+ while read fs dir fstype options; do
+ [ "x${dir}" = 'x' ] && continue
+ mount -t "${fstype}" -o "${options}" -- "${fs}" \
+ "${session_root}/${dir}"
+ done <<-EOF
+ $(profile_get_fstab "${session_arch}" "${session_plat}")
+ EOF
+}
+
+session_umount()
+{
+ local fs=
+ local dir=
+ local fstype=
+ local options=
+
+ while read fs dir fstype options; do
+ [ "x${dir}" = 'x' ] && continue
+ # umount sometimes complains that the /dev file system is busy.
+ # Here's a kludge to try to handle that. We better make sure
+ # bind mounts get unmounted; otherwise, `rm -Rf ${root}` can be
+ # painful.
+ while ! umount -- "${session_root}/${dir}"; do
+ sleep 1
+ done
+ done <<-EOF
+ $(profile_get_fstab "${session_arch}" "${session_plat}" | \
+ sed -n '1!G;h;$p')
+ EOF
+}
+
+session_end()
+{
+ trap : ${session_sigs}
+
+ ${session_atexit}
+
+ # Unregister the session.
+ profile_bind_umount "${session_arch}" "${session_plat}" \
+ "${session_mountdir}" \
+ "${session_root}/prokit/sessions/${session_id}/wd"
+ rmdir -- "${session_root}/prokit/sessions/${session_id}/wd"
+ rmdir -- "${session_root}/prokit/sessions/${session_id}"
+
+ if ! mutex_is_unlockable "${session_root}/prokit/sessions.lock"; then
+ if ! mutex_timedlock "${session_root}/prokit/sessions.lock" 5
+ then
+ error "$(get_msg 'cant_lock_sessions')"
+ trap - ${session_sigs}
+ return 1
+ fi
+ fi
+
+ # Clear the sessions pool. If there are no more sessions, unmount the
+ # file systems.
+ if rmdir -- "${session_root}/prokit/sessions" 2>/dev/null; then
+ session_umount
+ fi
+
+ mutex_unlock "${session_root}/prokit/sessions.lock"
+
+ trap - ${session_sigs}
+
+ return 0
+}
+
session_handle_sig()
{
local sig="${1}"
@@ -58,22 +131,6 @@ session_set_sigs()
done
}
-session_mount()
-{
- local fs=
- local dir=
- local fstype=
- local options=
-
- while read fs dir fstype options; do
- [ "x${dir}" = 'x' ] && continue
- mount -t "${fstype}" -o "${options}" -- "${fs}" \
- "${session_root}/${dir}"
- done <<-EOF
- $(profile_get_fstab "${session_arch}" "${session_plat}")
- EOF
-}
-
session_begin()
{
local root="${1}"
@@ -133,63 +190,6 @@ session_begin()
return 0
}
-session_umount()
-{
- local fs=
- local dir=
- local fstype=
- local options=
-
- while read fs dir fstype options; do
- [ "x${dir}" = 'x' ] && continue
- # umount sometimes complains that the /dev file system is busy.
- # Here's a kludge to try to handle that. We better make sure
- # bind mounts get unmounted; otherwise, `rm -Rf ${root}` can be
- # painful.
- while ! umount -- "${session_root}/${dir}"; do
- sleep 1
- done
- done <<-EOF
- $(profile_get_fstab "${session_arch}" "${session_plat}" | \
- sed -n '1!G;h;$p')
- EOF
-}
-
-session_end()
-{
- trap : ${session_sigs}
-
- ${session_atexit}
-
- # Unregister the session.
- profile_bind_umount "${session_arch}" "${session_plat}" \
- "${session_mountdir}" \
- "${session_root}/prokit/sessions/${session_id}/wd"
- rmdir -- "${session_root}/prokit/sessions/${session_id}/wd"
- rmdir -- "${session_root}/prokit/sessions/${session_id}"
-
- if ! mutex_is_unlockable "${session_root}/prokit/sessions.lock"; then
- if ! mutex_timedlock "${session_root}/prokit/sessions.lock" 5
- then
- error "$(get_msg 'cant_lock_sessions')"
- trap - ${session_sigs}
- return 1
- fi
- fi
-
- # Clear the sessions pool. If there are no more sessions, unmount the
- # file systems.
- if rmdir -- "${session_root}/prokit/sessions" 2>/dev/null; then
- session_umount
- fi
-
- mutex_unlock "${session_root}/prokit/sessions.lock"
-
- trap - ${session_sigs}
-
- return 0
-}
-
session_id()
{
printf '%d\n' ${session_id}