#!/bin/sh
exec 2>&1
# ConditionPathIsReadWrite=/sys, as udevd: with read-only /sys the unit
# records /run/svctl/skipped/mdevd, reports readiness and stays down until
# its next start
if awk '$2 == "/sys" { split($4, o, ","); if (o[1] == "ro") f = 1 } END { exit !f }' /proc/self/mounts; then
	mkdir -p /run/svctl/skipped
	printf '%s\n' 'ro /sys' >"/run/svctl/skipped/.mdevd.$$" && mv -f "/run/svctl/skipped/.mdevd.$$" /run/svctl/skipped/mdevd
	echo "mdevd: skipped (/sys read-only)"
	s6-svc -O .
	echo >&3
	exit 0
fi
rm -f /run/svctl/skipped/mdevd
# the control socket that udevd of the initrd leaves behind makes libdevmapper
# (cryptsetup, lvm) wait for udev
rm -f /run/udev/control
exec mdevd -D 3 -O 4 -b 200000
