luci-base: rpcd: handle swap entries in getBlockDevices
authorJo-Philipp Wich <jo@mein.io>
Fri, 28 Apr 2023 13:04:43 +0000 (15:04 +0200)
committerJo-Philipp Wich <jo@mein.io>
Fri, 28 Apr 2023 13:04:43 +0000 (15:04 +0200)
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 <jo@mein.io>
(backported from commit ad3509bf3bb5dfa79af634c841d584408068fb0a)

modules/luci-base/root/usr/libexec/rpcd/luci

index f124512f59a1bfd43e6ac56fcb836d61e6e75958..7ce59a3a842299082b69ecb2b21d37e2ddff44c4 100755 (executable)
@@ -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" }