From 3b3cadd72d3ec262c3872e437bacdcd86ecd9f0a Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Fri, 12 May 2023 15:42:45 +0200 Subject: [PATCH] src/confd: simplify after review comments from wkz Signed-off-by: Joachim Wiberg --- src/confd/src/core.c | 19 +++++++++---------- src/confd/src/core.h | 5 ++--- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/confd/src/core.c b/src/confd/src/core.c index cfc5091e..04652ca2 100644 --- a/src/confd/src/core.c +++ b/src/confd/src/core.c @@ -5,12 +5,10 @@ static struct confd confd; -static uint32_t hook_prio = CB_PRIO_PASSIVE; -static int num_changes; -static int cur_change; - uint32_t core_hook_prio(void) { + static uint32_t hook_prio = CB_PRIO_PASSIVE; + return hook_prio--; } @@ -31,13 +29,17 @@ int core_startup_save(sr_session_ctx_t *session, uint32_t sub_id, const char *mo int core_commit_done(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; + switch (event) { - case SR_EV_UPDATE: + case SR_EV_CHANGE: num_changes++; return SR_ERR_OK; + case SR_EV_ABORT: + num_changes = 0; + return SR_ERR_OK; case SR_EV_DONE: - cur_change++; - if (cur_change == num_changes) + if (--num_changes == 0) break; return SR_ERR_OK; default: @@ -45,9 +47,6 @@ int core_commit_done(sr_session_ctx_t *session, uint32_t sub_id, const char *mod return SR_ERR_SYS; } - /* reset for next changeset */ - num_changes = cur_change = 0; - /* skip reload in bootstrap, implicit reload in runlevel change */ if (systemf("runlevel >/dev/null 2>&1")) return SR_ERR_OK; diff --git a/src/confd/src/core.h b/src/confd/src/core.h index 2e913fa3..f016a21f 100644 --- a/src/confd/src/core.h +++ b/src/confd/src/core.h @@ -78,7 +78,6 @@ int core_startup_save (sr_session_ctx_t *, uint32_t, const char *, const ch static inline int register_change(sr_session_ctx_t *session, const char *module, const char *xpath, int flags, sr_module_change_cb cb, void *arg, sr_subscription_ctx_t **sub) { - int hook_flags = SR_SUBSCR_UPDATE | SR_SUBSCR_DONE_ONLY | SR_SUBSCR_PASSIVE; struct confd *confd = (struct confd *)arg; int rc; @@ -98,9 +97,9 @@ static inline int register_change(sr_session_ctx_t *session, const char *module, */ if (!flags) { sr_module_change_subscribe(confd->session, module, xpath, core_commit_done, NULL, - core_hook_prio(), hook_flags, sub); + core_hook_prio(), SR_SUBSCR_PASSIVE, sub); sr_module_change_subscribe(confd->startup, module, xpath, core_startup_save, NULL, - core_hook_prio(), hook_flags, sub); + core_hook_prio(), SR_SUBSCR_PASSIVE, sub); } return 0;