luci-base: rpcd: handle swap entries in getBlockDevices
authorJo-Philipp Wich <jo@mein.io>
Fri, 28 Apr 2023 12:55:09 +0000 (14:55 +0200)
committerJo-Philipp Wich <jo@mein.io>
Fri, 28 Apr 2023 12:55:09 +0000 (14:55 +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>
modules/luci-base/root/usr/share/rpcd/ucode/luci

index f4d204cf228415022c418a91d791778b81772595..35f592578b3a325b1b705644bf30bad3c592f659 100644 (file)
@@ -419,13 +419,33 @@ const methods = {
                                                        size: +readfile(`/sys/class/block/${dev}/size`) * 512
                                                };
 
-                                               for (m in match(line, / (\w+)="([^"]+)"/g))
+                                               for (let m in match(line, / (\w+)="([^"]+)"/g))
                                                        e[lc(m[1])] = m[2];
                                        }
                                }
 
                                block.close();
 
+                               const swaps = open('/proc/swaps', 'r');
+
+                               if (swaps) {
+                                       for (let line = swaps.read('line'); length(line); line = swaps.read('line')) {
+                                               let m = match(line, /^(\/\S+)\s+\S+\s+(\d+)/);
+
+                                               if (m) {
+                                                       let dev = replace(m[1], /\\(\d\d\d)/g, (_, n) => chr(int(n, 8)));
+
+                                                       result[`swap:${m[1]}`] = {
+                                                               dev,
+                                                               type: 'swap',
+                                                               size: +m[2] * 1024
+                                                       };
+                                               }
+                                       }
+
+                                       swaps.close();
+                               }
+
                                return result;
                        }
                        else {