summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorHans Dedecker <dedeckeh@gmail.com>2017-02-14 11:59:14 +0100
committerHans Dedecker <dedeckeh@gmail.com>2017-02-14 13:38:26 +0100
commita898ee5458950203d4b2f8fec28c85313c855b91 (patch)
treef1b37449b5fd354e31a16c466957472cf4aa5fb1 /src
parent51c756cfc15c63322df9fdb70d5c701cfb6b9a9f (diff)
config: make loglevel configurable via uci (FS#481)
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/config.c15
-rw-r--r--src/odhcpd.c10
-rw-r--r--src/odhcpd.h1
3 files changed, 20 insertions, 6 deletions
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 <libgen.h>
#include <string.h>
#include <sys/stat.h>
+#include <syslog.h>
#include <uci.h>
#include <uci_blob.h>
@@ -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 <unistd.h>
#include <signal.h>
#include <stdbool.h>
+#include <syslog.h>
#include <arpa/inet.h>
#include <net/if.h>
@@ -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;