diff mbox series

[v2] zram-swap: explicitely use mkswap/swapon/swapoff from /sbin

Message ID 20200724150758.15309-1-rsalvaterra@gmail.com
State Superseded
Headers show
Series [v2] zram-swap: explicitely use mkswap/swapon/swapoff from /sbin | expand

Commit Message

Rui Salvaterra July 24, 2020, 3:07 p.m. UTC
The required BusyBox applets are enabled by default, so we can rely on them
being present in the system. This way, we make sure there are no conflicts with
less featured variants of these same applets which might also be present in the
system.

Fixes: 0bd7dfa3ed60588ec83a8f60f48b6991ebb16940

Signed-off-by: Rui Salvaterra <rsalvaterra@gmail.com>
---
 package/system/zram-swap/files/zram.init | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

Comments

Henrique de Moraes Holschuh July 24, 2020, 3:51 p.m. UTC | #1
On 24/07/2020 12:07, Rui Salvaterra wrote:
> The required BusyBox applets are enabled by default, so we can rely on them
> being present in the system. This way, we make sure there are no conflicts with

Hmm, why not fix this for *good* and not depend on they being enabled in 
busybox "by default"?

I'd just depend on the required busybox features and applets explicitly 
(or select them) *on top of what your patch already does*.

While depends and selects are not always effective for busybox features, 
it *is* the proper build-time machine-readable documentation of the 
package requirements...  And it does work for anyone doing full builds.
Rui Salvaterra July 24, 2020, 4:03 p.m. UTC | #2
Hi, Henrique,

On Fri, 24 Jul 2020 at 16:51, Henrique de Moraes Holschuh
<henrique@nic.br> wrote:
>
> Hmm, why not fix this for *good* and not depend on they being enabled in
> busybox "by default"?
>
> I'd just depend on the required busybox features and applets explicitly
> (or select them) *on top of what your patch already does*.
>
> While depends and selects are not always effective for busybox features,
> it *is* the proper build-time machine-readable documentation of the
> package requirements...  And it does work for anyone doing full builds.

Seems like a fine suggestion! I'll send an amended patch soon.

Thanks,
Rui
diff mbox series

Patch

diff --git a/package/system/zram-swap/files/zram.init b/package/system/zram-swap/files/zram.init
index a6126e578f..f31a87438c 100755
--- a/package/system/zram-swap/files/zram.init
+++ b/package/system/zram-swap/files/zram.init
@@ -35,18 +35,18 @@  zram_applicable()
 		return 1
 	}
 
-	which mkswap >/dev/null || {
-		logger -s -t zram_applicable -p daemon.err "[ERROR] 'mkswap' not installed"
+	[ -x /sbin/mkswap ] || {
+		logger -s -t zram_applicable -p daemon.err "[ERROR] 'BusyBox mkswap' not installed"
 		return 1
 	}
 
-	which swapon >/dev/null || {
-		logger -s -t zram_applicable -p daemon.err "[ERROR] 'swapon' not installed"
+	[ -x /sbin/swapon ] || {
+		logger -s -t zram_applicable -p daemon.err "[ERROR] 'BusyBox swapon' not installed"
 		return 1
 	}
 
-	which swapoff >/dev/null || {
-		logger -s -t zram_applicable -p daemon.err "[ERROR] 'swapoff' not installed"
+	[ -x /sbin/swapoff ] || {
+		logger -s -t zram_applicable -p daemon.err "[ERROR] 'BusyBox swapoff' not installed"
 		return 1
 	}
 }
@@ -181,8 +181,8 @@  start()
 	zram_comp_algo "$zram_dev"
 	zram_comp_streams "$zram_dev"
 	echo $(( $zram_size * 1024 * 1024 )) >"/sys/block/$( basename "$zram_dev" )/disksize"
-	mkswap "$zram_dev"
-	swapon -d $zram_priority "$zram_dev"
+	/sbin/mkswap "$zram_dev"
+	/sbin/swapon -d $zram_priority "$zram_dev"
 }
 
 stop()
@@ -191,7 +191,7 @@  stop()
 
 	for zram_dev in $( grep zram /proc/swaps |awk '{print $1}' ); do {
 		logger -s -t zram_stop -p daemon.debug "deactivate swap $zram_dev"
-		swapoff "$zram_dev" && zram_reset "$zram_dev" "claiming memory back"
+		/sbin/swapoff "$zram_dev" && zram_reset "$zram_dev" "claiming memory back"
 		local dev_index="$( echo $zram_dev | grep -o "[0-9]*$" )"
 		if [ $dev_index -ne 0 ]; then
 			logger -s -t zram_stop -p daemon.debug "removing zram $zram_dev"