From a1e7c6f12668d577ba5296ced5e6943326723527 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Tue, 13 Jun 2023 13:28:30 +0200 Subject: [PATCH] Modified backend exit strategy so that 2nd ^C actually exits Copied creator cvec if modified with REPLACE --- CHANGELOG.md | 1 + apps/backend/backend_main.c | 2 ++ lib/clixon/clixon_xml.h | 1 + lib/src/clixon_datastore_write.c | 5 +++-- lib/src/clixon_xml.c | 32 ++++++++++++++++++++++++++------ 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bb3bfb2..ec7a9b12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,7 @@ Developers may need to change their code ### Minor features +* Modified backend exit strategy so that 2nd ^C actually exits * Performance: A change in the `merge` code made "co-located" config and non-config get retrieval go considerable faster. This is done by a specialized `xml_child_each_attr()` function. * CLI: Added `show statistics` example code for backend and CLI memory stats * [Support yang type union with are same subtypes with SNMP](https://github.com/clicon/clixon/pull/427) diff --git a/apps/backend/backend_main.c b/apps/backend/backend_main.c index a743240a..d3c0e7eb 100644 --- a/apps/backend/backend_main.c +++ b/apps/backend/backend_main.c @@ -158,6 +158,8 @@ backend_sig_term(int arg) if (i++ == 0) clicon_log(LOG_NOTICE, "%s: %s: pid: %u Signal %d", __PROGRAM__, __FUNCTION__, getpid(), arg); + else + exit(1); clixon_exit_set(1); /* checked in clixon_event_loop() */ } diff --git a/lib/clixon/clixon_xml.h b/lib/clixon/clixon_xml.h index 7a474000..f2a7e3f5 100644 --- a/lib/clixon/clixon_xml.h +++ b/lib/clixon/clixon_xml.h @@ -232,6 +232,7 @@ int xml_creator_add(cxobj *xn, char *name); int xml_creator_rm(cxobj *xn, char *name); int xml_creator_find(cxobj *xn, char *name); size_t xml_creator_len(cxobj *xn); +int xml_creator_copy(cxobj *x0, cxobj *x1); int xml_creator_print(FILE *f, cxobj *xn); char *xml_value(cxobj *xn); diff --git a/lib/src/clixon_datastore_write.c b/lib/src/clixon_datastore_write.c index b99ea1d4..1dd90c6e 100644 --- a/lib/src/clixon_datastore_write.c +++ b/lib/src/clixon_datastore_write.c @@ -188,8 +188,7 @@ check_body_namespace(cxobj *x0, if (ns0 != NULL && ns1 != NULL){ /* namespace exists in both x1 and x0 */ if (strcmp(ns0, ns1)){ /* prefixes in x1 and x0 refers to different namespaces - * XXX return netconf error instead -bad-attribue? + * XXX return netconf error instead bad-attribue? */ if ((cberr = cbuf_new()) == NULL){ clicon_err(OE_UNIX, errno, "cbuf_new"); @@ -848,6 +847,8 @@ text_modify(clicon_handle h, #ifdef XML_PARENT_CANDIDATE xml_parent_candidate_set(x0, x0p); #endif + if (xml_creator_copy(x1, x0) < 0) + goto done; changed++; /* Get namespace from x1 * Check if namespace exists in x0 parent diff --git a/lib/src/clixon_xml.c b/lib/src/clixon_xml.c index e0480165..b6d88e43 100644 --- a/lib/src/clixon_xml.c +++ b/lib/src/clixon_xml.c @@ -705,6 +705,29 @@ xml_creator_len(cxobj *xn) return 0; } +/*! Copy creator info from x0 to x1 + * + * @param[in] x0 Source XML node + * @param[in] x1 Destination XML node + * @retval 0 OK + * @retval -1 Error + */ +int +xml_creator_copy(cxobj *x0, + cxobj *x1) +{ + int retval = -1; + + if (x0->x_creators) + if ((x1->x_creators = cvec_dup(x0->x_creators)) == NULL){ + clicon_err(OE_UNIX, errno, "cvec_dup"); + goto done; + } + retval = 0; + done: + return retval; +} + /*! Print XML and creator tags where they exists, apply help function * * @param[in] x XML tree @@ -737,7 +760,7 @@ int xml_creator_print(FILE *f, cxobj *xn) { - return xml_apply(xn, CX_ELMNT, creator_print_fn, f); + return xml_apply0(xn, CX_ELMNT, creator_print_fn, f); } /*! Get value of xnode @@ -2079,11 +2102,8 @@ xml_copy_one(cxobj *x0, switch (xml_type(x0)){ case CX_ELMNT: xml_spec_set(x1, xml_spec(x0)); - if (x0->x_creators) - if ((x1->x_creators = cvec_dup(x0->x_creators)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_dup"); - goto done; - } + if (xml_creator_copy(x0, x1) < 0) + goto done; break; case CX_BODY: case CX_ATTR: