src/confd: refactor, expose flags arg to change subscrie

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2023-04-02 16:24:08 +02:00
parent 405e1f1b70
commit af5c5bc3d2
2 changed files with 10 additions and 13 deletions
+7 -8
View File
@@ -25,12 +25,12 @@
#define ERROR(frmt, ...) syslog(LOG_ERR, "%s: " frmt, __func__, ##__VA_ARGS__)
#define ERRNO(frmt, ...) syslog(LOG_ERR, "%s: " frmt ": %s", __func__, ##__VA_ARGS__, strerror(errno))
#define REGISTER_CHANGE(s,x,c,a,u) \
if (rc = register_change(s, x, c, a, u))\
#define REGISTER_CHANGE(s,m,x,f,c,a,u) \
if (rc = register_change(s, m, x, f, c, a, u)) \
goto err
#define REGISTER_RPC(s,x,c,a,u) \
if (rc = register_rpc(s, x, c, a, u)) \
#define REGISTER_RPC(s,x,c,a,u) \
if (rc = register_rpc(s, x, c, a, u)) \
goto err
struct confd {
@@ -41,11 +41,10 @@ struct confd {
augeas *aug;
};
static inline int register_change(sr_session_ctx_t *session, const char *xpath,
sr_module_change_cb cb, void *arg, sr_subscription_ctx_t **sub)
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 rc = sr_module_change_subscribe(session, "ietf-system", xpath, cb, arg, 0,
SR_SUBSCR_DEFAULT | SR_SUBSCR_ENABLED, sub);
int rc = sr_module_change_subscribe(session, module, xpath, cb, arg, 0, flags | SR_SUBSCR_DEFAULT, sub);
if (rc)
ERROR("failed subscribing to changes of %s: %s", xpath, sr_strerror(rc));
return rc;
+3 -5
View File
@@ -466,15 +466,13 @@ int ietf_system_init(struct confd *confd)
if (rc != SR_ERR_OK)
goto err;
REGISTER_CHANGE(confd->session, "ietf-system", "/ietf-system:system/hostname", 0, change_hostname, confd, &confd->sub);
REGISTER_CHANGE(confd->session, "ietf-system", "/ietf-system:system/ntp", 0, change_ntp, confd, &confd->sub);
REGISTER_RPC(confd->session, "/ietf-system:system-restart", rpc_exec, "reboot", &confd->sub);
REGISTER_RPC(confd->session, "/ietf-system:system-shutdown", rpc_exec, "poweroff", &confd->sub);
REGISTER_RPC(confd->session, "/ietf-system:set-current-datetime", rpc_set_datetime, NULL, &confd->sub);
REGISTER_CHANGE(confd->session, "/ietf-system:system/hostname", change_hostname, NULL, &confd->sub);
REGISTER_CHANGE(confd->session, "/ietf-system:system/ntp", change_ntp, NULL, &confd->sub);
DEBUG("init ok");
return SR_ERR_OK;
err:
ERROR("init failed: %s", sr_strerror(rc));