On Wed, Dec 29, 2021 at 03:07:38AM +0100, Lorenzo wrote: > I'm going to accept a fix for this issue, but I prefer to not have to > parse a file and also to not add another flag file only for this, if > it's possible.
Well, getting the first character from a file and printing it verbatim is hardly "parsing". :) > > #!/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" > > > > Because of #1000867 I'm going to create /run/runit.reboot in stage1, > so can't we just use stat in runlevel script (at least for runlevel 6)? I thought of that, but I don't think it's quite this foolproof. kexec can be critical (for example, if you have an HP raid controller in a non-HP server, recent firmware versions hang during POST depending on BIOS settings, even before entering the BIOS setup, so kexec may be the only way to reboot without taking the computer apart first). You create /run/runit.reboot once at reboot, which could have been years ago; anything might have befallen that file in the meantime. For example, it may not exist anymore, and 'init 6' won't create it, just set its mode if it exists. So far nothing depended on runit.reboot existing and having a "correct" mode outside of runit stage 3. We have no idea what else (other than kexec) depends on the output of runlevel(8) and how. I'd argue that introducing stricter requirements on the existence and correct mode of /run/runit.reboot that apply over the whole uptime of the system is a more dangerous and invasive change than introducing a new control file with semantics that are obvious and well defined from the beginning. But, it's mostly your show: if that's how you want to do it, you obviously can. It'll work for me. > Something like > #!/bin/sh > if [ $(stat -c %a /run/runit.reboot) = 100 ]; then > exec printf 'N 6' > else > exec printf 'N 2' > fi The problem with this is that runit hasn't so far cared about the mode of runit.reboot before stage 3, and people may set runit.reboot to mode 100 early, for example out of a desire to make sure a box will reboot instead of shut down if pid 1 were to receive a CONT signal for any reason. Like I said, I think making the meaning of the mode bits of runit.reboot meaningful in a broader context is dangerous. > Will it work for kexec? It should. (You'll want a 2>/dev/null on the stat(1) invocation for cases where the file doesn't exist, /run isn't mounted etc.) > Also, do we have to cover the 'N 0' shutdown case because of some > other init scripts that you know of? I'm not aware of any, but then I didn't know about kexec a week ago, so this doesn't necessarily mean anything. :) AndrĂ¡s -- What if the lottery was just invented by the government to capture time travelers?