|
|
@@ -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
|
|
|
|