summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/pro-archman.sh31
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 "${@}"