How can I automatically revert to a snapshot after the guest is stopped?

/etc/libvirt/hooks/qemu
#!/bin/sh
name="$1"
action="$2"
if [ "$name" = "name" ]; then
 virsh snapshot-revert "$name" --snapshotname "snapshot1"
fi

I tried this which resulted in a deadlock, then I saw the warning further down the page.