My scripts cdist-deploy-to and cdist-mass-deploy (from cdist configuration management) run interactively (i.e. are called by a user).

These scripts call a lot of scripts, which again call some scripts:

cdist-mass-deploy ...
   cdist-deploy-to ...
       cdist-explorer-run-global ...
           cdist-dir ....

What I want is to exit / kill all scripts, as soon as cdist-mass-deploy is either stopped by control C (SIGINT) or killed with SIGTERM.

cdist-deploy-to can also be called interactively and should exhibit the same behaviour.

Using ps -ef... and co variants to find out all processes with the ppid looks like it could be quite unportable. Using $! does not work as in the deeper levels the children are no background processes.

I tried using the following code:

__cdist_kill_on_interrupt()
{
   __cdist_tmp_removal
   kill 0
   exit 1
}

trap __cdist_kill_on_interrupt INT TERM

But this leads to ugly Terminated messages as well as to a segfault in the shells (dash, bash, zsh) and seems not to stop everything instantly anyway:

# cdist-mass-deploy -p ikq04.ethz.ch ikq05.ethz.ch
core: Waiting for cdist-deploy-to jobs to finish
^CTerminated
Terminated
Terminated
Terminated
Segmentation fault

So the question is, how to cleanly exit including all (sub-)children in a portable manner (bourne shell, no csh support needed)?

Edit
Report