File: traps.rc

package info (click to toggle)
glusterfs 11.2-2
  • links: PTS
  • area: main
  • in suites: sid
  • size: 28,244 kB
  • sloc: ansic: 471,238; sh: 45,610; python: 16,893; perl: 3,328; makefile: 2,014; yacc: 487; ruby: 171; lisp: 124; xml: 75; lex: 61
file content (22 lines) | stat: -rw-r--r-- 642 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash

# Make sure this only gets included/executed once.  Unfortunately, bash doesn't
# usually distinguish between values that are unset and values that are null.
# To work around that, we declare TRAPFUNCS to be a one-element array right at
# the start, but that one element is : which is defined to do nothing.

if [ ${#TRAPFUNCS[@]} = 0 ]; then
        TRAPFUNCS=(:)

        push_trapfunc () {
                TRAPFUNCS[${#TRAPFUNCS[@]}]="$@"
        }

        execute_trapfuncs () {
                for i in "${TRAPFUNCS[@]}"; do
                        $i
                done
        }

        trap execute_trapfuncs EXIT
fi