From d9f2f2c8f961a0b8e39c7dde4fe9a45f351715a7 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Thu, 13 Feb 2025 07:16:02 +0100 Subject: [PATCH] confd: refactor core_post_hook() - Reduce complexity - Change type, simplify - Allow errors from initctl Signed-off-by: Joachim Wiberg --- src/confd/src/core.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/confd/src/core.c b/src/confd/src/core.c index ccd2d681..c2c98865 100644 --- a/src/confd/src/core.c +++ b/src/confd/src/core.c @@ -56,7 +56,7 @@ int core_pre_hook(sr_session_ctx_t *session, uint32_t sub_id, const char *module int core_post_hook(sr_session_ctx_t *session, uint32_t sub_id, const char *module, const char *xpath, sr_event_t event, unsigned request_id, void *priv) { - static int num_changes = 0; + static size_t num_changes = 0; switch (event) { case SR_EV_CHANGE: @@ -66,15 +66,10 @@ int core_post_hook(sr_session_ctx_t *session, uint32_t sub_id, const char *modul num_changes = 0; return SR_ERR_OK; case SR_EV_DONE: - if (num_changes <= 0) { - ERROR("BUG in core_post_hook(): callback tracking out of sync"); - abort(); - } - - if (--num_changes == 0) - break; - - return SR_ERR_OK; + num_changes--; + if (num_changes > 0) + return SR_ERR_OK; + break; default: ERROR("core_post_hook() should not be called with event %s", ev2str(event)); return SR_ERR_SYS; @@ -87,7 +82,7 @@ int core_post_hook(sr_session_ctx_t *session, uint32_t sub_id, const char *modul if (systemf("runlevel >/dev/null 2>&1")) return SR_ERR_OK; - if (systemf("initctl -nbq reload")) + if (systemf("initctl -b reload")) return SR_ERR_SYS; return SR_ERR_OK;