From b437cd58826ebb97ea127febfad6eed7eaa897f3 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Fri, 25 Jan 2008 07:34:08 +0000 Subject: More bugfixes caused by a missing or empty config-file git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@646 ab2d0c66-481e-0410-8bed-d214d4d58bed --- syslog-model.lua | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'syslog-model.lua') diff --git a/syslog-model.lua b/syslog-model.lua index 6fa4bce..2e7cae2 100644 --- a/syslog-model.lua +++ b/syslog-model.lua @@ -4,6 +4,7 @@ require("fs") require("procps") require("getopts") require("format") +require("daemoncontrol") local configfile = "/etc/conf.d/syslog" local config = {} @@ -26,6 +27,10 @@ end -- ################################################################################ -- PUBLIC FUNCTIONS +function startstop_service ( self, state ) + return daemoncontrol.daemoncontrol("syslog", state) +end + function getstatus() local opts = getconfig() local status = {} @@ -43,29 +48,32 @@ end function get_filedetails() local filedetails = {} local path = configfile + filedetails.details = {path=path, size="0",mtime=""} + filedetails.content = "" if (fs.is_file(path)) then filedetails.details = fs.stat(path) filedetails.content = fs.read_file(path) - else - filedetails.details = {path="File is missing", size="0",mtime=""} - filedetails.content = "" end return filedetails end function getconfig() + local config = {} + config['SYSLOGD_OPTS']={} local errors = {} errors["SYSLOGD_OPTS"] = {} errors["KLOGD_OPTS"] = {} if (fs.is_file(configfile)) then - config = getopts.getoptsfromfile(configfile) + config = getopts.getoptsfromfile(configfile) or config else - config['SYSLOGD_OPTS']={} + errors["configfile"] = "Config file '".. configfile .. "' is missing!" end + -- Next section is to set/show default values when a option is not configured in the configfile config["SYSLOGD_OPTS"]["-O"] = config["SYSLOGD_OPTS"]["-O"] or "/var/log/messages" config["SYSLOGD_OPTS"]["-l_list"] = getloglevels() config["SYSLOGD_OPTS"]["-R"] = config["SYSLOGD_OPTS"]["-R"] or "" config["SYSLOGD_OPTS"]["-s"] = config["SYSLOGD_OPTS"]["-s"] or "" config["SYSLOGD_OPTS"]["-b"] = config["SYSLOGD_OPTS"]["-b"] or "" + -- Next section is to print errormessages when configs are wrong if (config["SYSLOGD_OPTS"]["-l"]) and ((tonumber(config["SYSLOGD_OPTS"]["-l"]) == nil) or (tonumber(config["SYSLOGD_OPTS"]["-l"]) > 8)) then errors["SYSLOGD_OPTS"]["-l"] = "Log value is out of range. Please select one of the above." -- cgit v1.2.3