summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2025-04-02 16:11:50 +0200
committerSimon Rettberg2025-04-02 16:11:50 +0200
commit8910c311a1acf7a9e53667d75d671c28c61e0a25 (patch)
tree96d7cc377011577ca60289b75eaba6d62056e0fd
parent[slx-watchdog] Run after network (guess URL), check if shell was dropped (diff)
downloadsystemd-init-8910c311a1acf7a9e53667d75d671c28c61e0a25.tar.gz
systemd-init-8910c311a1acf7a9e53667d75d671c28c61e0a25.tar.xz
systemd-init-8910c311a1acf7a9e53667d75d671c28c61e0a25.zip
Avoid loading dracut-lib.sh in several scripts
-rwxr-xr-xmodules.d/conf-tgz/hooks/s3-copy-openslx-config.sh1
-rwxr-xr-xmodules.d/copy-initrd/hooks/copy-initramfs-into-newroot.sh1
-rwxr-xr-xmodules.d/dnbd3-rootfs/hooks/copy-dracut-systemd-files-into-newroot.sh4
-rwxr-xr-xmodules.d/slx-dmsetup/hooks/dmsetup-slx-device20
-rwxr-xr-xmodules.d/slx-network/hooks/s3-setup-bootif-network.sh15
5 files changed, 20 insertions, 21 deletions
diff --git a/modules.d/conf-tgz/hooks/s3-copy-openslx-config.sh b/modules.d/conf-tgz/hooks/s3-copy-openslx-config.sh
index bedceb85..c17a8bf6 100755
--- a/modules.d/conf-tgz/hooks/s3-copy-openslx-config.sh
+++ b/modules.d/conf-tgz/hooks/s3-copy-openslx-config.sh
@@ -1,6 +1,5 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
-type emergency_shell >/dev/null 2>&1 || source /lib/dracut-lib.sh
source "/etc/openslx"
diff --git a/modules.d/copy-initrd/hooks/copy-initramfs-into-newroot.sh b/modules.d/copy-initrd/hooks/copy-initramfs-into-newroot.sh
index cdb3f50a..63ba1bd5 100755
--- a/modules.d/copy-initrd/hooks/copy-initramfs-into-newroot.sh
+++ b/modules.d/copy-initrd/hooks/copy-initramfs-into-newroot.sh
@@ -1,6 +1,5 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
-type emergency_shell >/dev/null 2>&1 || source /lib/dracut-lib.sh
# Needed to be able to go back to dracut at system shutdown.
# only do this if there is enough space in /run since systemd decided to limit
diff --git a/modules.d/dnbd3-rootfs/hooks/copy-dracut-systemd-files-into-newroot.sh b/modules.d/dnbd3-rootfs/hooks/copy-dracut-systemd-files-into-newroot.sh
index 007b950d..3eae12f0 100755
--- a/modules.d/dnbd3-rootfs/hooks/copy-dracut-systemd-files-into-newroot.sh
+++ b/modules.d/dnbd3-rootfs/hooks/copy-dracut-systemd-files-into-newroot.sh
@@ -1,7 +1,5 @@
#!/bin/bash
-type emergency_shell &>/dev/null || source /lib/dracut-lib.sh
-
# Copy dnbd3-client too, needed for controlling dnbd0
mkdir -p "${NEWROOT}/opt/openslx/sbin"
cp "$(which dnbd3-client)" "${NEWROOT}/opt/openslx/sbin/dnbd3-client"
@@ -20,6 +18,6 @@ for dir in /run/systemd/system /lib/systemd/system /etc/systemd/system; do
source_path="../${name}"
target_path="${new_systemd_system_unit_path}/initrd.target.wants/${name}"
ln -nfs "$source_path" "$target_path" || \
- warn "Failed to link \"$source_path\" to \"$target_path\"."
+ echo "Failed to link \"$source_path\" to \"$target_path\"." >&2
done
done
diff --git a/modules.d/slx-dmsetup/hooks/dmsetup-slx-device b/modules.d/slx-dmsetup/hooks/dmsetup-slx-device
index 7cf4df64..05a1b823 100755
--- a/modules.d/slx-dmsetup/hooks/dmsetup-slx-device
+++ b/modules.d/slx-dmsetup/hooks/dmsetup-slx-device
@@ -17,15 +17,19 @@
# TODO: Support external keys
# TODO: Put table in file in config.tgz
-type -p emergency_shell || . /lib/dracut-lib.sh
+drop_shell() {
+ . /lib/dracut-lib.sh
+ emergency_shell "$@"
+ exit 1
+}
# for debugging purposes
exec {BASH_XTRACEFD}> /run/openslx/dmsetup.log
set -x
# read-only device to prepare for CoW
-[ -n "$1" ] || emergency_shell "Read-only device was not given!"
-[ -b "$1" ] || emergency_shell "Given device '$1' does not exist or is not block device"
+[ -n "$1" ] || drop_shell "Read-only device was not given!"
+[ -b "$1" ] || drop_shell "Given device '$1' does not exist or is not block device"
declare -g read_only_device="$1"
declare -g read_only_device_sz="$( blockdev --getsz "$1" )"
@@ -285,7 +289,7 @@ ramdisk_fallback() {
local file="$cow_tmpfs/tmpfs-snapshot"
if ! truncate -s "$(( read_only_device_sz * 512 ))" "$file" \
&& ! dd if=/dev/null of="$file" seek="$read_only_device_sz" bs=512; then
- emergency_shell "Failed to allocate RAMdisk CoW file $file."
+ drop_shell "Failed to allocate RAMdisk CoW file $file."
fi
declare -rg writable_device="$( losetup --show --find "$file" )"
local cow_device_candidate="root"
@@ -293,8 +297,7 @@ ramdisk_fallback() {
cow_device_candidate="root.$RANDOM"
done
if [ -z "$writable_device" ] || ! create_snapshot "$cow_device_candidate N" "$writable_device"; then
- emergency_shell "CRITICAL: failed to setup RAMdisk fallback."
- exit 1
+ drop_shell "CRITICAL: failed to setup RAMdisk fallback."
fi
# [noreturn]
finish_setup "$cow_device_candidate" "0" "$read_only_device_sz"
@@ -307,11 +310,10 @@ ramdisk_fallback() {
# THIS FUNCTION MUST NEVER RETURN
finish_setup() {
if [ -z "$1" ] || ! [ -b "/dev/mapper/$1" ]; then
- emergency_shell "'/dev/mapper/$1' not a block device. Failed to setup CoW layer."
- exit 1
+ drop_shell "'/dev/mapper/$1' not a block device. Failed to setup CoW layer."
fi
if ! [[ "$2" =~ ^[0-9]$ ]]; then
- emergency_shell "'$2' not a valid type, 0 or 1 expected."
+ drop_shell "'$2' not a valid type, 0 or 1 expected."
fi
# <size> optional?
{
diff --git a/modules.d/slx-network/hooks/s3-setup-bootif-network.sh b/modules.d/slx-network/hooks/s3-setup-bootif-network.sh
index 75948867..3daa8a2c 100755
--- a/modules.d/slx-network/hooks/s3-setup-bootif-network.sh
+++ b/modules.d/slx-network/hooks/s3-setup-bootif-network.sh
@@ -6,7 +6,11 @@
# It is run inside dracut's initqueue, on settles to detect the
# physical network interface as fast as possible.
-type emergency_shell >/dev/null 2>&1 || . /lib/dracut-lib.sh
+drop_shell() {
+ . /lib/dracut-lib.sh
+ emergency_shell "$@"
+ exit 1
+}
. /run/openslx/network.conf
@@ -16,8 +20,7 @@ _fails=0
while ! [ -e "/sys/class/net/${SLX_PXE_NETIF}/device" ]; do
if (( ++_fails > 30 )); then
echo "Timeout"
- emergency_shell "Boot interface '${SLX_PXE_NETIF}' did not appear"
- exit 1
+ drop_shell "Boot interface '${SLX_PXE_NETIF}' did not appear"
fi
if (( (_fails % 7) == 0 )); then
echo "Triggering udev again..."
@@ -124,8 +127,7 @@ if [ -n "$SLX_BRIDGE" ]; then
# nope, handle
if [ -z "$try" ]; then
- emergency_shell "Failed to setup main network bridge, giving up!"
- exit 1
+ drop_shell "Failed to setup main network bridge, giving up!"
fi
echo "${SLX_BRIDGE}: Failed to setup main network bridge on try $try. Retrying ..."
# delete bridge, inc try and sleep 100ms before trying again
@@ -192,8 +194,7 @@ request_opts+=("-O" "nisdomain")
echo "${MAIN_NETIF}: Running DHCP client..."
for i in 1 1 1 fail; do
if [ "$i" = "fail" ]; then
- emergency_shell "DHCP failed 3 times... cannot continue."
- exit 1
+ drop_shell "DHCP failed 3 times... cannot continue."
fi
udhcpc -t 4 -T 3 -f -n -q \
-i "${MAIN_NETIF}" \