From 68df4daaa9efdaa58d4acaaeafdb15cd3fc3e543 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sun, 8 Nov 2026 18:25:36 -0300 Subject: [PATCH] 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> --- .../xcat/netboot/ubuntu/dracut/xcat-online.sh | 9 ++++++--- .../bats/ubuntu_netboot_root_handler.bats | 20 +++++++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/xCAT-server/share/xcat/netboot/ubuntu/dracut/xcat-online.sh b/xCAT-server/share/xcat/netboot/ubuntu/dracut/xcat-online.sh index 0d7b5f843c..f4e2cc330d 100755 --- a/xCAT-server/share/xcat/netboot/ubuntu/dracut/xcat-online.sh +++ b/xCAT-server/share/xcat/netboot/ubuntu/dracut/xcat-online.sh @@ -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 . if /sbin/xcatroot "$netif" "${netroot:-xcat}" "${NEWROOT:-/sysroot}"; then diff --git a/xCAT-test/bats/ubuntu_netboot_root_handler.bats b/xCAT-test/bats/ubuntu_netboot_root_handler.bats index fc3499401e..192d194b53 100644 --- a/xCAT-test/bats/ubuntu_netboot_root_handler.bats +++ b/xCAT-test/bats/ubuntu_netboot_root_handler.bats @@ -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* ]] +}