summary refs log tree commit diff
path: root/nixos/modules/system/boot/stage-1-init.sh
diff options
context:
space:
mode:
authorNikolay Amiantov <ab@fmap.me>2016-08-08 01:35:43 +0300
committerNikolay Amiantov <ab@fmap.me>2016-08-08 01:35:43 +0300
commit986a40421a94528c55531719fb382160292c7e16 (patch)
tree3a49182a00d6fdf6042865e7ed27e506dad4a99d /nixos/modules/system/boot/stage-1-init.sh
parent3ae468e8355494dda2e9c28b5d62d3c03bf4ce98 (diff)
downloadnixlib-986a40421a94528c55531719fb382160292c7e16.tar
nixlib-986a40421a94528c55531719fb382160292c7e16.tar.gz
nixlib-986a40421a94528c55531719fb382160292c7e16.tar.bz2
nixlib-986a40421a94528c55531719fb382160292c7e16.tar.lz
nixlib-986a40421a94528c55531719fb382160292c7e16.tar.xz
nixlib-986a40421a94528c55531719fb382160292c7e16.tar.zst
nixlib-986a40421a94528c55531719fb382160292c7e16.zip
nixos stage-1: wait for devices during resumption attempt
Also a microimprovement -- use `test -n` instead of `test -e`
since we have already checked that the file exists.
Diffstat (limited to 'nixos/modules/system/boot/stage-1-init.sh')
-rw-r--r--nixos/modules/system/boot/stage-1-init.sh16
1 files changed, 9 insertions, 7 deletions
diff --git a/nixos/modules/system/boot/stage-1-init.sh b/nixos/modules/system/boot/stage-1-init.sh
index fc50481e0bc8..ef04629d735f 100644
--- a/nixos/modules/system/boot/stage-1-init.sh
+++ b/nixos/modules/system/boot/stage-1-init.sh
@@ -346,7 +346,7 @@ waitDevice() {
 }
 
 
-# Try to resume - all modules are loaded now, and devices exist
+# Try to resume - all modules are loaded now.
 if test -e /sys/power/tuxonice/resume; then
     if test -n "$(cat /sys/power/tuxonice/resume)"; then
         echo 0 > /sys/power/tuxonice/user_interface/enabled
@@ -355,7 +355,7 @@ if test -e /sys/power/tuxonice/resume; then
 fi
 
 if test -e /sys/power/resume -a -e /sys/power/disk; then
-    if test -n "@resumeDevice@"; then
+    if test -n "@resumeDevice@" && waitDevice "@resumeDevice@"; then
         resumeDev="@resumeDevice@"
         resumeInfo="$(udevadm info -q property "$resumeDev" )"
     else
@@ -364,14 +364,16 @@ if test -e /sys/power/resume -a -e /sys/power/disk; then
             # https://bugs.launchpad.net/ubuntu/+source/pm-utils/+bug/923326/comments/1
             # when there are multiple swap devices, we can't know where the hibernate
             # image will reside. We can check all of them for swsuspend blkid.
-            resumeInfo="$(test -e "$sd" && udevadm info -q property "$sd")"
-            if [ "$(echo "$resumeInfo" | sed -n 's/^ID_FS_TYPE=//p')" = "swsuspend" ]; then
-                resumeDev="$sd"
-                break
+            if waitDevice "$sd"; then
+                resumeInfo="$(udevadm info -q property "$sd")"
+                if [ "$(echo "$resumeInfo" | sed -n 's/^ID_FS_TYPE=//p')" = "swsuspend" ]; then
+                    resumeDev="$sd"
+                    break
+                fi
             fi
         done
     fi
-    if test -e "$resumeDev"; then
+    if test -n "$resumeDev"; then
         resumeMajor="$(echo "$resumeInfo" | sed -n 's/^MAJOR=//p')"
         resumeMinor="$(echo "$resumeInfo" | sed -n 's/^MINOR=//p')"
         echo "$resumeMajor:$resumeMinor" > /sys/power/resume 2> /dev/null || echo "failed to resume..."