2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-20 17:32:15 +00:00

fix(xcat-core): the Ubuntu netboot online hook ends the script that runs it

dracut SOURCES a hook: source_all runs `. "$f" "$@"`. An `exit` in the hook
therefore ends networkd-run.sh, which is the script bringing the network up, so
the early return path would stop network setup on the second interface. A compute
node with three nics on the provisioning network reaches that path.

The hook leaves with `return` now. A case sources it with the marker already
present and asserts the caller still runs; putting `exit` back fails only that
case. Two cases drove the hook with `sh hook.sh` and now source it, which is both
what dracut does and what `return` requires.

dracut's own 98syslog/rsyslogd-start.sh uses `exit` in an online hook, so the
convention is not uniform. `return` is correct for a sourced script and says what
is meant: end this hook, not its caller.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
Daniel Hilst
2026-11-08 18:25:36 -03:00
parent 07651d98b8
commit 68df4daaa9
2 changed files with 24 additions and 5 deletions
@@ -8,12 +8,15 @@
# three seconds in. This hook runs from initqueue/online, which every network module reaches.
type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
# dracut SOURCES a hook -- source_all runs `. "$f" "$@"` -- so `exit` here would end
# networkd-run.sh, the script that is bringing the network up. Leave with `return`.
#
# One interface is enough, and a second call would download the image again.
[ -e /tmp/xcat.rootimg.done ] && exit 0
[ -x /sbin/xcatroot ] || exit 0
[ -e /tmp/xcat.rootimg.done ] && return 0
[ -x /sbin/xcatroot ] || return 0
netif=$1
[ -n "$netif" ] || exit 0
[ -n "$netif" ] || return 0
# dracut calls a netroot handler as <interface> <netroot> <NEWROOT>.
if /sbin/xcatroot "$netif" "${netroot:-xcat}" "${NEWROOT:-/sysroot}"; then
@@ -74,7 +74,7 @@ SH
sed -e 's#/lib/dracut-lib.sh#${BATS_TEST_TMPDIR}/lib/dracut-lib.sh#' \
-e 's#/sbin/xcatroot#${bin}/sbin/xcatroot#g' \
-e 's#/tmp/xcat.rootimg.done#${BATS_TEST_TMPDIR}/done#' '$hook' > ./hook.sh
sh ./hook.sh eth0"
sh -c '. ./hook.sh eth0'"
[ "$status" -eq 0 ]
[ "$(cat "${BATS_TEST_TMPDIR}/called")" = 'eth0 xcat /sysroot' ]
}
@@ -93,7 +93,23 @@ SH
sed -e 's#/lib/dracut-lib.sh#${BATS_TEST_TMPDIR}/lib/dracut-lib.sh#' \
-e 's#/sbin/xcatroot#${bin}/sbin/xcatroot#g' \
-e 's#/tmp/xcat.rootimg.done#${BATS_TEST_TMPDIR}/done#' '$hook' > ./hook.sh
sh ./hook.sh eth0; sh ./hook.sh eth1"
sh -c '. ./hook.sh eth0; . ./hook.sh eth1'"
[ "$status" -eq 0 ]
[ "$(wc -l < "${BATS_TEST_TMPDIR}/count")" -eq 1 ]
}
@test "the hook leaves its caller running, because dracut sources it" {
# source_all runs `. "$f" "$@"`, so an `exit` in a hook ends networkd-run.sh, which is the
# script bringing the network up. The early return path is the one that would do it.
local hook="$MOD/xcat-online.sh"
mkdir -p "${BATS_TEST_TMPDIR}/lib"
printf 'getarg() { return 1; }\n' >"${BATS_TEST_TMPDIR}/lib/dracut-lib.sh"
run env bash -c "
cd '${BATS_TEST_TMPDIR}'
sed -e 's#/lib/dracut-lib.sh#${BATS_TEST_TMPDIR}/lib/dracut-lib.sh#' \
-e 's#/tmp/xcat.rootimg.done#${BATS_TEST_TMPDIR}/done#' '$hook' > ./hook.sh
: > ./done
sh -c '. ./hook.sh eth0; echo CALLER-SURVIVED'"
[ "$status" -eq 0 ]
[[ "$output" == *CALLER-SURVIVED* ]]
}