Skip to content

Commit

Permalink
feat(resume): also consider resume= in the cmdline as enabling hibern…
Browse files Browse the repository at this point in the history
…ation

Move getcmdline from dracut-lib.sh to dracut-dev-lib.sh to make it
available on the host as well.

Closes dracutdevs#924
  • Loading branch information
Henrik66 committed Aug 20, 2023
1 parent c08ae40 commit eb7418e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 30 deletions.
14 changes: 12 additions & 2 deletions modules.d/95resume/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

# called by dracut
check() {
# shellcheck source=dracut-dev-lib.sh
. "${dracutsysrootdir}${dracutbasedir}"/modules.d/99base/dracut-dev-lib.sh

swap_on_netdevice() {
local _dev
for _dev in "${swap_devs[@]}"; do
Expand All @@ -10,10 +13,17 @@ check() {
return 1
}

# Only support resume if hibernation is currently on
# Always support resume if specified on the boot command line
# Otherwise only support resume if hibernation is currently on
# and no swap is mounted on a net device
[[ $hostonly ]] || [[ $mount_needs ]] && {
swap_on_netdevice || [[ -f /sys/power/resume && "$(< /sys/power/resume)" == "0:0" ]] || grep -rq '^\|[[:space:]]resume=' /proc/cmdline /etc/cmdline /etc/cmdline.d /etc/kernel/cmdline /usr/lib/kernel/cmdline 2> /dev/null && return 255
# Enable resume if set on command line
for arg in $(getcmdline); do
if [[ $arg == "resume="* ]]; then
return 0
fi
done
swap_on_netdevice || [[ -f /sys/power/resume && "$(< /sys/power/resume)" == "0:0" ]] && return 255
}

return 0
Expand Down
28 changes: 28 additions & 0 deletions modules.d/99base/dracut-dev-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,31 @@ cancel_wait_for_dev() {
/sbin/initqueue --onetime --unique --name daemon-reload systemctl daemon-reload
fi
}

getcmdline() {
local _line
local _i
local CMDLINE_ETC_D
local CMDLINE_ETC
local CMDLINE_PROC
unset _line

if [ -e /etc/cmdline ]; then
while read -r _line || [ -n "$_line" ]; do
CMDLINE_ETC="$CMDLINE_ETC $_line"
done < /etc/cmdline
fi
for _i in /etc/cmdline.d/*.conf; do
[ -e "$_i" ] || continue
while read -r _line || [ -n "$_line" ]; do
CMDLINE_ETC_D="$CMDLINE_ETC_D $_line"
done < "$_i"
done
if [ -e /proc/cmdline ]; then
while read -r _line || [ -n "$_line" ]; do
CMDLINE_PROC="$CMDLINE_PROC $_line"
done < /proc/cmdline
fi
CMDLINE="$CMDLINE_ETC_D $CMDLINE_ETC $CMDLINE_PROC"
printf "%s" "$CMDLINE"
}
28 changes: 0 additions & 28 deletions modules.d/99base/dracut-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,34 +123,6 @@ killall_proc_mountpoint() {
return $_killed
}

getcmdline() {
local _line
local _i
local CMDLINE_ETC_D
local CMDLINE_ETC
local CMDLINE_PROC
unset _line

if [ -e /etc/cmdline ]; then
while read -r _line || [ -n "$_line" ]; do
CMDLINE_ETC="$CMDLINE_ETC $_line"
done < /etc/cmdline
fi
for _i in /etc/cmdline.d/*.conf; do
[ -e "$_i" ] || continue
while read -r _line || [ -n "$_line" ]; do
CMDLINE_ETC_D="$CMDLINE_ETC_D $_line"
done < "$_i"
done
if [ -e /proc/cmdline ]; then
while read -r _line || [ -n "$_line" ]; do
CMDLINE_PROC="$CMDLINE_PROC $_line"
done < /proc/cmdline
fi
CMDLINE="$CMDLINE_ETC_D $CMDLINE_ETC $CMDLINE_PROC"
printf "%s" "$CMDLINE"
}

getarg() {
debug_off
local _deprecated _newoption
Expand Down

0 comments on commit eb7418e

Please sign in to comment.