#!/bin/sh -ux
# This script returns success if it itself or a command launched
# by it were killed by SIGTERM signal.

. /bin/shell-error

__term_ok()
{
	exit 0
}

[ $# -ge 1 ] ||	fatal "Usage: ${0##*/} <command> [args]"

cmd="$1"
shift

[ -x "$cmd" ] || fatal "Couldn't find $cmd"

trap __term_ok TERM

$cmd $@ >/dev/null 2>&1
exit_code=$?
# Is it was killed by SIGTERM?
[ $exit_code -eq 143 ] && exit 0 || exit $exit_code
