Restructured error,debug anf log API

Renamed functions clicon->clixon, replaced global variables w access functions
Unified clicon_netconf_error with clixon_err()
This commit is contained in:
Olof hagsand 2023-11-13 10:12:52 +01:00
parent 261469be16
commit 24a4991ec8
199 changed files with 4668 additions and 4158 deletions

View file

@ -62,7 +62,7 @@
/* cligen */
#include <cligen/cligen.h>
/* clicon */
/* clixon */
#include <clixon/clixon.h>
#include "clixon_backend_transaction.h"
@ -83,17 +83,17 @@ struct confirmed_commit {
char *cc_persist_id; /* a value given by a client in the confirmed-commit */
uint32_t cc_session_id; /* the session_id of the client that gave no <persist> value */
int (*cc_fn)(int, void*); /* function pointer for rollback event (rollback_fn()) */
void *cc_arg; /* clicon_handle that will be passed to rollback_fn() */
void *cc_arg; /* clixon_handle that will be passed to rollback_fn() */
};
int
confirmed_commit_init(clicon_handle h)
confirmed_commit_init(clixon_handle h)
{
int retval = -1;
struct confirmed_commit *cc = NULL;
if ((cc = calloc(1, sizeof(*cc))) == NULL){
clicon_err(OE_UNIX, errno, "calloc");
clixon_err(OE_UNIX, errno, "calloc");
goto done;
}
cc->cc_state = INACTIVE;
@ -110,7 +110,7 @@ confirmed_commit_init(clicon_handle h)
* @retval 0 OK
*/
int
confirmed_commit_free(clicon_handle h)
confirmed_commit_free(clixon_handle h)
{
struct confirmed_commit *cc = NULL;
@ -128,7 +128,7 @@ confirmed_commit_free(clicon_handle h)
* Accessor functions
*/
enum confirmed_commit_state
confirmed_commit_state_get(clicon_handle h)
confirmed_commit_state_get(clixon_handle h)
{
struct confirmed_commit *cc = NULL;
@ -137,7 +137,7 @@ confirmed_commit_state_get(clicon_handle h)
}
static int
confirmed_commit_state_set(clicon_handle h,
confirmed_commit_state_set(clixon_handle h,
enum confirmed_commit_state state)
{
struct confirmed_commit *cc = NULL;
@ -148,7 +148,7 @@ confirmed_commit_state_set(clicon_handle h,
}
char *
confirmed_commit_persist_id_get(clicon_handle h)
confirmed_commit_persist_id_get(clixon_handle h)
{
struct confirmed_commit *cc = NULL;
@ -157,7 +157,7 @@ confirmed_commit_persist_id_get(clicon_handle h)
}
static int
confirmed_commit_persist_id_set(clicon_handle h,
confirmed_commit_persist_id_set(clixon_handle h,
char *persist_id)
{
struct confirmed_commit *cc = NULL;
@ -167,7 +167,7 @@ confirmed_commit_persist_id_set(clicon_handle h,
free(cc->cc_persist_id);
if (persist_id){
if ((cc->cc_persist_id = strdup4(persist_id)) == NULL){
clicon_err(OE_UNIX, errno, "strdup4");
clixon_err(OE_UNIX, errno, "strdup4");
return -1;
}
}
@ -177,7 +177,7 @@ confirmed_commit_persist_id_set(clicon_handle h,
}
uint32_t
confirmed_commit_session_id_get(clicon_handle h)
confirmed_commit_session_id_get(clixon_handle h)
{
struct confirmed_commit *cc = NULL;
@ -186,7 +186,7 @@ confirmed_commit_session_id_get(clicon_handle h)
}
static int
confirmed_commit_session_id_set(clicon_handle h,
confirmed_commit_session_id_set(clixon_handle h,
uint32_t session_id)
{
struct confirmed_commit *cc = NULL;
@ -197,7 +197,7 @@ confirmed_commit_session_id_set(clicon_handle h,
}
static int
confirmed_commit_fn_arg_get(clicon_handle h,
confirmed_commit_fn_arg_get(clixon_handle h,
int (**fn)(int, void*),
void **arg)
{
@ -210,7 +210,7 @@ confirmed_commit_fn_arg_get(clicon_handle h,
}
static int
confirmed_commit_fn_arg_set(clicon_handle h,
confirmed_commit_fn_arg_set(clixon_handle h,
int (*fn)(int, void*),
void *arg)
{
@ -300,7 +300,7 @@ xe_timeout(cxobj *xe)
* @retval -1 No Rollback event was found
*/
int
cancel_rollback_event(clicon_handle h)
cancel_rollback_event(clixon_handle h)
{
int retval;
int (*fn)(int, void*) = NULL;
@ -308,9 +308,9 @@ cancel_rollback_event(clicon_handle h)
confirmed_commit_fn_arg_get(h, &fn, &arg);
if ((retval = clixon_event_unreg_timeout(fn, arg)) == 0) {
clicon_log(LOG_INFO, "a scheduled rollback event has been cancelled");
clixon_log(h, LOG_INFO, "a scheduled rollback event has been cancelled");
} else {
clicon_log(LOG_WARNING, "the specified scheduled rollback event was not found");
clixon_log(h, LOG_WARNING, "the specified scheduled rollback event was not found");
}
return retval;
@ -319,7 +319,7 @@ cancel_rollback_event(clicon_handle h)
/*! Apply the rollback configuration upon expiration of the confirm-timeout
*
* @param[in] fd a dummy argument per the event callback semantics
* @param[in] arg a void pointer to a clicon_handle
* @param[in] arg a void pointer to a clixon_handle
* @retval 0 the rollback was successful
* @retval -1 the rollback failed
* @see do_rollback()
@ -328,9 +328,9 @@ static int
rollback_fn(int fd,
void *arg)
{
clicon_handle h = arg;
clixon_handle h = arg;
clicon_log(LOG_CRIT, "a confirming-commit was not received before the confirm-timeout expired; rolling back");
clixon_log(NULL, LOG_CRIT, "a confirming-commit was not received before the confirm-timeout expired; rolling back");
return do_rollback(h, NULL);
}
@ -344,7 +344,7 @@ rollback_fn(int fd,
* @retval -1 Rollback event was not scheduled
*/
static int
schedule_rollback_event(clicon_handle h,
schedule_rollback_event(clixon_handle h,
uint32_t timeout)
{
int retval = -1;
@ -352,7 +352,7 @@ schedule_rollback_event(clicon_handle h,
// register a new scheduled event
struct timeval t, t1;
if (gettimeofday(&t, NULL) < 0) {
clicon_err(OE_UNIX, 0, "failed to get time of day: %s", strerror(errno));
clixon_err(OE_UNIX, 0, "failed to get time of day: %s", strerror(errno));
goto done;
};
t1.tv_sec = timeout; t1.tv_usec = 0;
@ -383,7 +383,7 @@ schedule_rollback_event(clicon_handle h,
* @retval 0 OK
*/
int
cancel_confirmed_commit(clicon_handle h)
cancel_confirmed_commit(clixon_handle h)
{
cancel_rollback_event(h);
@ -395,7 +395,7 @@ cancel_confirmed_commit(clicon_handle h)
confirmed_commit_state_set(h, INACTIVE);
if (xmldb_delete(h, "rollback") < 0)
clicon_err(OE_DB, 0, "Error deleting the rollback configuration");
clixon_err(OE_DB, 0, "Error deleting the rollback configuration");
return 0;
}
@ -414,7 +414,7 @@ cancel_confirmed_commit(clicon_handle h)
* @retval -1 Error
*/
static int
check_valid_confirming_commit(clicon_handle h,
check_valid_confirming_commit(clixon_handle h,
cxobj *xe,
uint32_t myid)
{
@ -422,7 +422,7 @@ check_valid_confirming_commit(clicon_handle h,
char *persist_id = NULL;
if (xe == NULL){
clicon_err(OE_CFG, EINVAL, "xe is NULL");
clixon_err(OE_CFG, EINVAL, "xe is NULL");
goto done;
}
if (myid == 0)
@ -435,13 +435,13 @@ check_valid_confirming_commit(clicon_handle h,
break; // valid
}
else {
clicon_log(LOG_INFO,
clixon_log(h, LOG_INFO,
"a persistent confirmed-commit is in progress but the client issued a "
"confirming-commit with an incorrect persist-id");
goto invalid;
}
} else {
clicon_log(LOG_INFO,
clixon_log(h, LOG_INFO,
"a persistent confirmed-commit is in progress but the client issued a confirming-commit"
"without a persist-id");
goto invalid;
@ -453,7 +453,7 @@ check_valid_confirming_commit(clicon_handle h,
*/
break; // valid
}
clicon_log(LOG_DEBUG, "an ephemeral confirmed-commit is in progress, but there confirming-commit was"
clixon_log(h, LOG_DEBUG, "an ephemeral confirmed-commit is in progress, but there confirming-commit was"
"not issued on the same session as the confirmed-commit");
goto invalid;
default:
@ -485,7 +485,7 @@ check_valid_confirming_commit(clicon_handle h,
* actually occur, and if so, if they are correctly handled. The calls are from do_rollback() and load_failsafe()
*/
int
handle_confirmed_commit(clicon_handle h,
handle_confirmed_commit(clixon_handle h,
cxobj *xe,
uint32_t myid)
{
@ -496,7 +496,7 @@ handle_confirmed_commit(clicon_handle h,
int db_exists;
if (xe == NULL){
clicon_err(OE_CFG, EINVAL, "xe is NULL");
clixon_err(OE_CFG, EINVAL, "xe is NULL");
goto done;
}
if (myid == 0)
@ -509,7 +509,7 @@ handle_confirmed_commit(clicon_handle h,
cc_valid = check_valid_confirming_commit(h, xe, myid);
if (cc_valid) {
if (cancel_rollback_event(h) < 0) {
clicon_err(OE_DAEMON, 0, "A valid confirming-commit was received, but the corresponding rollback event was not found");
clixon_err(OE_DAEMON, 0, "A valid confirming-commit was received, but the corresponding rollback event was not found");
}
if (confirmed_commit_state_get(h) == PERSISTENT &&
@ -537,7 +537,7 @@ handle_confirmed_commit(clicon_handle h,
* <persist-id>
*/
confirmed_commit_state_set(h, PERSISTENT);
clicon_log(LOG_INFO,
clixon_log(h, LOG_INFO,
"a persistent confirmed-commit has been requested with persist id of '%s' and a timeout of %lu seconds",
confirmed_commit_persist_id_get(h), confirm_timeout);
}
@ -549,7 +549,7 @@ handle_confirmed_commit(clicon_handle h,
confirmed_commit_session_id_set(h, myid);
confirmed_commit_state_set(h, EPHEMERAL);
clicon_log(LOG_INFO,
clixon_log(h, LOG_INFO,
"an ephemeral confirmed-commit has been requested by session-id %u and a timeout of %lu seconds",
confirmed_commit_session_id_get(h),
confirm_timeout);
@ -586,18 +586,18 @@ handle_confirmed_commit(clicon_handle h,
db_exists = xmldb_exists(h, "rollback");
if (db_exists == -1) {
clicon_err(OE_DAEMON, 0, "there was an error while checking existence of the rollback database");
clixon_err(OE_DAEMON, 0, "there was an error while checking existence of the rollback database");
goto done;
} else if (db_exists == 0) {
// db does not yet exists
if (xmldb_copy(h, "running", "rollback") < 0) {
clicon_err(OE_DAEMON, 0, "there was an error while copying the running configuration to rollback database.");
clixon_err(OE_DAEMON, 0, "there was an error while copying the running configuration to rollback database.");
goto done;
};
}
if (schedule_rollback_event(h, confirm_timeout) < 0) {
clicon_err(OE_DAEMON, 0, "the rollback event could not be scheduled");
clixon_err(OE_DAEMON, 0, "the rollback event could not be scheduled");
goto done;
};
@ -607,7 +607,7 @@ handle_confirmed_commit(clicon_handle h,
* The new configuration is already committed to running and the rollback database can now be deleted
*/
if (xmldb_delete(h, "rollback") < 0) {
clicon_err(OE_DB, 0, "Error deleting the rollback configuration");
clixon_err(OE_DB, 0, "Error deleting the rollback configuration");
goto done;
}
}
@ -635,7 +635,7 @@ handle_confirmed_commit(clicon_handle h,
* @see rollback_fn()
*/
int
do_rollback(clicon_handle h,
do_rollback(clixon_handle h,
uint8_t *errs)
{
int retval = -1;
@ -643,13 +643,13 @@ do_rollback(clicon_handle h,
cbuf *cbret;
if ((cbret = cbuf_new()) == NULL) {
clicon_err(OE_DAEMON, 0, "rollback was not performed. (cbuf_new: %s)", strerror(errno));
clixon_err(OE_DAEMON, 0, "rollback was not performed. (cbuf_new: %s)", strerror(errno));
/* the rollback_db won't be deleted, so one can try recovery by:
* load rollback running
* restart the backend, which will try to load the rollback_db, and delete it if successful
* (otherwise it will load the failsafe)
*/
clicon_log(LOG_CRIT, "An error occurred during rollback and the rollback_db wasn't deleted.");
clixon_log(h, LOG_CRIT, "An error occurred during rollback and the rollback_db wasn't deleted.");
errstate |= ROLLBACK_NOT_APPLIED | ROLLBACK_DB_NOT_DELETED;
goto done;
}
@ -663,19 +663,19 @@ do_rollback(clicon_handle h,
/* theoretically, this should never error, since the rollback database was previously active and therefore
* had itself been previously and successfully committed.
*/
clicon_log(LOG_CRIT, "An error occurred committing the rollback database.");
clixon_log(h, LOG_CRIT, "An error occurred committing the rollback database.");
errstate |= ROLLBACK_NOT_APPLIED;
/* Rename the errored rollback database */
if (xmldb_rename(h, "rollback", NULL, ".error") < 0) {
clicon_log(LOG_CRIT, "An error occurred renaming the rollback database.");
clixon_log(h, LOG_CRIT, "An error occurred renaming the rollback database.");
errstate |= ROLLBACK_DB_NOT_DELETED;
}
/* Attempt to load the failsafe config */
if (load_failsafe(h, "Rollback") < 0) {
clicon_log(LOG_CRIT, "An error occurred committing the failsafe database. Exiting.");
clixon_log(h, LOG_CRIT, "An error occurred committing the failsafe database. Exiting.");
/* Invoke our own signal handler to exit */
raise(SIGINT);
@ -688,7 +688,7 @@ do_rollback(clicon_handle h,
cbuf_free(cbret);
if (xmldb_delete(h, "rollback") < 0) {
clicon_log(LOG_WARNING, "A rollback occurred but the rollback_db wasn't deleted.");
clixon_log(h, LOG_WARNING, "A rollback occurred but the rollback_db wasn't deleted.");
errstate |= ROLLBACK_DB_NOT_DELETED;
goto done;
};
@ -717,7 +717,7 @@ do_rollback(clicon_handle h,
* @see RFC 6241 Sec 8.4
*/
int
from_client_cancel_commit(clicon_handle h,
from_client_cancel_commit(clixon_handle h,
cxobj *xe,
cbuf *cbret,
void *arg,
@ -775,7 +775,7 @@ from_client_cancel_commit(clicon_handle h,
if (do_rollback(h, NULL) < 0)
goto done;
cprintf(cbret, "<rpc-reply xmlns=\"%s\"><ok/></rpc-reply>", NETCONF_BASE_NAMESPACE);
clicon_log(LOG_INFO, "a confirmed-commit has been cancelled by client request");
clixon_log(h, LOG_INFO, "a confirmed-commit has been cancelled by client request");
}
retval = 0;
done:
@ -793,7 +793,7 @@ from_client_cancel_commit(clicon_handle h,
* @retval -1 Error
*/
int
from_client_confirmed_commit(clicon_handle h,
from_client_confirmed_commit(clixon_handle h,
cxobj *xe,
uint32_t myid,
cbuf *cbret)