From f2eccfdcaf7a808e1968ffab4b4bf095780c880c Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sun, 28 Mar 2010 17:42:40 +0000 Subject: [PATCH] luci-0.9: merge r5973 --- .../luasrc/controller/mini/system.lua | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/modules/admin-mini/luasrc/controller/mini/system.lua b/modules/admin-mini/luasrc/controller/mini/system.lua index 481fbf0f0e..b90205b3ba 100644 --- a/modules/admin-mini/luasrc/controller/mini/system.lua +++ b/modules/admin-mini/luasrc/controller/mini/system.lua @@ -226,3 +226,33 @@ function _keep_pattern() end return kpattern end + +function ltn12_popen(command) + + local fdi, fdo = nixio.pipe() + local pid = nixio.fork() + + if pid > 0 then + fdo:close() + local close + return function() + local buffer = fdi:read(2048) + local wpid, stat = nixio.waitpid(pid, "nohang") + if not close and wpid and stat == "exited" then + close = true + end + + if buffer and #buffer > 0 then + return buffer + elseif close then + fdi:close() + return nil + end + end + elseif pid == 0 then + nixio.dup(fdo, nixio.stdout) + fdi:close() + fdo:close() + nixio.exec("/bin/sh", "-c", command) + end +end -- 2.30.2