diff options
Diffstat (limited to 'lib/session.sh')
-rw-r--r-- | lib/session.sh | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/session.sh b/lib/session.sh index a2d18e3..fec6aec 100644 --- a/lib/session.sh +++ b/lib/session.sh @@ -33,6 +33,7 @@ session_arch= session_plat= session_mountdir= session_atexit= +session_sigs= session_begin() { @@ -54,6 +55,8 @@ session_begin() error 2 "$(get_msg 'install_running')" fi + session_set_sigs + if ! mutex_lock_timeout "${session_root}/prokit/sessions.lock" 5; then error 2 "$(get_msg 'cant_lock_sessions')" fi @@ -87,6 +90,8 @@ session_begin() session_end() { + session_unset_sigs + # Unregister the session. profile_bind_umount "${session_arch}" "${session_plat}" \ "${session_mountdir}" \ @@ -173,3 +178,43 @@ session_umount() 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_unset_sigs() +{ + trap - ${session_sigs} +} + +session_handle_sig() +{ + local sig="${1}" + + session_end + + if [ "x${exit_status:+set}" = 'xset' ]; then + exit ${exit_status} + else + exit $((128 + $sig)) + fi +} |