On Tue, Dec 28, 2021 at 03:16:30PM +0100, Andras Korn wrote:
> If /sbin/runlevel looked like this instead:
>
> #!/bin/sh
> # This only does anything useful if /etc/runit/3 updates /run/runit.runlevel
> before starting stop scripts
> if [ -s /run/runit.runlevel ]; then
> CURLEVEL="$(head -c 1 /run/runit.runlevel)"
> else
> CURLEVEL=2
> fi
> exec printf "N $CURLEVEL"
It just occurred to me that technically the above is racy; a non-racy but
less readable solution would be something like
#!/bin/sh
# /etc/runit/3 should update /run/runit.runlevel before starting stop scripts
unset CURLEVEL
CURLEVEL="$(head -c 1 /run/runit.runlevel 2>/dev/null)"
if [ -z "$CURLEVEL" ]; then
CURLEVEL=2
fi
exec printf "N $CURLEVEL"
AndrĂ¡s
--
Expect disappointment and you won't be disappointed.