diff --git a/src/confd/src/confd/core.c b/src/confd/src/confd/core.c index fb3e686f..768af713 100644 --- a/src/confd/src/confd/core.c +++ b/src/confd/src/confd/core.c @@ -66,9 +66,18 @@ int core_post_hook(sr_session_ctx_t *session, uint32_t sub_id, const char *modul int sr_plugin_init_cb(sr_session_ctx_t *session, void **priv) { + int log_opts = LOG_USER; int rc = SR_ERR_SYS; + char *env; - openlog("confd", LOG_USER, 0); + /* Convert into command line option+SIGUSR1 when converting to standalone confd */ + env = getenv("DEBUG"); + if (env) { + log_opts |= LOG_PERROR; + debug = 1; + } + + openlog("confd", log_opts, 0); /* Save context with default running config datastore for all our models */ *priv = (void *)&confd; diff --git a/src/confd/src/confd/ietf-interfaces.c b/src/confd/src/confd/ietf-interfaces.c index 7299eded..0cc1bffa 100644 --- a/src/confd/src/confd/ietf-interfaces.c +++ b/src/confd/src/confd/ietf-interfaces.c @@ -814,7 +814,7 @@ static int netdag_gen_vlan(struct dagger *net, struct lyd_node *dif, const char *proto; int err; - DEBUG(""); + DEBUG("ifname %s parent %s", ifname, parent); err = dagger_add_dep(net, ifname, parent); if (err) @@ -844,7 +844,7 @@ static int netdag_gen_vlan(struct dagger *net, struct lyd_node *dif, fprintf(ip, " id %s", vidd.new); fputc('\n', ip); - DEBUG(""); + return 0; } diff --git a/src/confd/src/confd/infix-system-software.c b/src/confd/src/confd/infix-system-software.c index f132dd74..ac308543 100644 --- a/src/confd/src/confd/infix-system-software.c +++ b/src/confd/src/confd/infix-system-software.c @@ -186,7 +186,7 @@ static int infix_system_sw_state(sr_session_ctx_t *session, uint32_t sub_id, RaucInstaller *rauc; struct lyd_node *sw; - DEBUG(""); + DEBUG("%s", path); rauc = infix_system_sw_new_rauc(); if (!rauc) diff --git a/src/confd/src/lib/common.h b/src/confd/src/lib/common.h index d682a88e..33913e11 100644 --- a/src/confd/src/lib/common.h +++ b/src/confd/src/lib/common.h @@ -7,6 +7,9 @@ #include #include #include "srx_module.h" +#include "common.h" + +extern int debug; #ifndef HAVE_VASPRINTF int vasprintf(char **strp, const char *fmt, va_list ap); @@ -15,8 +18,7 @@ int vasprintf(char **strp, const char *fmt, va_list ap); int asprintf(char **strp, const char *fmt, ...); #endif -#define DEBUG(fmt, ...) -//#define DEBUG(fmt, ...) syslog(LOG_DEBUG, "%s: "fmt, __func__, ##__VA_ARGS__) +#define DEBUG(fmt, ...) do { if (debug) syslog(LOG_DEBUG, fmt, ##__VA_ARGS__); } while (0) #define INFO(fmt, ...) syslog(LOG_INFO, fmt, ##__VA_ARGS__) #define ERROR(fmt, ...) syslog(LOG_ERR, "%s: " fmt, __func__, ##__VA_ARGS__) #define ERRNO(fmt, ...) syslog(LOG_ERR, "%s: " fmt ": %s", __func__, ##__VA_ARGS__, strerror(errno)) diff --git a/src/confd/src/lib/helpers.c b/src/confd/src/lib/helpers.c index eb67eccc..0ccade20 100644 --- a/src/confd/src/lib/helpers.c +++ b/src/confd/src/lib/helpers.c @@ -13,6 +13,8 @@ #include #include +int debug; /* Sets debug level (0:off) */ + /* TODO remove once confd / statd lib situation is resolved */ #ifndef vasprintf int vasprintf(char **strp, const char *fmt, va_list ap); diff --git a/src/statd/Makefile b/src/statd/Makefile index 56a93499..87fa589f 100644 --- a/src/statd/Makefile +++ b/src/statd/Makefile @@ -10,7 +10,7 @@ CPPFLAGS := -I$(CONFD_SRC_LIB) TARGET = statd SRC = statd.c LIB_SRC = $(CONFD_SRC_LIB)/helpers.c $(CONFD_SRC_LIB)/lyx.c $(CONFD_LIB)/vasprintf.c -LIB_HDR = $(CONFD_SRC_LIB)/helpers.h $(CONFD_SRC_LIB)/lyx.h +LIB_HDR = $(CONFD_SRC_LIB)/helpers.h $(CONFD_SRC_LIB)/lyx.h $(CONFD_SRC_LIB)/common.h all: $(TARGET) diff --git a/src/statd/statd.c b/src/statd/statd.c index 47a0cf0a..ee206eec 100644 --- a/src/statd/statd.c +++ b/src/statd/statd.c @@ -235,7 +235,7 @@ static int ly_add_ip_link(const struct ly_ctx *ctx, struct lyd_node **parent, ch return SR_ERR_OK; } -static int sr_ifaces_cb(sr_session_ctx_t *session, uint32_t, const char *, +static int sr_ifaces_cb(sr_session_ctx_t *session, uint32_t, const char *path, const char *, const char *, uint32_t, struct lyd_node **parent, void *priv) { @@ -267,11 +267,16 @@ static int sr_ifaces_cb(sr_session_ctx_t *session, uint32_t, const char *, return err; } -static void sig_event_cb(struct ev_loop *loop, struct ev_signal *, int) +static void sigint_cb(struct ev_loop *loop, struct ev_signal *, int) { ev_break(loop, EVBREAK_ALL); } +static void sigusr1_cb(struct ev_loop *, struct ev_signal *, int) +{ + debug ^= 1; +} + static void sr_event_cb(struct ev_loop *, struct ev_io *w, int) { struct sub *sub = (struct sub *)w->data; @@ -442,13 +447,21 @@ static int sub_to_ifaces(struct statd *statd) return SR_ERR_OK; } -int main(void) +int main(int argc, char *argv[]) { - struct ev_signal sig_watcher; + struct ev_signal sigint_watcher, sigusr1_watcher; struct statd statd = {}; + int log_opts = LOG_USER; sr_conn_ctx_t *sr_conn; int err; + if (argc > 1 && !strcmp(argv[1], "-d")) { + log_opts |= LOG_PERROR; + debug = 1; + } + + openlog("statd", log_opts, 0); + TAILQ_INIT(&statd.subs); statd.ev_loop = EV_DEFAULT; @@ -484,9 +497,13 @@ int main(void) return EXIT_FAILURE; } - ev_signal_init(&sig_watcher, sig_event_cb, SIGINT); - sig_watcher.data = &statd; - ev_signal_start(statd.ev_loop, &sig_watcher); + ev_signal_init(&sigint_watcher, sigint_cb, SIGINT); + sigint_watcher.data = &statd; + ev_signal_start(statd.ev_loop, &sigint_watcher); + + ev_signal_init(&sigusr1_watcher, sigusr1_cb, SIGUSR1); + sigusr1_watcher.data = &statd; + ev_signal_start(statd.ev_loop, &sigusr1_watcher); ev_io_init(&statd.nl.watcher, nl_event_cb, statd.nl.sd, EV_READ); statd.nl.watcher.data = &statd;