From 2336104faee586b6e0e5fddb282fcff9a0386203 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Fri, 02 May 2014 10:03:09 -0400 Subject: handle_sig(): New funtion. In init(), set this as the handler for a number of signals. --- diff --git a/src/pro-archman.sh b/src/pro-archman.sh index 2494e96..cc23a22 100644 --- a/src/pro-archman.sh +++ b/src/pro-archman.sh @@ -39,6 +39,7 @@ conf_incoming_dir= conf_pool_gc_delay= conf_verbose= lock= +exit_status= # use() must be defined inline so it can be used to load other modules. use() @@ -131,6 +132,23 @@ get_options() init() { + 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 + 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') + trap "handle_sig ${i}" ${i} + ;; + esac + done + lock get_conf } @@ -185,4 +203,17 @@ unlock() rm -f "${lock}" } +handle_sig() +{ + local sig="${1}" + + unlock + + if [ "x${exit_status:+set}" = 'xset' ]; then + exit ${exit_status} + else + exit $((128 + $sig)) + fi +} + main "${@}" -- cgit v0.9.1