#!/bin/sh

if profile=`printcontenv S6_RUNTIME_PROFILE` ; then
  etc="/etc/cont-profile.d/$profile"
else
  etc=/etc
fi

if v=`printcontenv S6_VERBOSITY` && eltest "$v" =~ '^[[:digit:]]+$' ; then : ; else
  v=2
fi

if kimeout=`printcontenv S6_KILL_FINISH_MAXTIME` && eltest "$kimeout" =~ '^[[:digit:]]+$' ; then : ; else
  kimeout=0
fi

for file in `s6-ls "$etc/cont-finish.d" 2>/dev/null | s6-sort` ; do
  if test $v -ge 2 ; then
    echo "cont-finish: info: running $etc/cont-finish.d/$file" 1>&2
  fi
  s6-maximumtime -k "$kimeout" "$etc/cont-finish.d/$file"
done

exit 0
