#!/sbin/openrc-run
# Copyright 2018 Hyperbola Project
# Distributed under the terms of the GNU General Public License v2

. /etc/xen/scripts/hotplugpath.sh

description="Xen driver domain device service"
command="$sbindir/xl"
command_args="devd $XLDEVD_ARGS"
pidfile="$XEN_RUN_DIR/xldevd.pid"

depend() {
	need xencommons
}

start_pre() {
	# not running in Xen dom0 or domU
	if ! test -d /proc/xen ; then
		exit 0
	fi

	# mount xenfs in dom0 or domU with a pv_ops kernel
	if test "x$1" = xstart && \
		! test -f /proc/xen/capabilities && \
		! grep '^xenfs ' /proc/mounts >/dev/null;
	then
		mount -t xenfs xenfs /proc/xen
	fi

	# run this script only in domU:
	# no capabilities file in xenlinux domU kernel
	# empty capabilities file in pv_ops domU kernel
	if ! test -f /proc/xen/capabilities || \
		grep -q "control_d" /proc/xen/capabilities ; then
		exit 0
	fi
}
