github.com/rootless-containers/rootlesskit/v2@v2.3.4/hack/integration-systemd-socket-check-env.sh (about)

     1  #!/bin/bash
     2  
     3  set -eu -o pipefail
     4  
     5  OK_FILE=$1
     6  ERR_FILE=$2
     7  EXPECTED_LISTEN_FDS=$3
     8  
     9  fail() {
    10    echo "$@" > "$ERR_FILE"
    11    exit 1
    12  }
    13  
    14  if ! [[ "${LISTEN_FDS:-}" =~ [1-9] ]]; then
    15    fail "LISTEN_FDS (${LISTEN_FDS:-}) is not set or not positive a number."
    16  fi
    17  
    18  if [[ "${LISTEN_FDS:-}" != "${EXPECTED_LISTEN_FDS}" ]]; then
    19    fail "LISTEN_FDS (${LISTEN_FDS}) is not equal to expected ${EXPECTED_LISTEN_FDS}."
    20  fi
    21  
    22  if [[ "${LISTEN_PID}" != "$$" ]]; then
    23    fail "LISTEN_PID (${LISTEN_PID}) is not equal to \$\$ ($$)."
    24  fi
    25  
    26  for ((i=0,fdnum=3; i<LISTEN_FDS; fdnum++, i++)); do
    27    fdpath="/proc/$$/fd/${fdnum}"
    28    if [[ ! -e "$fdpath" ]]; then
    29      fail "FD #${fdnum} does not exists"
    30    fi
    31  done
    32  
    33  touch "${OK_FILE}"