summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2013-01-01 15:48:13 +0000
committerTed Trask <ttrask01@yahoo.com>2013-01-01 15:48:13 +0000
commitd7460a8bd3b2fd106957434e2c1ae5135f72fddd (patch)
tree5a49af51dd0258c18c4eaa69b9b60b8bfac7c7cf
parent6d4635f62231fdf787c7e53a0249be8fc67e3a5c (diff)
downloadacf-chrony-d7460a8bd3b2fd106957434e2c1ae5135f72fddd.tar.bz2
acf-chrony-d7460a8bd3b2fd106957434e2c1ae5135f72fddd.tar.xz
Replaced io.popen with modelfunctions.run_executable and subprocess.popen
-rw-r--r--chrony-model.lua48
1 files changed, 29 insertions, 19 deletions
diff --git a/chrony-model.lua b/chrony-model.lua
index 0bc53d5..d63ec63 100644
--- a/chrony-model.lua
+++ b/chrony-model.lua
@@ -6,6 +6,8 @@ format = require("acf.format")
fs = require("acf.fs")
validator = require("acf.validator")
processinfo = require("acf.processinfo")
+require("subprocess")
+require("posix")
-- Set variables
local configfile = "/etc/chrony/chrony.conf"
@@ -89,13 +91,30 @@ function startstop_service(self, startstop, action)
if not password then
startstop.errtxt = "Could not find password in key file"
else
- local cmd = path.."chronyc <<EOF\npassword "..format.escapespecialcharacters(password).."\n"..lower.."\nEOF"
- local f = io.popen(cmd)
- startstop.descr = f:read("*a") or ""
- f:close()
- if (startstop.descr == "") then
- startstop.descr = nil
- startstop.errtxt = "Command failed"
+ local res, err = pcall(function()
+ -- For security, set the path
+ posix.setenv("PATH", "/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin")
+
+ local args = {"chronyc", "-m", "password", lower}
+ args.stdin = subprocess.PIPE
+ args.stdout = subprocess.PIPE
+ args.stderr = "/dev/null"
+ local proc, errmsg, errno = subprocess.popen(args)
+ if proc then
+ proc.stdin:write(password.."\n")
+ proc.stdin:close()
+ proc:wait()
+ startstop.descr = proc.stdout:read("*a")
+ if proc.exitcode ~= 0 then
+ startstop.errtxt = startstop.descr
+ startstop.descr = nil
+ end
+ else
+ startstop.errtxt = errmsg or "Unknown failure"
+ end
+ end)
+ if not res or err then
+ startstop.errtxt = err or "Unknown failure"
end
end
end
@@ -118,18 +137,9 @@ function getdetails()
local pid = processinfo.pidof(processname)
if pid and #pid > 0 then
- local cmd = path.."chronyc sources"
- local f = io.popen(cmd)
- details.sources.value = f:read("*a") or ""
- f:close()
- cmd = path.."chronyc sourcestats"
- f = io.popen(cmd)
- details.sourcestats.value = f:read("*a") or ""
- f:close()
- cmd = path.."chronyc tracking"
- f = io.popen(cmd)
- details.tracking.value = f:read("*a") or ""
- f:close()
+ details.sources.value, details.sources.errtxt = modelfunctions.run_executable({"chronyc", "sources"})
+ details.sourcestats.value, details.sourcestats.errtxt = modelfunctions.run_executable({"chronyc", "sourcestats"})
+ details.tracking.value, details.tracking.errtxt = modelfunctions.run_executable({"chronyc", "tracking"})
end
return cfe({ type="group", value=details, label="Chrony Status Details" })