package/skeleton-init-sysv: conditionally enable swapon/swapoff in inittab
authorCarlos Santos <unixmania@gmail.com>
Fri, 7 Feb 2020 22:33:22 +0000 (19:33 -0300)
committerPeter Korsgaard <peter@korsgaard.com>
Sat, 8 Feb 2020 19:17:57 +0000 (20:17 +0100)
The default inittab files added by busybox and sysvinit runs 'swapon -a'
during init and 'swapoff -a' during shutdown, but those programs are not
guaranteed to be available, so the boot log may become polluted by error
messages like this:

    swapon: not found

Add a target-finalize hook to skeleton-init-sysv that enables or disables
the swapon/swapoff lines in /etc/inittab, depending on the existence of
$(TARGET_DIR)/sbin/swap{on,off}.

Based on a previous patch sent by Thomas De Schampheleire.

Signed-off-by: Carlos Santos <unixmania@gmail.com>
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
package/skeleton-init-sysv/skeleton-init-sysv.mk

index c89c2dc1fdc830ba8f180c7d336480396bcc92bb..009dc100ea54fee0f8b5ca7f45ba890bc8d54695 100644 (file)
@@ -19,4 +19,15 @@ define SKELETON_INIT_SYSV_INSTALL_TARGET_CMDS
        $(call SYSTEM_RSYNC,$(SKELETON_INIT_SYSV_PKGDIR)/skeleton,$(TARGET_DIR))
 endef
 
+# enable/disable swapon/off calls depending on availability of the commands
+define SKELETON_INIT_SYSV_SWAPON_SWAPOFF_INITTAB
+       if [ -x $(TARGET_DIR)/sbin/swapon -a -x $(TARGET_DIR)/sbin/swapoff ]; then \
+               $(SED) '/^#.*\/sbin\/swap/s/^#\+[[:blank:]]*//' $(TARGET_DIR)/etc/inittab; \
+       else \
+               $(SED) '/^[^#].*\/sbin\/swap/s/^/#/' $(TARGET_DIR)/etc/inittab; \
+       fi
+endef
+
+SKELETON_INIT_SYSV_TARGET_FINALIZE_HOOKS += SKELETON_INIT_SYSV_SWAPON_SWAPOFF_INITTAB
+
 $(eval $(generic-package))