Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
smpirun: Raise the same signal we received
authorGabriel Corona <gabriel.corona@loria.fr>
Tue, 25 Aug 2015 07:35:48 +0000 (09:35 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Tue, 25 Aug 2015 07:35:48 +0000 (09:35 +0200)
src/smpi/smpirun.in

index e9e2b43..18a29d8 100755 (executable)
@@ -69,6 +69,8 @@ HOSTFILETMP=0
 
 unset pid
 
 
 unset pid
 
+trapped_signals="HUP INT QUIT ILL ABRT SEGV FPE ALRM TERM USR1 USR2 BUS"
+
 smpirun_cleanup()
 {
   if [ -z "${KEEP}" ] ; then
 smpirun_cleanup()
 {
   if [ -z "${KEEP}" ] ; then
@@ -92,17 +94,28 @@ smpirun_cleanup()
 }
 
 smpirun_trap() {
 }
 
 smpirun_trap() {
+  local sig
+  sig="$1"
+
+  # Cleanup and kill the child process:
   smpirun_cleanup
   if ! [ -z "$pid" ]; then
     kill -TERM $pid
   fi
   unset pid
   smpirun_cleanup
   if ! [ -z "$pid" ]; then
     kill -TERM $pid
   fi
   unset pid
-  trap - HUP INT QUIT ILL ABRT SEGV FPE ALRM TERM USR1 USR2 BUS
+
+  # Raise the same signal again (remove the traps first):
+  trap - $trapped_signals
+  kill -$sig $$
+
+  # This should never happen:
+  kill -ABRT $$
   kill -TERM $$
   kill -TERM $$
-  exit 128
 }
 
 }
 
-trap smpirun_trap HUP INT QUIT ILL ABRT SEGV FPE ALRM TERM USR1 USR2 BUS
+for s in $trapped_signals; do
+  trap "smpirun_trap $s" $s
+done
 
 while true; do
     case "$1" in
 
 while true; do
     case "$1" in