summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2010-03-28 17:42:05 +0000
committerJo-Philipp Wich <jow@openwrt.org>2010-03-28 17:42:05 +0000
commit876b33a1dd3baa9afc3b4fca4d13db47012423d5 (patch)
treee03ddd549de66335daf78a0bacfb66faf8e36b81
parent564649cb9286ad4f24c1d5446591deb16de8965e (diff)
modules/admin-mini: add missing ltn12_popen()
-rw-r--r--modules/admin-mini/luasrc/controller/mini/system.lua30
1 files changed, 30 insertions, 0 deletions
diff --git a/modules/admin-mini/luasrc/controller/mini/system.lua b/modules/admin-mini/luasrc/controller/mini/system.lua
index 44d0688f6..e562af028 100644
--- a/modules/admin-mini/luasrc/controller/mini/system.lua
+++ b/modules/admin-mini/luasrc/controller/mini/system.lua
@@ -218,3 +218,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