Discussion:
[ast-developers] traps vs. nested "function foo"-style functions calls ...
Roland Mainz
2013-06-17 18:06:13 UTC
Permalink
Hi!

----

Does anyone know know a good way (in ksh93 or any other shell (bash,
zsh etc.)) how signal traps and nested calls to "function foo"-style
functions (e.g. functions with a seperate scope) can be mixed ?

The problem is that if I have function "x1" which sets-up a trap for
SIGINT and calls function "x2" which has a seperate function scope
(e.g. was declared via "function x2") the trap for "x1" is reset to
the global trap handler as long as function "x2" runs... which opens a
wide gap for race conditions if asynchronous signals arrive, e.g.
signals from other processes or threads in the same process... this
gap can lead to impractical race conditions if the default behaviour
for the matching signal is to terminate the process or call |abort()|.

AFAIK options are:
1. use the most recent established trap handler, e.g. traps are global
and independent of any function scope (bash4 seems to use this model)
2. defer execution of any traps when other functions are running and
queue them until they return
3. each "function foo-"style function has it's own scope for traps.
The obvious disadvantage is the race condition which exists between
entering the function and setting-up the signal handler trap

----

Bye,
Roland
--
__ . . __
(o.\ \/ /.o) roland.mainz at nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
Loading...