summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-nlbwmon
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2018-01-17 21:15:47 +0100
committerJo-Philipp Wich <jo@mein.io>2018-01-17 21:15:47 +0100
commit08916f4335e96e4a3c9dcf77262fa151348ed93c (patch)
treea310d1b0b43f6d60ce39e7697a8a0127d35c0956 /applications/luci-app-nlbwmon
parenta441721d32d06d18368bf236ad127ffccad0bef8 (diff)
luci-app-nlbw: fix sporadic premature EOF when rendering JSON data
Specific timing patterns sometimes caused the LuCI controller to prematurely stop reading data, resulting in truncated JSON output. Turn the nonblocking waitpid() call into a blocking call after the IO read loop to avoid this issue. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'applications/luci-app-nlbwmon')
-rw-r--r--applications/luci-app-nlbwmon/luasrc/controller/nlbw.lua11
1 files changed, 6 insertions, 5 deletions
diff --git a/applications/luci-app-nlbwmon/luasrc/controller/nlbw.lua b/applications/luci-app-nlbwmon/luasrc/controller/nlbw.lua
index bb56bc6e6..a8c577929 100644
--- a/applications/luci-app-nlbwmon/luasrc/controller/nlbw.lua
+++ b/applications/luci-app-nlbwmon/luasrc/controller/nlbw.lua
@@ -28,16 +28,17 @@ local function exec(cmd, args, writer)
while true do
local buffer = fdi:read(2048)
- local wpid, stat, code = nixio.waitpid(pid, "nohang")
- if writer and buffer and #buffer > 0 then
- writer(buffer)
+ if not buffer or #buffer == 0 then
+ break
end
- if wpid and stat == "exited" then
- break
+ if writer then
+ writer(buffer)
end
end
+
+ nixio.waitpid(pid)
elseif pid == 0 then
nixio.dup(fdo, nixio.stdout)
fdi:close()