diff options
author | P. J. McDermott <pj@pehjota.net> | 2014-05-02 10:03:09 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2014-05-02 10:04:19 (EDT) |
commit | 2336104faee586b6e0e5fddb282fcff9a0386203 (patch) | |
tree | 77f6adbb717e054f07d090fe3886bc926e14c675 | |
parent | e0052f38f4fbd4ac1928461d5315fd2215e6dc57 (diff) |
handle_sig(): New funtion.
In init(), set this as the handler for a number of signals.
-rw-r--r-- | src/pro-archman.sh | 31 |
1 files changed, 31 insertions, 0 deletions
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 "${@}" |