From 431f445b87284a84d7a567f0dc4788c38941d022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= Date: Mon, 23 Nov 2026 14:47:38 +0100 Subject: [PATCH] sysrepo: report errors from done callbacks to the caller MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit confd applies most of a change in SR_EV_DONE. When that fails, e.g., dagger cannot set an address or create an interface, the old patch only failed the event processing in confd. sysrepocfg, the CLI and RESTCONF still got a success, and a startup-config that could not be applied left the device half configured, without users. The new patch returns the callback error to the caller with the data still written. A failed startup-config now ends in failure-config. The series is regenerated from the fork, hence the header changes in the other patches. Signed-off-by: Mattias Walström --- doc/ChangeLog.md | 2 + ...add-support-for-running-in-foregroun.patch | 5 +- ...NE-to-return-any-error-to-sysrepocfg.patch | 90 ---- ...rom-done-callbacks-to-the-originator.patch | 491 ++++++++++++++++++ ...3-Allow-to-copy-from-factory-default.patch | 9 +- ...sysrepoctl-to-install-factory-config.patch | 7 +- ...e-new-log-level-SEC-for-audit-trails.patch | 5 +- ...ail-for-high-priority-system-changes.patch | 15 +- ...sr_shmsub_listen_thread-exit-process.patch | 9 +- .../5.2.27/0008-Cross-compile-fixes.patch | 5 +- ...kfifo-set-sysrepo-group-if-available.patch | 7 +- ...factory_config-take-the-context-lock.patch | 8 +- 12 files changed, 533 insertions(+), 120 deletions(-) delete mode 100644 patches/sysrepo/5.2.27/0002-Allow-SR_EV_DONE-to-return-any-error-to-sysrepocfg.patch create mode 100644 patches/sysrepo/5.2.27/0002-Report-errors-from-done-callbacks-to-the-originator.patch diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index d0fbf81a9..8cb71a42b 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -184,6 +184,8 @@ All notable changes to the project are documented in this file. configured channel - Wi-Fi interfaces could be renamed at boot, e.g., to `wlan123`, so their configuration was not applied +- A configuration change that could not be applied, e.g., an address + refused by the kernel, was reported as successful - Changing the mode of a Wi-Fi interface, e.g., from station to mesh point, made the whole configuration change fail to apply, although the commit was reported as successful diff --git a/patches/sysrepo/5.2.27/0001-sysrepo-plugind-add-support-for-running-in-foregroun.patch b/patches/sysrepo/5.2.27/0001-sysrepo-plugind-add-support-for-running-in-foregroun.patch index e292d9367..fccf36095 100644 --- a/patches/sysrepo/5.2.27/0001-sysrepo-plugind-add-support-for-running-in-foregroun.patch +++ b/patches/sysrepo/5.2.27/0001-sysrepo-plugind-add-support-for-running-in-foregroun.patch @@ -1,9 +1,10 @@ -From a705ffbcaf48f5c79ad82b4901d327b8ec273853 Mon Sep 17 00:00:00 2001 +From b6ea3c12482936e7ee3d40b07010413f828c740e Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Tue, 28 Mar 2023 10:37:53 +0200 -Subject: [PATCH 1/9] sysrepo-plugind: add support for running in foreground +Subject: [PATCH 01/10] sysrepo-plugind: add support for running in foreground with syslog Organization: Wires +Organization: Wires Signed-off-by: Joachim Wiberg --- diff --git a/patches/sysrepo/5.2.27/0002-Allow-SR_EV_DONE-to-return-any-error-to-sysrepocfg.patch b/patches/sysrepo/5.2.27/0002-Allow-SR_EV_DONE-to-return-any-error-to-sysrepocfg.patch deleted file mode 100644 index b6dd22896..000000000 --- a/patches/sysrepo/5.2.27/0002-Allow-SR_EV_DONE-to-return-any-error-to-sysrepocfg.patch +++ /dev/null @@ -1,90 +0,0 @@ -From 316d7851500f30b42424e6a8d89e66d4f346f2dd Mon Sep 17 00:00:00 2001 -From: Joachim Wiberg -Date: Tue, 7 May 2024 15:41:53 +0200 -Subject: [PATCH 2/9] Allow SR_EV_DONE to return any error to sysrepocfg -Organization: Wires - -Importing a system configuration with sysrepocfg the model callbacks do -their best to validate the configuration and prepare the transaction in -SR_EV_CHANGE. In cases when dealing with a complex system, like adding -a route, address, or other change using iproute2, we may still get into -trouble when actually sending off the transaction in SR_EV_DONE. - -If something does go wrong we'd like to know this by the exit code of -sysrepocfg, not by inspecting logs or expected system state. - -This patch is a clumsy way of forcing the (first) error to bubble up to -the surface and cause a non-zero exit code from sysrepocfg. - -Signed-off-by: Joachim Wiberg ---- - src/shm_sub.c | 22 ++++++++++++++++++---- - 1 file changed, 18 insertions(+), 4 deletions(-) - -diff --git a/src/shm_sub.c b/src/shm_sub.c -index 38b189ef..3fe8c8e6 100644 ---- a/src/shm_sub.c -+++ b/src/shm_sub.c -@@ -3587,7 +3587,7 @@ sr_shmsub_change_listen_relock(sr_sub_shm_t *sub_shm, sr_lock_mode_t mode, struc - sr_error_info_t * - sr_shmsub_change_listen_process_module_events(struct modsub_change_s *change_subs, sr_conn_ctx_t *conn) - { -- sr_error_info_t *err_info = NULL; -+ sr_error_info_t *err_info = NULL, *err_tmp = NULL; - uint32_t i, data_len = 0; - char *data = NULL, *shm_data_ptr; - int ret = SR_ERR_OK, filter_valid; -@@ -3609,7 +3609,6 @@ sr_shmsub_change_listen_process_module_events(struct modsub_change_s *change_sub - } - } - if (i == change_subs->sub_count) { -- /* no new module event */ - goto cleanup; - } - -@@ -3715,6 +3714,11 @@ process_event: - } - break; - } -+ } else if (sub_info.event == SR_SUB_EV_DONE) { -+ if (ret && err_code == SR_ERR_OK) { -+ /* unexpected, callback actually failed, save for later. */ -+ err_code = ret; -+ } - } - - /* subscription processed this event, decrease subscriber count right away for possible later abort event */ -@@ -3747,6 +3751,11 @@ process_event: - } - break; - case SR_SUB_EV_DONE: -+ if (err_code) { -+ /* prepare unexepected error from session to be written to SHM */ -+ sr_errinfo_new(&err_info, err_code, "Oups, error detected in SR_EV_DONE"); -+ } -+ break; - case SR_SUB_EV_ABORT: - /* nothing to do */ - break; -@@ -3769,14 +3778,19 @@ process_event: - - /* SUB WRITE URGE LOCK */ - if (sr_shmsub_change_listen_relock(sub_shm, SR_LOCK_WRITE_URGE, &sub_info, change_sub, change_subs->module_name, -- ret, filter_valid, ev_sess, &err_info)) { -+ ret, filter_valid, ev_sess, &err_tmp)) { -+ if (err_tmp) -+ err_info = err_tmp; - goto cleanup; - } - sub_lock = SR_LOCK_WRITE_URGE; - - /* finish event */ -- err_info = sr_shmsub_listen_write_event(sub_shm, 0, err_code, &shm_data_sub, data, data_len, -+ err_tmp = sr_shmsub_listen_write_event(sub_shm, 0, err_code, &shm_data_sub, data, data_len, - change_subs->module_name, err_code ? "fail" : "success"); -+ if (err_tmp) { -+ err_info = err_tmp; -+ } - } else { - SR_LOG_DBG("EV LISTEN: \"%s\" \"%s\" ID %" PRIu32 " priority %" PRIu32 " success (remaining %" PRIu32 " subscribers).", - change_subs->module_name, sr_ev2str(sub_info.event), sub_info.operation_id, sub_info.priority, diff --git a/patches/sysrepo/5.2.27/0002-Report-errors-from-done-callbacks-to-the-originator.patch b/patches/sysrepo/5.2.27/0002-Report-errors-from-done-callbacks-to-the-originator.patch new file mode 100644 index 000000000..fe232054e --- /dev/null +++ b/patches/sysrepo/5.2.27/0002-Report-errors-from-done-callbacks-to-the-originator.patch @@ -0,0 +1,491 @@ +From db7a855c1c4f2f3b98d507b9b6492d5e35ebf14e Mon Sep 17 00:00:00 2001 +From: Mattias Walström +Date: Mon, 23 Nov 2026 14:07:31 +0100 +Subject: [PATCH 02/10] Report errors from "done" callbacks to the originator +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit +Organization: Wires +Organization: Wires + +Applying a change can still fail in SR_EV_DONE, for example when the +system is reconfigured there. The caller needs to see that in the +return code instead of having to read the logs. + +The earlier attempt made the subscriber fail its own event processing, +the originator never saw the error. + +Signed-off-by: Mattias Walström +--- + src/executables/srpd_rotation.c | 13 ++- + src/shm_sub.c | 143 +++++++++++++++++++++++--------- + src/shm_types.h | 1 + + src/sysrepo.c | 10 +-- + tests/test_apply_changes.c | 113 +++++++++++++++++++++++++ + 5 files changed, 231 insertions(+), 49 deletions(-) + +diff --git a/src/executables/srpd_rotation.c b/src/executables/srpd_rotation.c +index acfe4b33..b9e17733 100644 +--- a/src/executables/srpd_rotation.c ++++ b/src/executables/srpd_rotation.c +@@ -272,7 +272,7 @@ srpd_rotation_change_cb(sr_session_ctx_t *session, uint32_t UNUSED(sub_id), cons + const char *UNUSED(xpath), sr_event_t UNUSED(event), uint32_t UNUSED(request_id), void *private_data) + { + srpd_rotation_data_t *data = (srpd_rotation_data_t *)private_data; +- int rc = SR_ERR_OK, t_creat = 0; ++ int rc = SR_ERR_OK, r, t_creat = 0; + time_t time_value; + sr_change_iter_t *iter = NULL; + sr_change_oper_t oper; +@@ -342,6 +342,7 @@ srpd_rotation_change_cb(sr_session_ctx_t *session, uint32_t UNUSED(sub_id), cons + } + if (rc == -1) { + SRPLG_LOG_ERR(SRPD_PLUGIN_NAME, "asprintf() failed (%s:%d) (%s)", __FILE__, __LINE__, strerror(errno)); ++ rc = SR_ERR_NO_MEMORY; + goto cleanup; + } + ATOMIC_PTR_STORE_RELAXED(data->output_folder, dir_str); +@@ -357,12 +358,18 @@ srpd_rotation_change_cb(sr_session_ctx_t *session, uint32_t UNUSED(sub_id), cons + } + } + ++ if (rc != SR_ERR_NOT_FOUND) { ++ goto cleanup; ++ } ++ rc = SR_ERR_OK; ++ + /* check whether a thread should be created */ + if (t_creat) { + assert(ATOMIC_PTR_LOAD_RELAXED(data->output_folder)); + ATOMIC_STORE_RELAXED(data->running, 1); +- if ((rc = pthread_create(&(data->tid), NULL, &srpd_rotation_loop, data))) { +- SRPLG_LOG_ERR(SRPD_PLUGIN_NAME, "Pthread create failed (%s).", strerror(rc)); ++ if ((r = pthread_create(&(data->tid), NULL, &srpd_rotation_loop, data))) { ++ SRPLG_LOG_ERR(SRPD_PLUGIN_NAME, "Pthread create failed (%s).", strerror(r)); ++ rc = SR_ERR_SYS; + } + t_creat = 0; + } +diff --git a/src/shm_sub.c b/src/shm_sub.c +index 38b189ef..9c70e408 100644 +--- a/src/shm_sub.c ++++ b/src/shm_sub.c +@@ -432,6 +432,51 @@ event_handled: + return NULL; + } + ++/** ++ * @brief Read callback errors written by a subscriber into sub data SHM. ++ * ++ * @param[in] ptr Pointer to the errors in sub data SHM. ++ * @param[in,out] cb_err_info Error info to add the errors to. ++ */ ++static void ++sr_shmsub_notify_read_error(const char *ptr, sr_error_info_t **cb_err_info) ++{ ++ sr_error_t err_code; ++ const char *err_msg, *err_format, *err_data; ++ uint32_t i, err_count; ++ ++ /* error count */ ++ err_count = *((uint32_t *)ptr); ++ ptr += SR_SHM_SIZE(sizeof err_count); ++ ++ for (i = 0; i < err_count; ++i) { ++ /* error code */ ++ err_code = *((sr_error_t *)ptr); ++ ptr += SR_SHM_SIZE(sizeof err_code); ++ ++ /* error message */ ++ err_msg = ptr; ++ ptr += sr_strshmlen(err_msg); ++ ++ /* error data format */ ++ err_format = ptr; ++ ptr += sr_strshmlen(err_format); ++ if (!err_format[0]) { ++ err_format = NULL; ++ } ++ ++ /* error data */ ++ err_data = ptr; ++ ptr += SR_SHM_SIZE(sr_ev_data_size(err_data)); ++ if (!err_format) { ++ err_data = NULL; ++ } ++ ++ /* add into err_info structure */ ++ sr_errinfo_add(cb_err_info, err_code, err_format, err_data, err_msg, NULL); ++ } ++} ++ + /** + * @brief Having WRITE lock, wait for subscribers to handle a generated event. + * +@@ -464,10 +509,8 @@ _sr_shmsub_notify_wait_wr(sr_sub_shm_t *sub_shm, sr_sub_event_t event, uint32_t + int *lock_lost, sr_error_info_t **cb_err_info) + { + sr_error_info_t *err_info = NULL; +- sr_error_t err_code; +- const char *ptr, *err_msg, *err_format, *err_data; + sr_sub_event_t last_event; +- uint32_t last_request_id, i, err_count; ++ uint32_t last_request_id; + int ret, write_lock = 0; + struct timespec timeout_abs2; + +@@ -576,38 +619,7 @@ event_handled: + break; + case SR_SUB_EV_ERROR: + /* create error structure from the information in data SHM */ +- ptr = shm_data_sub->addr; +- +- /* error count */ +- err_count = *((uint32_t *)ptr); +- ptr += SR_SHM_SIZE(sizeof err_count); +- +- for (i = 0; i < err_count; ++i) { +- /* error code */ +- err_code = *((sr_error_t *)ptr); +- ptr += SR_SHM_SIZE(sizeof err_code); +- +- /* error message */ +- err_msg = ptr; +- ptr += sr_strshmlen(err_msg); +- +- /* error data format */ +- err_format = ptr; +- ptr += sr_strshmlen(err_format); +- if (!err_format[0]) { +- err_format = NULL; +- } +- +- /* error data */ +- err_data = ptr; +- ptr += SR_SHM_SIZE(sr_ev_data_size(err_data)); +- if (!err_format) { +- err_data = NULL; +- } +- +- /* add into err_info structure */ +- sr_errinfo_add(cb_err_info, err_code, err_format, err_data, err_msg, NULL); +- } ++ sr_shmsub_notify_read_error(shm_data_sub->addr, cb_err_info); + + if (clear_ev_on_err) { + /* clear the error */ +@@ -620,6 +632,18 @@ event_handled: + sr_ev2str(last_event), sr_ev2str(expected_ev)); + return err_info; + } ++ } else if ((expected_ev == SR_SUB_EV_FINISHED) && (last_event == SR_SUB_EV_ERROR)) { ++ /* the event was processed but a "done" callback failed, its error follows the event data */ ++ if (!sub_shm->err_data_off || (sub_shm->err_data_off >= shm_data_sub->size)) { ++ sr_errinfo_new(&err_info, SR_ERR_INTERNAL, "Invalid sub SHM \"%s\" error offset %" PRIu32 ".", ++ sr_ev2str(event), sub_shm->err_data_off); ++ return err_info; ++ } ++ sr_shmsub_notify_read_error(shm_data_sub->addr + sub_shm->err_data_off, cb_err_info); ++ ++ /* clear it */ ++ ATOMIC_STORE_RELAXED(sub_shm->event, SR_SUB_EV_NONE); ++ sub_shm->orig_cid = 0; + } else { + /* we expect a finished or none event */ + if (ATOMIC_LOAD_RELAXED(sub_shm->event) == expected_ev) { +@@ -825,6 +849,7 @@ sr_shmsub_notify_write_event(sr_sub_shm_t *sub_shm, sr_cid_t orig_cid, uint32_t + ATOMIC_STORE_RELAXED(sub_shm->priority, priority); + ATOMIC_STORE_RELAXED(sub_shm->subscriber_count, subscriber_count); + sub_shm->operation_id = operation_id; ++ sub_shm->err_data_off = 0; + + /* remap if needed */ + if (xpath || data_len) { +@@ -3360,11 +3385,34 @@ sr_shmsub_listen_write_event(sr_sub_shm_t *sub_shm, uint32_t valid_subscr_count, + { + sr_error_info_t *err_info = NULL; + sr_sub_event_t event; ++ uint32_t err_off; + + assert(ATOMIC_LOAD_RELAXED(sub_shm->subscriber_count) >= valid_subscr_count); + + event = ATOMIC_LOAD_RELAXED(sub_shm->event); + ++ if (event == SR_SUB_EV_DONE) { ++ if (err_code && data && data_len && !sub_shm->err_data_off) { ++ /* first failed callback, append the error after the event data, other subscribers may still need them */ ++ if ((err_info = sr_shmsub_data_open_remap(NULL, NULL, -1, shm_data_sub, 0))) { ++ return err_info; ++ } ++ err_off = SR_SHM_SIZE(shm_data_sub->size); ++ if ((err_info = sr_shmsub_data_open_remap(NULL, NULL, -1, shm_data_sub, err_off + data_len))) { ++ return err_info; ++ } ++ memcpy(shm_data_sub->addr + err_off, data, data_len); ++ sub_shm->err_data_off = err_off; ++ } ++ ++ if (ATOMIC_LOAD_RELAXED(sub_shm->subscriber_count) == valid_subscr_count) { ++ /* last subscriber finished, the changes are applied so the event cannot fail, only report an error */ ++ ATOMIC_STORE_RELAXED(sub_shm->event, sub_shm->err_data_off ? SR_SUB_EV_ERROR : SR_SUB_EV_FINISHED); ++ } ++ ATOMIC_SUB_RELAXED(sub_shm->subscriber_count, valid_subscr_count); ++ goto print; ++ } ++ + if ((ATOMIC_LOAD_RELAXED(sub_shm->subscriber_count) == valid_subscr_count) || err_code) { + /* last subscriber finished or an error, update event */ + switch (event) { +@@ -3379,9 +3427,8 @@ sr_shmsub_listen_write_event(sr_sub_shm_t *sub_shm, uint32_t valid_subscr_count, + ATOMIC_STORE_RELAXED(sub_shm->event, SR_SUB_EV_SUCCESS); + } + break; +- case SR_SUB_EV_DONE: + case SR_SUB_EV_ABORT: +- /* notifier waits for these events to clear them and make shm ready for next notification */ ++ /* notifier waits for this event to clear it and make shm ready for next notification */ + assert(!err_code); + ATOMIC_STORE_RELAXED(sub_shm->event, SR_SUB_EV_FINISHED); + break; +@@ -3409,6 +3456,7 @@ sr_shmsub_listen_write_event(sr_sub_shm_t *sub_shm, uint32_t valid_subscr_count, + memcpy(shm_data_sub->addr, data, data_len); + } + ++print: + SR_LOG_DBG("EV LISTEN: \"%s\" \"%s\" ID %" PRIu32 " priority %" PRIu32 " %s (remaining %" PRIu32 " subscribers).", + event_desc, sr_ev2str(event), sub_shm->operation_id, (uint32_t)ATOMIC_LOAD_RELAXED(sub_shm->priority), + result_str, (uint32_t)ATOMIC_LOAD_RELAXED(sub_shm->subscriber_count)); +@@ -3588,7 +3636,7 @@ sr_error_info_t * + sr_shmsub_change_listen_process_module_events(struct modsub_change_s *change_subs, sr_conn_ctx_t *conn) + { + sr_error_info_t *err_info = NULL; +- uint32_t i, data_len = 0; ++ uint32_t i, data_len = 0, valid_subscr_count = 0; + char *data = NULL, *shm_data_ptr; + int ret = SR_ERR_OK, filter_valid; + sr_lock_mode_t sub_lock = SR_LOCK_NONE; +@@ -3717,8 +3765,19 @@ process_event: + } + } + +- /* subscription processed this event, decrease subscriber count right away for possible later abort event */ +- ATOMIC_DEC_RELAXED(sub_shm->subscriber_count); ++ if ((sub_info.event == SR_SUB_EV_DONE) && filter_valid && ret && !err_code) { ++ /* the changes are applied but the callback failed, report the first such error to the originator */ ++ err_code = ret; ++ if ((err_info = sr_shmsub_prepare_error(err_code, ev_sess, &data, &data_len))) { ++ goto cleanup; ++ } ++ ++ /* keep this subscriber counted until the error is written, the event must not be finished without it */ ++ valid_subscr_count = 1; ++ } else { ++ /* subscription processed this event, decrease subscriber count right away for possible later abort event */ ++ ATOMIC_DEC_RELAXED(sub_shm->subscriber_count); ++ } + + /* remember request ID and event so that we do not process it again */ + ATOMIC_STORE_RELAXED(change_sub->request_id, ATOMIC_LOAD_RELAXED(sub_shm->request_id)); +@@ -3747,6 +3806,8 @@ process_event: + } + break; + case SR_SUB_EV_DONE: ++ /* any error was already prepared */ ++ break; + case SR_SUB_EV_ABORT: + /* nothing to do */ + break; +@@ -3775,7 +3836,7 @@ process_event: + sub_lock = SR_LOCK_WRITE_URGE; + + /* finish event */ +- err_info = sr_shmsub_listen_write_event(sub_shm, 0, err_code, &shm_data_sub, data, data_len, ++ err_info = sr_shmsub_listen_write_event(sub_shm, valid_subscr_count, err_code, &shm_data_sub, data, data_len, + change_subs->module_name, err_code ? "fail" : "success"); + } else { + SR_LOG_DBG("EV LISTEN: \"%s\" \"%s\" ID %" PRIu32 " priority %" PRIu32 " success (remaining %" PRIu32 " subscribers).", +diff --git a/src/shm_types.h b/src/shm_types.h +index 9539b21a..38f06894 100644 +--- a/src/shm_types.h ++++ b/src/shm_types.h +@@ -381,6 +381,7 @@ typedef struct { + ATOMIC_T priority; /**< Priority of the subscriber. */ + ATOMIC_T subscriber_count; /**< Number of subscribers to process this event. */ + uint32_t operation_id; /**< Operation ID for the callback. */ ++ uint32_t err_data_off; /**< Offset in data SHM of the error of a failed "done" callback, 0 if none. */ + } sr_sub_shm_t; + + #endif /* _SHM_TYPES_H */ +diff --git a/src/sysrepo.c b/src/sysrepo.c +index 49f52d29..56c1fbae 100644 +--- a/src/sysrepo.c ++++ b/src/sysrepo.c +@@ -1127,8 +1127,8 @@ sr_session_set_error(sr_session_ctx_t *session, const char *err_format_name, sr_ + va_list vargs; + + SR_CHECK_ARG_APIRET(!session || ((session->ev != SR_SUB_EV_CHANGE) && (session->ev != SR_SUB_EV_UPDATE) && +- (session->ev != SR_SUB_EV_OPER) && (session->ev != SR_SUB_EV_RPC)) || !err_code || !err_msg_format, +- session, err_info); ++ (session->ev != SR_SUB_EV_DONE) && (session->ev != SR_SUB_EV_OPER) && (session->ev != SR_SUB_EV_RPC)) || !err_code || ++ !err_msg_format, session, err_info); + + va_start(vargs, err_msg_format); + sr_errinfo_add(&session->ev_err_info, err_code, err_format_name, NULL, err_msg_format, &vargs); +@@ -1144,7 +1144,7 @@ sr_session_set_error_message(sr_session_ctx_t *session, const char *format, ...) + va_list vargs; + + SR_CHECK_ARG_APIRET(!session || ((session->ev != SR_SUB_EV_CHANGE) && (session->ev != SR_SUB_EV_UPDATE) && +- (session->ev != SR_SUB_EV_OPER) && (session->ev != SR_SUB_EV_RPC)) || !format, session, err_info); ++ (session->ev != SR_SUB_EV_DONE) && (session->ev != SR_SUB_EV_OPER) && (session->ev != SR_SUB_EV_RPC)) || !format, session, err_info); + + va_start(vargs, format); + sr_errinfo_add(&session->ev_err_info, SR_ERR_OPERATION_FAILED, NULL, NULL, format, &vargs); +@@ -1160,7 +1160,7 @@ sr_session_set_error_format(sr_session_ctx_t *session, const char *error_format) + char *err_format; + + SR_CHECK_ARG_APIRET(!session || ((session->ev != SR_SUB_EV_CHANGE) && (session->ev != SR_SUB_EV_UPDATE) && +- (session->ev != SR_SUB_EV_OPER) && (session->ev != SR_SUB_EV_RPC)) || !session->ev_err_info, session, err_info); ++ (session->ev != SR_SUB_EV_DONE) && (session->ev != SR_SUB_EV_OPER) && (session->ev != SR_SUB_EV_RPC)) || !session->ev_err_info, session, err_info); + + if (error_format) { + if (!(err_format = strdup(error_format))) { +@@ -1183,7 +1183,7 @@ sr_session_push_error_data(sr_session_ctx_t *session, uint32_t size, const void + sr_error_info_t *err_info = NULL; + + SR_CHECK_ARG_APIRET(!session || ((session->ev != SR_SUB_EV_CHANGE) && (session->ev != SR_SUB_EV_UPDATE) && +- (session->ev != SR_SUB_EV_OPER) && (session->ev != SR_SUB_EV_RPC)) || !session->ev_err_info || ++ (session->ev != SR_SUB_EV_DONE) && (session->ev != SR_SUB_EV_OPER) && (session->ev != SR_SUB_EV_RPC)) || !session->ev_err_info || + !session->ev_err_info->err[session->ev_err_info->err_count - 1].error_format || !size || !data, session, err_info); + + err_info = sr_ev_data_push(&session->ev_err_info->err[session->ev_err_info->err_count - 1].error_data, size, data); +diff --git a/tests/test_apply_changes.c b/tests/test_apply_changes.c +index a2db91fd..c6273c3d 100644 +--- a/tests/test_apply_changes.c ++++ b/tests/test_apply_changes.c +@@ -8533,6 +8533,118 @@ test_change_enabled_race(void **state) + pthread_join(tid[1], NULL); + } + ++/* TEST */ ++static int ++module_done_fail_cb(sr_session_ctx_t *session, uint32_t sub_id, const char *module_name, const char *xpath, ++ sr_event_t event, uint32_t request_id, void *private_data) ++{ ++ struct state *st = (struct state *)private_data; ++ ++ (void)sub_id; ++ (void)module_name; ++ (void)xpath; ++ (void)request_id; ++ ++ assert_int_equal(event, SR_EV_DONE); ++ ATOMIC_INC_RELAXED(st->cb_called); ++ ++ sr_session_set_error(session, NULL, SR_ERR_OPERATION_FAILED, "Done callback failed."); ++ return SR_ERR_OPERATION_FAILED; ++} ++ ++static int ++module_done_ok_cb(sr_session_ctx_t *session, uint32_t sub_id, const char *module_name, const char *xpath, ++ sr_event_t event, uint32_t request_id, void *private_data) ++{ ++ struct state *st = (struct state *)private_data; ++ ++ (void)session; ++ (void)sub_id; ++ (void)module_name; ++ (void)xpath; ++ (void)request_id; ++ ++ assert_int_equal(event, SR_EV_DONE); ++ ATOMIC_INC_RELAXED(st->cb_called2); ++ return SR_ERR_OK; ++} ++ ++static void ++test_done_fail(void **state) ++{ ++ struct state *st = (struct state *)*state; ++ sr_subscription_ctx_t *subscr = NULL, *subscr2 = NULL; ++ sr_session_ctx_t *sess; ++ const sr_error_info_t *err_info; ++ sr_data_t *data; ++ uint32_t i; ++ int ret, found; ++ ++ ret = sr_session_start(st->conn, SR_DS_RUNNING, &sess); ++ assert_int_equal(ret, SR_ERR_OK); ++ ++ /* failing and succeeding subscription in one context, another succeeding one in its own context, ++ * all with the same priority */ ++ ret = sr_module_change_subscribe(sess, "test", NULL, module_done_fail_cb, st, 0, SR_SUBSCR_DONE_ONLY, &subscr); ++ assert_int_equal(ret, SR_ERR_OK); ++ ret = sr_module_change_subscribe(sess, "test", NULL, module_done_ok_cb, st, 0, SR_SUBSCR_DONE_ONLY, &subscr); ++ assert_int_equal(ret, SR_ERR_OK); ++ ret = sr_module_change_subscribe(sess, "test", NULL, module_done_ok_cb, st, 0, SR_SUBSCR_DONE_ONLY, &subscr2); ++ assert_int_equal(ret, SR_ERR_OK); ++ ++ /* the changes are stored, the callback error is reported */ ++ ret = sr_set_item_str(sess, "/test:l1[k='key1']/v", "1", NULL, 0); ++ assert_int_equal(ret, SR_ERR_OK); ++ ret = sr_apply_changes(sess, 0); ++ assert_int_equal(ret, SR_ERR_OK_CALLBACK_FAILED); ++ ++ ret = sr_session_get_error(sess, &err_info); ++ assert_int_equal(ret, SR_ERR_OK); ++ assert_non_null(err_info); ++ found = 0; ++ for (i = 0; i < err_info->err_count; ++i) { ++ if ((err_info->err[i].err_code == SR_ERR_OPERATION_FAILED) && ++ !strcmp(err_info->err[i].message, "Done callback failed.")) { ++ found = 1; ++ } ++ } ++ assert_int_equal(found, 1); ++ ++ /* all the subscriptions got the event */ ++ assert_int_equal(ATOMIC_LOAD_RELAXED(st->cb_called), 1); ++ assert_int_equal(ATOMIC_LOAD_RELAXED(st->cb_called2), 2); ++ ++ ret = sr_get_data(sess, "/test:l1[k='key1']", 0, 0, 0, &data); ++ assert_int_equal(ret, SR_ERR_OK); ++ assert_non_null(data); ++ sr_release_data(data); ++ ++ /* the subscriptions keep working */ ++ ret = sr_delete_item(sess, "/test:l1[k='key1']", 0); ++ assert_int_equal(ret, SR_ERR_OK); ++ ret = sr_apply_changes(sess, 0); ++ assert_int_equal(ret, SR_ERR_OK_CALLBACK_FAILED); ++ assert_int_equal(ATOMIC_LOAD_RELAXED(st->cb_called), 2); ++ assert_int_equal(ATOMIC_LOAD_RELAXED(st->cb_called2), 4); ++ ++ /* no error without the failing subscription */ ++ sr_unsubscribe(subscr); ++ ret = sr_set_item_str(sess, "/test:l1[k='key1']/v", "1", NULL, 0); ++ assert_int_equal(ret, SR_ERR_OK); ++ ret = sr_apply_changes(sess, 0); ++ assert_int_equal(ret, SR_ERR_OK); ++ assert_int_equal(ATOMIC_LOAD_RELAXED(st->cb_called2), 5); ++ ++ /* cleanup */ ++ ret = sr_delete_item(sess, "/test:l1[k='key1']", 0); ++ assert_int_equal(ret, SR_ERR_OK); ++ ret = sr_apply_changes(sess, 0); ++ assert_int_equal(ret, SR_ERR_OK); ++ ++ sr_unsubscribe(subscr2); ++ sr_session_stop(sess); ++} ++ + /* MAIN */ + int + main(void) +@@ -8569,6 +8681,7 @@ main(void) + cmocka_unit_test_setup_teardown(test_write_starve, setup_f, teardown_f), + cmocka_unit_test_setup_teardown(test_mult_update, setup_f, teardown_f), + cmocka_unit_test_setup_teardown(test_done_timeout_priority, setup_f, teardown_f), ++ cmocka_unit_test_setup_teardown(test_done_fail, setup_f, teardown_f), + cmocka_unit_test_setup_teardown(test_list_replace, setup_f, teardown_f), + cmocka_unit_test_setup_teardown(test_lock_write, setup_f, teardown_f), + cmocka_unit_test_setup_teardown(test_change_enabled_race, setup_f, teardown_f), diff --git a/patches/sysrepo/5.2.27/0003-Allow-to-copy-from-factory-default.patch b/patches/sysrepo/5.2.27/0003-Allow-to-copy-from-factory-default.patch index a18c49926..56ea7b438 100644 --- a/patches/sysrepo/5.2.27/0003-Allow-to-copy-from-factory-default.patch +++ b/patches/sysrepo/5.2.27/0003-Allow-to-copy-from-factory-default.patch @@ -1,7 +1,8 @@ -From 1fb495404020832a02059a36a15c8940a2ca4564 Mon Sep 17 00:00:00 2001 +From 830418c1d56a7a020de1653f6ae1107a5195d635 Mon Sep 17 00:00:00 2001 From: Mattias Walström Date: Wed, 8 May 2024 17:00:50 +0200 -Subject: [PATCH 3/9] Allow to copy from factory default +Subject: [PATCH 03/10] Allow to copy from factory default +Organization: Wires Organization: Wires --- @@ -9,10 +10,10 @@ Organization: Wires 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sysrepo.c b/src/sysrepo.c -index 9a858a55..bdef7dba 100644 +index 56c1fbae..95728d8e 100644 --- a/src/sysrepo.c +++ b/src/sysrepo.c -@@ -5536,7 +5536,7 @@ sr_copy_config(sr_session_ctx_t *session, const char *module_name, sr_datastore_ +@@ -5373,7 +5373,7 @@ sr_copy_config(sr_session_ctx_t *session, const char *module_name, sr_datastore_ const struct lys_module *ly_mod = NULL; sr_datastore_t ds1, ds2; diff --git a/patches/sysrepo/5.2.27/0004-Add-z-switch-to-sysrepoctl-to-install-factory-config.patch b/patches/sysrepo/5.2.27/0004-Add-z-switch-to-sysrepoctl-to-install-factory-config.patch index 180ef11bb..77690791f 100644 --- a/patches/sysrepo/5.2.27/0004-Add-z-switch-to-sysrepoctl-to-install-factory-config.patch +++ b/patches/sysrepo/5.2.27/0004-Add-z-switch-to-sysrepoctl-to-install-factory-config.patch @@ -1,9 +1,10 @@ -From ab7a3331c38945ddbcdc2c88f382dfbfbc41c884 Mon Sep 17 00:00:00 2001 +From 54e4a93c828ac26315aa9870acdfb675c5ceb7b6 Mon Sep 17 00:00:00 2001 From: Mattias Walström Date: Mon, 6 May 2024 14:49:32 +0200 -Subject: [PATCH 4/9] Add -z switch to sysrepoctl to install factory config +Subject: [PATCH 04/10] Add -z switch to sysrepoctl to install factory config from a json file Organization: Wires +Organization: Wires This to be able to load the yang modules during build time instead on boot. --- @@ -84,7 +85,7 @@ index c1c2ea7a..1cdf2436 100644 + #endif diff --git a/src/sysrepo.c b/src/sysrepo.c -index bdef7dba..6296ff56 100644 +index 95728d8e..d33c7f92 100644 --- a/src/sysrepo.c +++ b/src/sysrepo.c @@ -1768,6 +1768,55 @@ sr_free_int_install_mods(sr_int_install_mod_t *new_mods, uint32_t new_mod_count) diff --git a/patches/sysrepo/5.2.27/0005-Introduce-new-log-level-SEC-for-audit-trails.patch b/patches/sysrepo/5.2.27/0005-Introduce-new-log-level-SEC-for-audit-trails.patch index 8d8cf838f..c316f46a3 100644 --- a/patches/sysrepo/5.2.27/0005-Introduce-new-log-level-SEC-for-audit-trails.patch +++ b/patches/sysrepo/5.2.27/0005-Introduce-new-log-level-SEC-for-audit-trails.patch @@ -1,7 +1,8 @@ -From 264cc5babfe191491b733c78d883608f9046b372 Mon Sep 17 00:00:00 2001 +From 4975aa4324fb187fbcbe1f3df4d943ce7bcf35dd Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Wed, 21 Aug 2024 16:00:35 +0200 -Subject: [PATCH 5/9] Introduce new log level [SEC] for audit trails +Subject: [PATCH 05/10] Introduce new log level [SEC] for audit trails +Organization: Wires Organization: Wires This adds a new log level for security and audit trail related log diff --git a/patches/sysrepo/5.2.27/0006-Add-audit-trail-for-high-priority-system-changes.patch b/patches/sysrepo/5.2.27/0006-Add-audit-trail-for-high-priority-system-changes.patch index 4efcba548..c767bbd39 100644 --- a/patches/sysrepo/5.2.27/0006-Add-audit-trail-for-high-priority-system-changes.patch +++ b/patches/sysrepo/5.2.27/0006-Add-audit-trail-for-high-priority-system-changes.patch @@ -1,7 +1,8 @@ -From 494ac6248241cd3abd8cf0b4635f648dd1a002c6 Mon Sep 17 00:00:00 2001 +From 4c462ef475eaf05d12fa76fffedad660c5b23035 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Wed, 21 Aug 2024 16:04:43 +0200 -Subject: [PATCH 6/9] Add audit trail for high priority system changes +Subject: [PATCH 06/10] Add audit trail for high priority system changes +Organization: Wires Organization: Wires Committing a change to running, copying to a datastore, or calling an @@ -18,10 +19,10 @@ Signed-off-by: Joachim Wiberg 1 file changed, 12 insertions(+) diff --git a/src/sysrepo.c b/src/sysrepo.c -index 6296ff56..6693e412 100644 +index d33c7f92..d5db9e36 100644 --- a/src/sysrepo.c +++ b/src/sysrepo.c -@@ -4936,6 +4936,9 @@ store: +@@ -4773,6 +4773,9 @@ store: goto cleanup; } @@ -31,7 +32,7 @@ index 6296ff56..6693e412 100644 /* generate the netconf-config-change notification before the "done" event, the changes are * already committed at this point; otherwise a notification subscription created by a "done" * callback would receive this change, which predates it */ -@@ -4951,6 +4954,9 @@ store: +@@ -4788,6 +4791,9 @@ store: } cleanup: @@ -41,7 +42,7 @@ index 6296ff56..6693e412 100644 if (change_sub_lock) { assert(change_sub_lock == SR_LOCK_READ); -@@ -5678,6 +5684,9 @@ sr_copy_config(sr_session_ctx_t *session, const char *module_name, sr_datastore_ +@@ -5515,6 +5521,9 @@ sr_copy_config(sr_session_ctx_t *session, const char *module_name, sr_datastore_ } } @@ -51,7 +52,7 @@ index 6296ff56..6693e412 100644 cleanup: /* MODULES UNLOCK */ sr_shmmod_modinfo_unlock(&mod_info); -@@ -8339,6 +8348,9 @@ sr_rpc_send_tree_internal(sr_session_ctx_t *session, struct lyd_node *input, uin +@@ -8176,6 +8185,9 @@ sr_rpc_send_tree_internal(sr_session_ctx_t *session, struct lyd_node *input, uin } } diff --git a/patches/sysrepo/5.2.27/0007-On-error-in-sr_shmsub_listen_thread-exit-process.patch b/patches/sysrepo/5.2.27/0007-On-error-in-sr_shmsub_listen_thread-exit-process.patch index 774b3219f..6b0414e77 100644 --- a/patches/sysrepo/5.2.27/0007-On-error-in-sr_shmsub_listen_thread-exit-process.patch +++ b/patches/sysrepo/5.2.27/0007-On-error-in-sr_shmsub_listen_thread-exit-process.patch @@ -1,7 +1,8 @@ -From 2c57fd6f7e03fd95459c8274e97406526709c4fd Mon Sep 17 00:00:00 2001 +From 6944bc2bcb4593135d63fe54fc19da01ddfe4e06 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Fri, 23 Aug 2024 12:22:06 +0200 -Subject: [PATCH 7/9] On error in sr_shmsub_listen_thread(), exit process +Subject: [PATCH 07/10] On error in sr_shmsub_listen_thread(), exit process +Organization: Wires Organization: Wires If processing callback events in, e.g., sysrepo-plugind, make sure to @@ -14,10 +15,10 @@ Signed-off-by: Joachim Wiberg 1 file changed, 2 insertions(+) diff --git a/src/shm_sub.c b/src/shm_sub.c -index 3fe8c8e6..2ab31ed3 100644 +index 9c70e408..07102f8e 100644 --- a/src/shm_sub.c +++ b/src/shm_sub.c -@@ -5035,5 +5035,7 @@ error: +@@ -5082,5 +5082,7 @@ error: /* free our own resources */ ATOMIC_STORE_RELAXED(subscr->thread_running, 0); pthread_detach(pthread_self()); diff --git a/patches/sysrepo/5.2.27/0008-Cross-compile-fixes.patch b/patches/sysrepo/5.2.27/0008-Cross-compile-fixes.patch index bd7fcb470..a150ba4a1 100644 --- a/patches/sysrepo/5.2.27/0008-Cross-compile-fixes.patch +++ b/patches/sysrepo/5.2.27/0008-Cross-compile-fixes.patch @@ -1,7 +1,8 @@ -From eb4f2063d4225fc9a41dc4ae648d62299c768061 Mon Sep 17 00:00:00 2001 +From 394b6850e0823d12f92f6e89e8f3c12d9ca5c702 Mon Sep 17 00:00:00 2001 From: Mattias Walström Date: Tue, 16 Dec 2025 08:18:32 +0100 -Subject: [PATCH 8/9] Cross compile fixes +Subject: [PATCH 08/10] Cross compile fixes +Organization: Wires Organization: Wires --- diff --git a/patches/sysrepo/5.2.27/0009-sr_mkfifo-set-sysrepo-group-if-available.patch b/patches/sysrepo/5.2.27/0009-sr_mkfifo-set-sysrepo-group-if-available.patch index 66d9a67a0..cf6fafdb5 100644 --- a/patches/sysrepo/5.2.27/0009-sr_mkfifo-set-sysrepo-group-if-available.patch +++ b/patches/sysrepo/5.2.27/0009-sr_mkfifo-set-sysrepo-group-if-available.patch @@ -1,7 +1,8 @@ -From d2155166da3d9fd7a2e8180106fc3f02bb69226f Mon Sep 17 00:00:00 2001 +From 9439f07ecdd61d918747f469bf92320c6b6c931d Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Wed, 7 Jan 2026 18:09:32 +0100 -Subject: [PATCH 9/9] sr_mkfifo(): set sysrepo group if available +Subject: [PATCH 09/10] sr_mkfifo(): set sysrepo group if available +Organization: Wires Organization: Wires We already set the umask, set the group to allow users of the sysrepo @@ -13,7 +14,7 @@ Signed-off-by: Joachim Wiberg 1 file changed, 11 insertions(+) diff --git a/src/common.c b/src/common.c -index 0a96a8f4..6f82bd4d 100644 +index f59c5621..e6a6052d 100644 --- a/src/common.c +++ b/src/common.c @@ -3952,6 +3952,17 @@ sr_mkfifo(const char *path, mode_t mode) diff --git a/patches/sysrepo/5.2.27/0010-sr_install_factory_config-take-the-context-lock.patch b/patches/sysrepo/5.2.27/0010-sr_install_factory_config-take-the-context-lock.patch index 5b9aba0e9..fbf687a31 100644 --- a/patches/sysrepo/5.2.27/0010-sr_install_factory_config-take-the-context-lock.patch +++ b/patches/sysrepo/5.2.27/0010-sr_install_factory_config-take-the-context-lock.patch @@ -1,19 +1,21 @@ -From ba3d7ab869edd3bee016dfe0189f63e00de50cbc Mon Sep 17 00:00:00 2001 +From d6da6561825e7ebaba1bc2f731b4e0076d387a30 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Tue, 3 Nov 2026 23:54:39 +0100 -Subject: [PATCH] sr_install_factory_config(): take the context lock +Subject: [PATCH 10/10] sr_install_factory_config(): take the context lock +Organization: Wires Organization: Wires Without the lock the process-global context is not loaded. With a printed context it is NULL in the process that printed it, so every module lookup against it fails and logs an invalid argument error. +Signed-off-by: Joachim Wiberg --- src/sysrepo.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/sysrepo.c b/src/sysrepo.c -index a3446564..a11f7cb8 100644 +index d5db9e36..2cd71787 100644 --- a/src/sysrepo.c +++ b/src/sysrepo.c @@ -1777,6 +1777,11 @@ sr_install_factory_config(sr_conn_ctx_t *conn, const char *factory_file) {