Добавлена обработка подпроцессов.
[weathermon.git] / lib / wm_util.lua
index bb5d8ee30c158afac1375594be0dc86d67bfd2a0..2c05bb054cb882f6fcfb8d381d44cd442cbfdfb6 100644 (file)
@@ -1,6 +1,9 @@
 #!/usr/bin/lua
 
 local socket = require "socket"
+local lfs = require "lfs"
+local uci = require "uci"
+local posix = require "posix"
 
 function startswith(String,Start)
    if String then
@@ -95,7 +98,6 @@ function split(s, delimiter)
 end
 
 function list_dir(name)
-    local lfs = require "lfs"
     local result = {}
     for name in lfs.dir(name) do
         if not startswith(name,".") then
@@ -104,3 +106,46 @@ function list_dir(name)
     end
     return result
 end
+
+function get_devid(config)
+
+  local web_devid = uci.get(config,"web","devid")
+  
+  if web_devid then
+    return web_devid
+  end  
+    
+  web_iface = uci.get(config,"web","iface")
+  
+  if not web_iface then
+    web_iface = list_dir('/sys/class/net/')[1]
+  end
+  io.input("/sys/class/net/"..web_iface.."/address")
+
+  local web_devid = io.read("*line")
+  return web_devid:gsub(":",""):upper()
+
+end
+
+function get_children()
+
+  local pid = posix.getpid()
+  local pidlist = list_dir('/proc')
+  local pids = {}
+
+  for k,v in pairs(pidlist) do
+
+    pcall( function ()
+      local stats = get_file_content('/proc/'..v..'/stat')
+      local ppid = tonumber(split(stats,' ')[4])
+      if pid == ppid then
+        pids[#pids+1] = tonumber(v)
+      end 
+    end)
+
+  end
+
+  return pids
+
+end