#!/usr/bin/env /lib/runit/invoke-run
#Copyright: 2026 Aitor <aitor@genuen.org>
#License: CC0-1.0
#Comment: supervised vdevd (-f early; coldplug promotes same PID)
#Comment: env from stage-1 boot-run (/run/vdev/env); KMS also stage-1
#Comment: vdev-coldplug.sh is a sibling 01-core oneshot (waits for control)

exec 2>&1
if [ -r /run/vdev/env ]; then
	# shellcheck disable=SC1091
	. /run/vdev/env
elif [ -r /lib/vdev/vdev-env.sh ]; then
	# shellcheck disable=SC1091
	. /lib/vdev/vdev-env.sh
else
	exit 162
fi
[ -x "${VDEV_BIN}" ] || exit 162
if [ -w /sys/kernel/uevent_helper ]; then
	echo > /sys/kernel/uevent_helper
fi
[ -x /sbin/restorecon ] && /sbin/restorecon -R "${VDEV_MOUNTPOINT}" || true

export VDEV_JSON_STATE=early
exec "${VDEV_BIN}" -f -c "${VDEV_CONFIG_DIR}/${VDEV_EARLY}" "${VDEV_MOUNTPOINT}"
