From f3f4030b4ed0734c9810923cac179f52a7fb0c38 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Mon, 26 Jan 2009 21:54:28 +0000 Subject: More work to remove unnecessary popen calls. git-svn-id: svn://svn.alpinelinux.org/acf/openntpd/trunk@1696 ab2d0c66-481e-0410-8bed-d214d4d58bed --- openntpd-model.lua | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'openntpd-model.lua') diff --git a/openntpd-model.lua b/openntpd-model.lua index 5279388..a3dbbae 100644 --- a/openntpd-model.lua +++ b/openntpd-model.lua @@ -15,13 +15,17 @@ local processname = "ntpd" -- LOCAL FUNCTIONS local function last_time_change() - local cmdoutput = {} - local cmd, error = io.popen("cat /var/log/messages | grep ntpd | grep adjusting | tail -1" ,r) - local cmdoutput1,cmdoutput2 = string.match(cmd:read("*a"), "^%s*(%S+%s+%S+%s+%S+%s+).*: (.*)$") - cmd:close() - cmdoutput1 = cmdoutput1 or "(Have no data on updates)" - cmdoutput2 = cmdoutput2 or "" - return cmdoutput1 .. cmdoutput2 + local cmdoutput = "(Have no data on updates)" + local mess = fs.read_file_as_array("/var/log/messages") + for i=table.maxn(mess),1,-1 do + if string.find(mess[i], "ntpd.*adjusting") then + local cmd1,cmd2 = string.match(mess[i], "^%s*(%S+%s+%S+%s+%S+%s+).*: (.*)$") + cmdoutput = cmd1 .. cmd2 + break + end + + end + return cmdoutput end local function validate_config(config) -- cgit v1.2.3