24.2 Managing signal handlers

Signal handlers are stored in hooks, one hook for every signal specification; Executing commands with event hooks.

Function: mbfl_signal_attach SIGNAME HANDLER

Add HANDLER to the SIGNAME’s hook. When successful return true; otherwise return false. If currently there is no SIGNAME’s hook: a new hook is defined.

function my_sigkill_handler () {
    echo gotcha >&2
}

mbfl_signal_attack 'SIGKILL' my_sigkill_handler
Function: mbfl_signal_has_handlers SIGNAME

Return true if SIGNAME has handlers associated to it, using this MBFL module; otherwise return false.

Function: mbfl_signal_remove_all_handlers

Undefine all the signal hooks, implicitly removing all the registered handlers.

Function: mbfl_signal_remove_signal_handlers SIGNAME

Undefine the signal hook associated to SIGNAME, implicitly removing all the registered handlers.

Function: mbfl_signal_invoke_handlers SIGNAME

Run the hook associated to the signal SIGNAME. This function is not meant to be used during normal scripts execution, but it may be useful to debug a script by simulating signal delivery.

Function: mbfl_signal_hook_var HOOK_RV SIGNAME

If SIGNAME is a valid signal name: store in the result variable HOOK_RV SIGNAME’s hook data variable, then return true; otherwise return false. If currently there is no SIGNAME’s hook: a new hook is defined.

mbfl_declare_varref(SIGKILL_HOOK)

mbfl_signal_hook_var _(SIGKILL_HOOK) 'SIGKILL'
mbfl_hook_add $SIGKILL_HOOK 'my_signal_handler'

This document describes version 3.0.0-devel.9 of Marcos Bash Functions Library.