The core/cleanup library provides a mechanism for other libraries to register functions that get called when the script exits.
Some libraries need to perform cleanup before exiting. This can include releasing system resources (deleting files, closing sockets, etc.) or reversing temporary side-effects. The cleanup_add() function provided by this library allows registering functions to accomplish that task.
$cleanup_funcs[]
Lists functions to be called upon application exit.
cleanup_init()
Initializes the core/cleanup library.
This function registers an internal function, cleanup_exec(), that will called when the process receives the EXIT signal.
cleanup_add()
Registers a function ($1) that will be called when the application exits.
cleanup_exec()
Called when the process receives the EXIT signal at application exit(). Calls all cleanup functions that were registered with cleanup_add().