From: stephan b. <sg...@us...> - 2004-12-24 11:40:00
|
Update of /cvsroot/pclasses/pclasses2/toc/sbin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9471 Modified Files: toc_core.sh Log Message: Added toc_atexit() Index: toc_core.sh =================================================================== RCS file: /cvsroot/pclasses/pclasses2/toc/sbin/toc_core.sh,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- toc_core.sh 22 Dec 2004 19:04:25 -0000 1.1 +++ toc_core.sh 24 Dec 2004 11:39:44 -0000 1.2 @@ -160,6 +160,40 @@ return 0 } +######################################################################## +# _TOC_ATEXIT holds the path to this app's "atexit" code, which is +# executed at app exit. +_TOC_ATEXIT=$TOP_SRCDIR}/.toc.atexit.sh +trap 'echo "rm $_TOC_ATEXIT" >> $_TOC_ATEXIT; $SHELL $_TOC_ATEXIT; exit;' 0 1 2 3 +# ^^^^^ the 'exit' in the trap is to force a SIGINT/SIGHUP to cause an exit. +# On a trap 0 the exit is redundant yet harmless. +######################################################################## +# toc_atexit() is used to provide 'trap' functionality within the TOC framework. +# Client code should NEVER use trap directly, because trap does not offer +# a way to append trap commands. i.e., if clients add a trap they will override +# the framework's trap, which won't be nice. +# $@ must be a list of commands to run at app shutdown. +# Returns 0 unless there is a usage error, in which case it returns non-zero. +# Note that complex string quoting will probably not survive the quote-conversion +# process involved in function calls and parameter passing, so if you need to +# run complex commands at exit, send them to a script and then register that +# script to be run via toc_atexit(). +# +# Commands are run in the order they are registered, NOT in reverse order +# (as in C's atexit()). +# +# NEVER call exit from within atexit code! +toc_atexit() +{ + toc_debug toc_atexit "$@" + test "x" = "x$1" && { + echo "toc_atexit() usage error: \$@ must contain commands to run at app shutdown." + return 1 + } + echo "$@" >> $_TOC_ATEXIT + return 0 +} + toc_dump_make_properties () { # Dumps the current properties from the makefile array to stdout |