confd,statd: add support for enabling DEBUG log messages at runtime

- add debug flag to trigger DEBUG() statements
 - DEBUG() macro needs 'path' argument

For statd we can add support for an optional '-d' command line option to
trigger, and SIGUSR1 to toggle, debug mode.  TBD for confd which still
remains to be refactored into the same standalone daemon as statd.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2023-08-07 00:28:04 +02:00
committed by Tobias Waldekranz
parent f40e747fbd
commit 1afc2adcfc
7 changed files with 44 additions and 14 deletions
+10 -1
View File
@@ -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;
+2 -2
View File
@@ -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;
}
+1 -1
View File
@@ -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)
+4 -2
View File
@@ -7,6 +7,9 @@
#include <sysrepo.h>
#include <sysrepo.h>
#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))
+2
View File
@@ -13,6 +13,8 @@
#include <sys/wait.h>
#include <libite/lite.h>
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);
+1 -1
View File
@@ -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)
+24 -7
View File
@@ -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;