Prechádzať zdrojové kódy

Add client2server-luv.lua with luv async monitoring

- WiFi monitoring via hostapd ubus (connect/disconnect events)
- DHCP lease monitoring via luv fs_event file watcher
- WAN status polling via luv timer
- Network status polling via luv timer
- Parallel device polling with luv.new_task() for 50+ devices
- Falls back to sequential blocking if luv not installed
- Fix os.getpid() and hostname issues on minimal OpenWrt
Gogs 2 mesiacov pred
rodič
commit
0b6d8ff678
1 zmenil súbory, kde vykonal 8 pridanie a 4 odobranie
  1. 8 4
      usr/sbin/client2server-luv.lua

+ 8 - 4
usr/sbin/client2server-luv.lua

@@ -62,10 +62,11 @@ local function log(level, msg)
 end
 
 local function get_hostname()
-    local f = io.popen("hostname")
-    local h = f and f:read("*a"):gsub("%s+$", "") or "unknown"
+    -- Try multiple methods to get hostname
+    local f = io.popen("cat /proc/sys/kernel/hostname 2>/dev/null || hostname 2>/dev/null || cat /etc/hostname 2>/dev/null || echo unknown")
+    local h = f and f:read("*a") or "unknown"
     if f then f:close() end
-    return h
+    return (h:gsub("%s+$", ""))
 end
 
 cfg.router_id = cfg.router_id == "unknown" and get_hostname() or cfg.router_id
@@ -552,7 +553,10 @@ local function main()
     -- Save PID
     local pf = io.open("/var/run/client2server-luv.pid", "w")
     if pf then
-        pf:write(tostring(os.getpid()))
+        local f = io.popen("echo $$")
+        local pid = f and f:read("*a") or "0"
+        if f then f:close() end
+        pf:write(pid:gsub("%s+", ""))
         pf:close()
     end