From: Hans Dedecker Date: Tue, 14 Feb 2017 10:59:14 +0000 (+0100) Subject: config: make loglevel configurable via uci (FS#481) X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=a898ee5458950203d4b2f8fec28c85313c855b91;p=oweals%2Fodhcpd.git config: make loglevel configurable via uci (FS#481) Signed-off-by: Hans Dedecker --- diff --git a/README b/README index 4ae5ef2..8c3b12c 100644 --- a/README +++ b/README @@ -62,6 +62,7 @@ legacy bool 0 Enable DHCPv4 if start but no dhcpv4 option set leasefile string DHCP/v6 lease/hostfile leasetrigger string Lease trigger script +loglevel integer 6 Syslog level priority (0-7) Sections of type dhcp (configure DHCP / DHCPv6 / RA / NDP service) diff --git a/src/config.c b/src/config.c index 5174f2c..69a3ad1 100644 --- a/src/config.c +++ b/src/config.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -16,7 +17,8 @@ static struct blob_buf b; static int reload_pipe[2]; struct list_head leases = LIST_HEAD_INIT(leases); struct list_head interfaces = LIST_HEAD_INIT(interfaces); -struct config config = {false, NULL, NULL}; +struct config config = {.legacy = false, .dhcp_cb = NULL, + .dhcp_statefile = NULL, .log_level = LOG_INFO}; enum { IFACE_ATTR_INTERFACE, @@ -123,6 +125,7 @@ enum { ODHCPD_ATTR_MAINDHCP, ODHCPD_ATTR_LEASEFILE, ODHCPD_ATTR_LEASETRIGGER, + ODHCPD_ATTR_LOGLEVEL, ODHCPD_ATTR_MAX }; @@ -130,6 +133,7 @@ static const struct blobmsg_policy odhcpd_attrs[LEASE_ATTR_MAX] = { [ODHCPD_ATTR_MAINDHCP] = { .name = "maindhcp", .type = BLOBMSG_TYPE_BOOL }, [ODHCPD_ATTR_LEASEFILE] = { .name = "leasefile", .type = BLOBMSG_TYPE_STRING }, [ODHCPD_ATTR_LEASETRIGGER] = { .name = "leasetrigger", .type = BLOBMSG_TYPE_STRING }, + [ODHCPD_ATTR_LOGLEVEL] = { .name = "loglevel", .type = BLOBMSG_TYPE_INT32 }, }; const struct uci_blob_param_list odhcpd_attr_list = { @@ -247,6 +251,15 @@ static void set_config(struct uci_section *s) free(config.dhcp_cb); config.dhcp_cb = strdup(blobmsg_get_string(c)); } + + if ((c = tb[ODHCPD_ATTR_LOGLEVEL])) { + int log_level = (blobmsg_get_u32(c) & LOG_PRIMASK); + + if (config.log_level != log_level) { + config.log_level = log_level; + setlogmask(LOG_UPTO(config.log_level)); + } + } } static double parse_leasetime(struct blob_attr *c) { diff --git a/src/odhcpd.c b/src/odhcpd.c index 9a76e4d..8a18fbf 100644 --- a/src/odhcpd.c +++ b/src/odhcpd.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -52,7 +53,6 @@ static int ioctl_sock; static struct nl_sock *rtnl_socket = NULL; static int urandom_fd = -1; -static int log_level = LOG_INFO; static void sighandler(_unused int signal) { @@ -65,7 +65,7 @@ static void print_usage(const char *app) "== %s Usage ==\n\n" " -h, --help Print this help\n" " -l level Specify log level 0..7 (default %d)\n", - app, log_level + app, config.log_level ); } @@ -80,12 +80,12 @@ int main(int argc, char **argv) print_usage(argv[0]); return 0; case 'l': - log_level = atoi(optarg); - fprintf(stderr, "Log level set to %d\n", log_level); + config.log_level = (atoi(optarg) & LOG_PRIMASK); + fprintf(stderr, "Log level set to %d\n", config.log_level); break; } } - setlogmask(LOG_UPTO(log_level)); + setlogmask(LOG_UPTO(config.log_level)); uloop_init(); if (getuid() != 0) { diff --git a/src/odhcpd.h b/src/odhcpd.h index ceef0bf..8db3e7d 100644 --- a/src/odhcpd.h +++ b/src/odhcpd.h @@ -97,6 +97,7 @@ struct config { bool legacy; char *dhcp_cb; char *dhcp_statefile; + int log_level; } config;