system: don't attempt swapon/swapoff in inittab if not available
authorThomas De Schampheleire <thomas.de_schampheleire@nokia.com>
Wed, 5 Feb 2020 12:55:18 +0000 (13:55 +0100)
committerPeter Korsgaard <peter@korsgaard.com>
Wed, 5 Feb 2020 14:57:56 +0000 (15:57 +0100)
The default inittab files added by busybox and sysvinit run 'swapon -a'
during init and 'swapoff -a' during shutdown.

But, the swapon/swapoff programs are not guaranteed to be
available. For the busybox versions, it is steered by
CONFIG_SWAPON/CONFIG_SWAPOFF. For the util-linux versions, it is steered by
BR2_PACKAGE_UTIL_LINUX_BINARIES.

In a case where swapon/swapoff is not available but the inittab tries to
execute them, the boot log would be polluted by error messages like:

    swapon: not found

Avoid this by commenting out the swapon/swapoff lines if the swapon/swapoff
binaries are not available.

Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
[Peter: test with -x]
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
package/busybox/busybox.mk
package/sysvinit/sysvinit.mk
system/system.mk

index 6283bc96ea4ead91f4ebf33c338915452a9a0ffc..45f74271f270ae360afd8f015afef860f7cc3a23 100644 (file)
@@ -226,6 +226,7 @@ endif # BR2_TARGET_GENERIC_GETTY
 BUSYBOX_TARGET_FINALIZE_HOOKS += BUSYBOX_SET_GETTY
 
 BUSYBOX_TARGET_FINALIZE_HOOKS += SYSTEM_REMOUNT_ROOT_INITTAB
+BUSYBOX_TARGET_FINALIZE_HOOKS += SYSTEM_UPDATE_SWAPON_SWAPOFF_INITTAB
 
 endif # BR2_INIT_BUSYBOX
 
index c778a9cde5bd6a0280c0caeddfa452a86f5c12fc..a717ae045924b46ea89a6e5c5a191917d4e4d7cc 100644 (file)
@@ -45,5 +45,6 @@ endif # BR2_TARGET_GENERIC_GETTY
 SYSVINIT_TARGET_FINALIZE_HOOKS += SYSVINIT_SET_GETTY
 
 SYSVINIT_TARGET_FINALIZE_HOOKS += SYSTEM_REMOUNT_ROOT_INITTAB
+SYSVINIT_TARGET_FINALIZE_HOOKS += SYSTEM_UPDATE_SWAPON_SWAPOFF_INITTAB
 
 $(eval $(generic-package))
index 8fe2c138b049b256e7aa600250f95922c1884235..6f1f5c27b19fd0ffebd5f609c7f8060e288e8821 100644 (file)
@@ -96,6 +96,19 @@ define SYSTEM_REMOUNT_ROOT_INITTAB
 endef
 endif
 
+define SYSTEM_UPDATE_SWAPON_SWAPOFF_INITTAB
+       if [ -x $(TARGET_DIR)/sbin/swapon ]; then \
+               $(SED) '\%:/sbin/swapon%s/^#*//' $(TARGET_DIR)/etc/inittab ; \
+       else \
+               $(SED) '\%:/sbin/swapon%s/^#*/#/' $(TARGET_DIR)/etc/inittab ; \
+       fi
+       if [ -x $(TARGET_DIR)/sbin/swapoff ]; then \
+               $(SED) '\%:/sbin/swapoff%s/^#*//' $(TARGET_DIR)/etc/inittab ; \
+       else \
+               $(SED) '\%:/sbin/swapoff%s/^#*/#/' $(TARGET_DIR)/etc/inittab ; \
+       fi
+endef
+
 ifeq ($(BR_BUILDING)$(BR2_SYSTEM_DEFAULT_PATH),y"")
 $(error BR2_SYSTEM_DEFAULT_PATH can't be empty)
 endif