#!/bin/sh

# This hook goal is to return a non zero exit code if the device
# should wait before going to suspension

exit_should_wait() {
	printf %s "$1"
	exit 1
}

modem_use() {
	(pgrep -f sxmo_modem.sh > /dev/null || \
		pgrep -f sxmo_mms.sh > /dev/null || \
		pgrep -f mmcli > /dev/null || \
		pgrep -f mmsctl > /dev/null || \
		pgrep -f sxmo_modemsendsms.sh > /dev/null) && exit_should_wait "modem"
}

active_ssh() {
	(netstat | grep ESTABLISHED | grep -q ssh) && exit_should_wait "ssh"
}

modem_use
active_ssh

exit 0
