From 9951da394abb71c6542f91031ac3a9fab04193bd Mon Sep 17 00:00:00 2001 From: Martin Buck Date: Mon, 6 Jan 2025 12:47:33 +0100 Subject: [PATCH 1/2] lib: Try to open 5424 log destination when changing log threshold When changing the log threshold (prio_min) using zlog_5424_apply_meta(), try to open the log destination using zlog_5424_open() if we haven't done so before. Without this, we might never open the destination at all, because when zlog_5424_apply_dst() gets called (which so far was the only initial caller of zlog_5424_open()), chances are that prio_min is still at its initial value of ZLOG_DISABLED, causing it to skip the call to zlog_5424_open(). Signed-off-by: Martin Buck --- lib/zlog_5424.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/zlog_5424.c b/lib/zlog_5424.c index 4c60d4b405..c8586a1a02 100644 --- a/lib/zlog_5424.c +++ b/lib/zlog_5424.c @@ -1076,9 +1076,17 @@ bool zlog_5424_apply_dst(struct zlog_cfg_5424 *zcf) bool zlog_5424_apply_meta(struct zlog_cfg_5424 *zcf) { + int fd; + frr_with_mutex (&zcf->cfg_mtx) { if (zcf->active) - zlog_5424_cycle(zcf, zcf->active->fd); + fd = zcf->active->fd; + else if (zcf->prio_min != ZLOG_DISABLED) + fd = zlog_5424_open(zcf, -1); + else + fd = -1; + if (fd >= 0) + zlog_5424_cycle(zcf, fd); } return true; From 59ee9d2a796ea9ad4fc55ee5df69fd6b0218a887 Mon Sep 17 00:00:00 2001 From: Martin Buck Date: Mon, 6 Jan 2025 15:35:30 +0100 Subject: [PATCH 2/2] lib: Handle call to zlog_5424_cycle() without valid FD properly In zlog_5424_cycle(), struct zlt_5424 *zlt only points to valid memory when the passed file descriptor is >= 0 (and passing -1 seems to be a supported use case). So we shouldn't try to compute the address of its zt member when zlt is NULL. Signed-off-by: Martin Buck --- lib/zlog_5424.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/zlog_5424.c b/lib/zlog_5424.c index c8586a1a02..6265ce3b1f 100644 --- a/lib/zlog_5424.c +++ b/lib/zlog_5424.c @@ -782,7 +782,7 @@ static void zlog_5424_cycle(struct zlog_cfg_5424 *zcf, int fd) } old = zcf->active ? &zcf->active->zt : NULL; - old = zlog_target_replace(old, &zlt->zt); + old = zlog_target_replace(old, zlt ? &zlt->zt : NULL); zcf->active = zlt; /* oldt->fd == fd happens for zlog_5424_apply_meta() */