#!/bin/sh

set -e

case "${1}" in
  prereqs)
    echo "udev"
    exit 0
    ;;
esac

. /scripts/functions

# kernel_watchdog_timeout in config.txt makes the firmware leave the
# hardware watchdog running and pass watchdog.open_timeout to the kernel,
# which is an explicit request for continuous coverage until systemd takes
# over. Leave it armed in that case, or if watchdog_disarm=0 is set.
if grep -qE '(^| )(watchdog\.open_timeout=[^ ]*|watchdog_disarm=0)( |$)' /proc/cmdline; then
  exit 0
fi

log_begin_msg "Disarming watchdog..."

if [ -c /dev/watchdog0 ]; then
  echo -n 'V' > /dev/watchdog0
else
  log_warning_msg "Watchdog device not found"
fi

log_end_msg

exit 0
