Commit | Line | Data |
---|---|---|
2058ffa5 TM |
1 | -- Returns array with parsed contents of /proc/meminfo |
2 | -- Returns nil on failure | |
3 | function get_meminfo() | |
4 | local r={} | |
5 | local f=io.open("/proc/meminfo","r") | |
6 | if not f then return nil; end | |
7 | local s=f:read("*a") | |
8 | for k,v in string.gmatch(s,"(%w+): *(%d+)") do | |
9 | r[k]=tonumber(v) | |
10 | end | |
11 | f:close() | |
12 | return r | |
13 | end | |
14 | ||
15 | -- Returns 1 when RAM is bad, 0 when RAM is ok | |
16 | -- Returns nil when memtest was not run | |
17 | function memory_bad() | |
18 | local m=get_meminfo() | |
19 | if not m then return nil; end | |
20 | if not m.HardwareCorrupted then return nil; end | |
21 | if not m.EarlyMemtestBad then return nil; end | |
22 | if m.HardwareCorrupted > 0 then return 1; end | |
23 | if m.EarlyMemtestBad > 0 then return 1; end | |
24 | return 0; | |
25 | end | |
26 | ||
27 | m=get_meminfo() | |
28 | print(m.MemTotal, m.MemFree, m.HardwareCorrupted, m.EarlyMemtestBad) | |
29 | print(memory_bad()); |