#!/bin/bash
set -u

# Pin PATH rather than rely on sudoers secure_path being set.
PATH=/usr/sbin:/usr/bin:/sbin:/bin
export PATH

usage() {
  echo "usage: unifi-protect-proc-io-read <pid>" >&2
  exit 1
}

[ $# -eq 1 ] || usage

pid="$1"
case "$pid" in
  ''|*[!0-9]*) usage ;;
esac

# Bound the read here: it takes the target's exec_update_lock and the unprivileged caller cannot
# signal this process.
exec /usr/bin/timeout -k 3 5 /bin/cat -- "/proc/$pid/io"
