summaryrefslogtreecommitdiffhomepage
path: root/libs/sys
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2013-01-11 18:16:26 +0000
committerJo-Philipp Wich <jow@openwrt.org>2013-01-11 18:16:26 +0000
commita52a6a4f22861bbb1b7676b91b1f873e09bdbdfd (patch)
tree215c15d0d6f60cc0fea9fce5c2c7a6fc07d2c3ff /libs/sys
parentacd72484366d436e6fd6827209558b552da54126 (diff)
libs/sys: fix luci.sys.processes.list() for entries with spaces i nthe STAT column (#528)
Diffstat (limited to 'libs/sys')
-rw-r--r--libs/sys/luasrc/sys.lua41
1 files changed, 16 insertions, 25 deletions
diff --git a/libs/sys/luasrc/sys.lua b/libs/sys/luasrc/sys.lua
index 825092fff..18622da77 100644
--- a/libs/sys/luasrc/sys.lua
+++ b/libs/sys/luasrc/sys.lua
@@ -695,38 +695,29 @@ end
function process.list()
local data = {}
local k
- local ps = luci.util.execi("top -bn1")
+ local ps = luci.util.execi("/bin/busybox top -bn1")
if not ps then
return
end
- while true do
- local line = ps()
- if not line then
- return
- end
-
- k = luci.util.split(luci.util.trim(line), "%s+", nil, true)
- if k[6] == "%VSZ" then
- k[6] = "%MEM"
- end
- if k[1] == "PID" then
- break
- end
- end
-
for line in ps do
- local row = {}
-
- line = luci.util.trim(line)
- for i, value in ipairs(luci.util.split(line, "%s+", #k-1, true)) do
- row[k[i]] = value
- end
+ local pid, ppid, user, stat, vsz, mem, cpu, cmd = line:match(
+ "^ *(%d+) +(%d+) +(%S.-%S) +([RSDZTW][W ][<N ]) +(%d+) +(%d+%%) +(%d+%%) +(.+)"
+ )
- local pid = tonumber(row[k[1]])
- if pid then
- data[pid] = row
+ local idx = tonumber(pid)
+ if idx then
+ data[idx] = {
+ ['PID'] = pid,
+ ['PPID'] = ppid,
+ ['USER'] = user,
+ ['STAT'] = stat,
+ ['VSZ'] = vsz,
+ ['%MEM'] = mem,
+ ['%CPU'] = cpu,
+ ['COMMAND'] = cmd
+ }
end
end