[LEDE-DEV] odhcpd: [PATCH 1/3] enable loglevel setting via envvar ODHCPD_LOG_LEVEL
Karl Palsson
karlp at tweak.net.au
Thu Sep 22 10:32:17 PDT 2016
From: Karl Palsson <karlp at etactica.com>
Currently the loglevel is hardcoded to LOG_WARNING, even though there is
debug log messages. Allow an env var to control the log threshold.
Signed-off-by: Karl Palsson <karlp at etactica.com>
---
src/odhcpd.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/odhcpd.c b/src/odhcpd.c
index 74830ac..c51cfa1 100644
--- a/src/odhcpd.c
+++ b/src/odhcpd.c
@@ -58,7 +58,21 @@ static void sighandler(_unused int signal)
int main()
{
openlog("odhcpd", LOG_PERROR | LOG_PID, LOG_DAEMON);
- setlogmask(LOG_UPTO(LOG_WARNING));
+ char *env_log_level = getenv("ODHCPD_LOG_LEVEL");
+ int log_level = LOG_WARNING;
+ if (env_log_level) {
+ char *end;
+ errno = 0;
+ long temp = strtol(env_log_level, &end, 0);
+ if (end == env_log_level || *end != '\0'
+ || ((temp == LONG_MIN || temp == LONG_MAX) && errno == ERANGE)
+ || (log_level > LOG_DEBUG) || log_level < LOG_EMERG) {
+ syslog(LOG_ERR, "ODHCPD_LOG_LEVEL envvar was invalid");
+ } else {
+ log_level = temp;
+ }
+ }
+ setlogmask(LOG_UPTO(log_level));
uloop_init();
if (getuid() != 0) {
--
2.4.11
More information about the Lede-dev
mailing list