summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-04-25 22:27:28 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-04-25 22:27:28 (EDT)
commit8a74fa45eee453564c60b9c7ac8595b294002ccb (patch)
tree7c3a176fb7b20905c03d43793fbc243222f71151 /src
parent2b9acd261dbdc8f470be8858536bc19aee005f02 (diff)
src/session.sh: Define functions before references
Diffstat (limited to 'src')
-rw-r--r--src/session.sh140
1 files changed, 70 insertions, 70 deletions
diff --git a/src/session.sh b/src/session.sh
index bb6347b..3dbf875 100644
--- a/src/session.sh
+++ b/src/session.sh
@@ -26,6 +26,54 @@ session_mountdir=
session_atexit=
session_sigs=
+session_handle_sig()
+{
+ local sig="${1}"
+ shift 1
+
+ session_end
+
+ exit $((128 + ${sig}))
+}
+
+session_set_sigs()
+{
+ local i=
+ local sig=
+
+ # We need the signal *number* in the signal handler. The only portable
+ # and easy way to get the number of a named signal is to search for it
+ # as in the following loop hack.
+ i=0
+ session_sigs=''
+ while [ ${i} -lt 127 ]; do
+ i=$((${i} + 1))
+ sig="$(kill -l ${i} 2>/dev/null)" || continue
+ case "${sig}" in
+ 'HUP' | 'INT' | 'QUIT' | 'ABRT' | 'ALRM' | 'TERM')
+ session_sigs="${session_sigs} ${i}"
+ trap "session_handle_sig ${i}" ${i}
+ ;;
+ esac
+ 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}"
@@ -85,6 +133,28 @@ 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}
@@ -147,73 +217,3 @@ session_exec()
return ${?}
}
-
-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_set_sigs()
-{
- local i=
- local sig=
-
- # We need the signal *number* in the signal handler. The only portable
- # and easy way to get the number of a named signal is to search for it
- # as in the following loop hack.
- i=0
- session_sigs=''
- while [ ${i} -lt 127 ]; do
- i=$((${i} + 1))
- sig="$(kill -l ${i} 2>/dev/null)" || continue
- case "${sig}" in
- 'HUP' | 'INT' | 'QUIT' | 'ABRT' | 'ALRM' | 'TERM')
- session_sigs="${session_sigs} ${i}"
- trap "session_handle_sig ${i}" ${i}
- ;;
- esac
- done
-}
-
-session_handle_sig()
-{
- local sig="${1}"
- shift 1
-
- session_end
-
- exit $((128 + ${sig}))
-}