github.com/rootless-containers/rootlesskit/v2@v2.3.4/hack/integration-exit-code.sh (about) 1 #!/bin/bash 2 source $(realpath $(dirname $0))/common.inc.sh 3 4 function test_exit_code() { 5 args="$@" 6 INFO "Testig exit status for args=${args}" 7 set +e 8 for f in 0 42; do 9 $ROOTLESSKIT $args sh -exc "exit $f" >/dev/null 2>&1 10 code=$? 11 if [ $code != $f ]; then 12 ERROR "expected code $f, got $code" 13 exit 1 14 fi 15 done 16 } 17 18 test_exit_code --pidns=false 19 test_exit_code --pidns=true --reaper=auto 20 test_exit_code --pidns=true --reaper=true 21 test_exit_code --pidns=true --reaper=false 22 23 function test_signal() { 24 args="$@" 25 INFO "Testig signal for args=${args}" 26 set +e 27 tmp=$(mktemp -d) 28 $ROOTLESSKIT --state-dir=${tmp}/state $args sleep infinity >${tmp}/out 2>&1 & 29 pid=$! 30 sleep 1 31 kill -SIGUSR1 $(cat ${tmp}/state/child_pid) 32 wait $pid 33 code=$? 34 if [ $code != 255 ]; then 35 ERROR "expected code 255, got $code" 36 exit 1 37 fi 38 if ! grep -q "user defined signal 1" ${tmp}/out; then 39 ERROR "didn't get SIGUSR1?" 40 cat ${tmp}/out 41 exit 1 42 fi 43 rm -rf $tmp 44 } 45 46 test_signal --pidns=false 47 test_signal --pidns=true --reaper=auto 48 test_signal --pidns=true --reaper=true 49 test_signal --pidns=true --reaper=false