From c204523a7af08488bedc1b7d06898c4d2da510aa Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Thu, 25 Jun 2020 19:14:05 -0400 Subject: session: Prefix "static" vars with "_" --- (limited to 'src') diff --git a/src/session.sh b/src/session.sh index 40b00e7..c646a41 100644 --- a/src/session.sh +++ b/src/session.sh @@ -18,12 +18,12 @@ # along with the ProteanOS Development Kit. If not, see # . -session_id= -session_root= -session_arch= -session_plat= -session_mountdir= -session_sigs= +_session_id= +_session_root= +_session_arch= +_session_plat= +_session_mountdir= +_session_sigs= _session_es= _session_mount() @@ -36,9 +36,9 @@ _session_mount() while read fs dir fstype options; do [ "x${dir}" = 'x' ] && continue mount -t "${fstype}" -o "${options}" -- "${fs}" \ - "${session_root}/${dir}" + "${_session_root}/${dir}" done <<-EOF - $(profile_get_fstab "${session_arch}" "${session_plat}") + $(profile_get_fstab "${_session_arch}" "${_session_plat}") EOF } @@ -55,44 +55,44 @@ _session_umount() # 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 + while ! umount -- "${_session_root}/${dir}"; do sleep 1 done done <<-EOF - $(profile_get_fstab "${session_arch}" "${session_plat}" | \ + $(profile_get_fstab "${_session_arch}" "${_session_plat}" | \ sed -n '1!G;h;$p') EOF } session_end() { - trap : ${session_sigs} + trap : ${_session_sigs} # 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 + 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} + 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 + if rmdir -- "${_session_root}/prokit/sessions" 2>/dev/null; then _session_umount fi - mutex_unlock "${session_root}/prokit/sessions.lock" + mutex_unlock "${_session_root}/prokit/sessions.lock" - trap - ${session_sigs} + trap - ${_session_sigs} return 0 } @@ -114,13 +114,13 @@ _session_set_sigs() # 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='' + _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}" + _session_sigs="${_session_sigs} ${i}" trap "_session_handle_sig ${i}" ${i} ;; esac @@ -136,64 +136,64 @@ session_begin() shift 4 rand - session_id=${rand_x} - session_root="${root}" - session_arch="$(cat -- "${root}/etc/proteanos_arch")" - session_plat="$(cat -- "${root}/etc/proteanos_plat")" - session_mountdir="${mountdir}" - - [ -d "${session_root}/prokit" ] || mkdir -- "${session_root}/prokit" - if [ -f "${session_root}/prokit/installing" ] && ! ${installing}; then + _session_id=${rand_x} + _session_root="${root}" + _session_arch="$(cat -- "${root}/etc/proteanos_arch")" + _session_plat="$(cat -- "${root}/etc/proteanos_plat")" + _session_mountdir="${mountdir}" + + [ -d "${_session_root}/prokit" ] || mkdir -- "${_session_root}/prokit" + if [ -f "${_session_root}/prokit/installing" ] && ! ${installing}; then error "$(get_msg 'install_running')" return 1 fi _session_set_sigs - if ! mutex_timedlock "${session_root}/prokit/sessions.lock" 5; then + if ! mutex_timedlock "${_session_root}/prokit/sessions.lock" 5; then error "$(get_msg 'cant_lock_sessions')" - trap - ${session_sigs} + trap - ${_session_sigs} return 1 fi # Check for a sessions pool. - if [ -d "${session_root}/prokit/sessions" ]; then - if ! profile_file_systems_mounted "${session_root}" \ - "${session_arch}" "${session_plat}"; then + if [ -d "${_session_root}/prokit/sessions" ]; then + if ! profile_file_systems_mounted "${_session_root}" \ + "${_session_arch}" "${_session_plat}"; then # If a sessions pool exists but the file systems aren't # mounted, clean up the old sessions and mount the file # systems. - rmdir -- "${session_root}/prokit/sessions/"* + rmdir -- "${_session_root}/prokit/sessions/"* _session_mount fi else # If the sessions pool doesn't exist, create it and mount the # file systems. - mkdir -- "${session_root}/prokit/sessions" + mkdir -- "${_session_root}/prokit/sessions" _session_mount fi # Register the session. - mkdir -- "${session_root}/prokit/sessions/${session_id}" - mkdir -- "${session_root}/prokit/sessions/${session_id}/wd" - profile_bind_mount "${session_arch}" "${session_plat}" \ - "${session_mountdir}" \ - "${session_root}/prokit/sessions/${session_id}/wd" + mkdir -- "${_session_root}/prokit/sessions/${_session_id}" + mkdir -- "${_session_root}/prokit/sessions/${_session_id}/wd" + profile_bind_mount "${_session_arch}" "${_session_plat}" \ + "${_session_mountdir}" \ + "${_session_root}/prokit/sessions/${_session_id}/wd" - mutex_unlock "${session_root}/prokit/sessions.lock" + mutex_unlock "${_session_root}/prokit/sessions.lock" return 0 } session_id() { - printf '%d\n' ${session_id} + printf '%d\n' ${_session_id} return 0 } session_dir() { - printf '/prokit/sessions/%d\n' ${session_id} + printf '/prokit/sessions/%d\n' ${_session_id} return 0 } @@ -209,8 +209,8 @@ session_exec() arg="'$(printf '%s\n' "${arg}" | sed "s/'/'\\\\''/g")'" args="${args} ${arg}" done - session_dir="/prokit/sessions/${session_id}/wd" - chroot "${session_root}" /bin/sh -c "cd ${session_dir}; ${args}" || \ + session_dir="/prokit/sessions/${_session_id}/wd" + chroot "${_session_root}" /bin/sh -c "cd ${session_dir}; ${args}" || \ return ${?} return ${_session_es} -- cgit v0.9.1