Skip to contentSkip to conversation

initscripts: check if swapon/swapoff exists before executing them

PATCH New Ming Liu 1 participant 1 message May 26, 2016

lore
Share & tools
lore

Ming Liu

author
#0 lore raw

PATCH v2 1/1 initscripts: check if swapon/swapoff exists before executing them

From: Ming Liu <[email protected]>

Not all built images contain swapon/swapoff, for instance, it is configurable with or without them in busybox. So it'd better to check if they exist or not before executing them.

Redirecting the potential errors to /dev/null is not good enough, which might suppress the *real* errors.

---
 meta/recipes-core/initscripts/initscripts-1.0/checkroot.sh | 2 +-
 meta/recipes-core/initscripts/initscripts-1.0/mountall.sh  | 2 +-
 meta/recipes-core/initscripts/initscripts-1.0/umountfs     | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
meta/recipes-core/initscripts/initscripts-1.0/checkroot.sh +1 -1
index dfee2af..02f0351 100755
@@ -69,7 +69,7 @@ fi
 # before fsck, since fsck can be quite memory-hungry.
 #
 test "$VERBOSE" != no && echo "Activating swap"
-swapon -a 2> /dev/null
+[ -x /sbin/swapon ] && swapon -a
 
 #
 # Check the root filesystem.
meta/recipes-core/initscripts/initscripts-1.0/mountall.sh +1 -1
index 94bae42..c719be5 100755
@@ -33,7 +33,7 @@ kill -USR1 1
 # Execute swapon command again, in case we want to swap to
 # a file on a now mounted filesystem.
 #
-swapon -a 2> /dev/null
+[ -x /sbin/swapon ] && swapon -a
 
 : exit 0
 
meta/recipes-core/initscripts/initscripts-1.0/umountfs +1 -1
index 61324c6..7fb5c58 100755
@@ -12,7 +12,7 @@
 PATH=/sbin:/bin:/usr/sbin:/usr/bin
 
 echo "Deactivating swap..."
-swapoff -a
+[ -x /sbin/swapoff ] && swapoff -a
 
 # We leave /proc mounted.
 echo "Unmounting local filesystems..."
Signature · 1 line
1.9.1