From 1db30ab57076e8d249a329197eb1820d57abe23b Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Fri, 28 Apr 2023 15:04:43 +0200 Subject: [PATCH] luci-base: rpcd: handle swap entries in getBlockDevices Add entries from `/proc/swaps` to the result array as well in order to let the ui properly deal with swap files. Fixes: #6350 Signed-off-by: Jo-Philipp Wich (backported from commit ad3509bf3bb5dfa79af634c841d584408068fb0a) --- modules/luci-base/root/usr/libexec/rpcd/luci | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/modules/luci-base/root/usr/libexec/rpcd/luci b/modules/luci-base/root/usr/libexec/rpcd/luci index f124512f59..7ce59a3a84 100755 --- a/modules/luci-base/root/usr/libexec/rpcd/luci +++ b/modules/luci-base/root/usr/libexec/rpcd/luci @@ -488,6 +488,30 @@ local methods = { block:close() + local swaps = io.open("/proc/swaps", "r") + if swaps then + while true do + local ln = swaps:read("*l") + if not ln then + break + end + + local dev, s = ln:match("^(/%S+)%s+%S+%s+(%d+)") + if dev and s then + rv["swap:" .. dev] = { + dev = dev:gsub("\\(%d%d%d)", + function(n) + return string.char(tonumber(n, 8)) + end), + size = s * 1024, + type = "swap" + } + end + end + + swaps:close() + end + return rv else return { error = "Unable to execute block utility" } -- 2.30.2