Netconf startup configuration support. Set CLICON_USE_STARTUP_CONFIG to 1 to
enable. Eg, if backend_main is started with -CIr startup will be copied to running. Added .. as valid step in xpath
This commit is contained in:
parent
30a479de68
commit
4461cc9598
20 changed files with 116 additions and 159 deletions
|
|
@ -241,10 +241,6 @@ clicon_option_sanity(clicon_hash_t *copt)
|
|||
clicon_err(OE_UNIX, 0, "CLICON_ARCHIVE_DIR not defined in config file");
|
||||
goto done;
|
||||
}
|
||||
if (!hash_lookup(copt, "CLICON_STARTUP_CONFIG")){
|
||||
clicon_err(OE_UNIX, 0, "CLICON_STARTUP_CONFIG not defined in config file");
|
||||
goto done;
|
||||
}
|
||||
if (!hash_lookup(copt, "CLICON_SOCK")){
|
||||
clicon_err(OE_UNIX, 0, "CLICON_SOCK not defined in config file");
|
||||
goto done;
|
||||
|
|
@ -461,12 +457,6 @@ clicon_archive_dir(clicon_handle h)
|
|||
return clicon_option_str(h, "CLICON_ARCHIVE_DIR");
|
||||
}
|
||||
|
||||
char *
|
||||
clicon_startup_config(clicon_handle h)
|
||||
{
|
||||
return clicon_option_str(h, "CLICON_STARTUP_CONFIG");
|
||||
}
|
||||
|
||||
/* get family of backend socket: AF_UNIX, AF_INET or AF_INET6 */
|
||||
int
|
||||
clicon_sock_family(clicon_handle h)
|
||||
|
|
|
|||
|
|
@ -128,22 +128,17 @@ clicon_rpc_msg(clicon_handle h,
|
|||
* @param[in] h CLICON handle
|
||||
* @param[in] from name of 'from' database (eg "candidate")
|
||||
* @param[in] db name of 'to' database (eg "running")
|
||||
* @param[in] snapshot Make a snapshot copy of db state
|
||||
* @param[in] startup Make a copy to startup.
|
||||
* @retval 0 Copy current->candidate
|
||||
*/
|
||||
int
|
||||
clicon_rpc_commit(clicon_handle h,
|
||||
char *from,
|
||||
char *to,
|
||||
int snapshot,
|
||||
int startup)
|
||||
char *to)
|
||||
{
|
||||
int retval = -1;
|
||||
struct clicon_msg *msg;
|
||||
|
||||
if ((msg=clicon_msg_commit_encode(from, to, snapshot, startup,
|
||||
__FUNCTION__)) == NULL)
|
||||
if ((msg=clicon_msg_commit_encode(from, to, __FUNCTION__)) == NULL)
|
||||
goto done;
|
||||
if (clicon_rpc_msg(h, msg, NULL, NULL, NULL, __FUNCTION__) < 0)
|
||||
goto done;
|
||||
|
|
|
|||
|
|
@ -73,18 +73,16 @@
|
|||
|
||||
struct clicon_msg *
|
||||
clicon_msg_commit_encode(char *dbsrc, char *dbdst,
|
||||
uint32_t snapshot, uint32_t startup,
|
||||
const char *label)
|
||||
{
|
||||
struct clicon_msg *msg;
|
||||
uint16_t len;
|
||||
int hdrlen = sizeof(*msg);
|
||||
int p;
|
||||
uint32_t tmp;
|
||||
|
||||
clicon_debug(2, "%s: snapshot: %d startup: %d dbsrc: %s dbdst: %s",
|
||||
clicon_debug(2, "%s: dbsrc: %s dbdst: %s",
|
||||
__FUNCTION__,
|
||||
snapshot, startup, dbsrc, dbdst);
|
||||
dbsrc, dbdst);
|
||||
p = 0;
|
||||
len = sizeof(*msg) + 2*sizeof(uint32_t) + strlen(dbsrc) + 1 +
|
||||
strlen(dbdst) + 1;
|
||||
|
|
@ -97,12 +95,6 @@ clicon_msg_commit_encode(char *dbsrc, char *dbdst,
|
|||
msg->op_type = htons(CLICON_MSG_COMMIT);
|
||||
msg->op_len = htons(len);
|
||||
/* body */
|
||||
tmp = htonl(snapshot);
|
||||
memcpy(msg->op_body+p, &tmp, sizeof(uint32_t));
|
||||
p += sizeof(uint32_t);
|
||||
tmp = htonl(startup);
|
||||
memcpy(msg->op_body+p, &tmp, sizeof(uint32_t));
|
||||
p += sizeof(uint32_t);
|
||||
strncpy(msg->op_body+p, dbsrc, len-p-hdrlen);
|
||||
p += strlen(dbsrc)+1;
|
||||
strncpy(msg->op_body+p, dbdst, len-p-hdrlen);
|
||||
|
|
@ -113,20 +105,12 @@ clicon_msg_commit_encode(char *dbsrc, char *dbdst,
|
|||
int
|
||||
clicon_msg_commit_decode(struct clicon_msg *msg,
|
||||
char **dbsrc, char **dbdst,
|
||||
uint32_t *snapshot, uint32_t *startup,
|
||||
const char *label)
|
||||
{
|
||||
int p;
|
||||
uint32_t tmp;
|
||||
|
||||
p = 0;
|
||||
/* body */
|
||||
memcpy(&tmp, msg->op_body+p, sizeof(uint32_t));
|
||||
*snapshot = ntohl(tmp);
|
||||
p += sizeof(uint32_t);
|
||||
memcpy(&tmp, msg->op_body+p, sizeof(uint32_t));
|
||||
*startup = ntohl(tmp);
|
||||
p += sizeof(uint32_t);
|
||||
if ((*dbsrc = chunk_sprintf(label, "%s", msg->op_body+p)) == NULL){
|
||||
clicon_err(OE_PROTO, errno, "%s: chunk_sprintf",
|
||||
__FUNCTION__);
|
||||
|
|
@ -139,9 +123,7 @@ clicon_msg_commit_decode(struct clicon_msg *msg,
|
|||
return -1;
|
||||
}
|
||||
p += strlen(*dbdst)+1;
|
||||
clicon_debug(2, "%s: snapshot: %d startup: %d dbsrc: %s dbdst: %s",
|
||||
__FUNCTION__,
|
||||
*snapshot, *startup, *dbsrc, *dbdst);
|
||||
clicon_debug(2, "%s: dbsrc: %s dbdst: %s", __FUNCTION__, *dbsrc, *dbdst);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -414,6 +414,7 @@ xmlkeyfmt2xpath(char *xkfmt,
|
|||
*/
|
||||
static int _running_locked = 0;
|
||||
static int _candidate_locked = 0;
|
||||
static int _startup_locked = 0;
|
||||
|
||||
/*! Lock database
|
||||
*/
|
||||
|
|
@ -425,6 +426,8 @@ db_lock(char *db,
|
|||
_running_locked = pid;
|
||||
else if (strcmp("candidate", db) == 0)
|
||||
_candidate_locked = pid;
|
||||
else if (strcmp("startup", db) == 0)
|
||||
_startup_locked = pid;
|
||||
clicon_debug(1, "%s: locked by %u", db, pid);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -438,6 +441,8 @@ db_unlock(char *db)
|
|||
_running_locked = 0;
|
||||
else if (strcmp("candidate", db) == 0)
|
||||
_candidate_locked = 0;
|
||||
else if (strcmp("startup", db) == 0)
|
||||
_startup_locked = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -452,6 +457,8 @@ db_islocked(char *db)
|
|||
return (_running_locked);
|
||||
else if (strcmp("candidate", db) == 0)
|
||||
return(_candidate_locked);
|
||||
else if (strcmp("startup", db) == 0)
|
||||
return(_startup_locked);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -485,6 +492,7 @@ db2file(clicon_handle h,
|
|||
}
|
||||
if (strcmp(db, "running") != 0 &&
|
||||
strcmp(db, "candidate") != 0 &&
|
||||
strcmp(db, "startup") != 0 &&
|
||||
strcmp(db, "tmp") != 0){
|
||||
clicon_err(OE_XML, 0, "Unexpected database: %s", db);
|
||||
goto done;
|
||||
|
|
@ -1016,8 +1024,10 @@ xmldb_get_local(clicon_handle h,
|
|||
if (xvec != NULL)
|
||||
for (i=0; i<xlen; i++)
|
||||
xml_flag_set(xvec[i], XML_FLAG_MARK);
|
||||
if (xml_tree_prune_unmarked(xt, NULL) < 0)
|
||||
goto done;
|
||||
/* Top is special case */
|
||||
if (!xml_flag(xt, XML_FLAG_MARK))
|
||||
if (xml_tree_prune_unmarked(xt, NULL) < 0)
|
||||
goto done;
|
||||
if (xml_apply(xt, CX_ELMNT, (xml_applyfn_t*)xml_flag_reset, (void*)XML_FLAG_MARK) < 0)
|
||||
goto done;
|
||||
if (xvec0 && xlen0){
|
||||
|
|
@ -1741,7 +1751,7 @@ xmldb_put_xkey_local(clicon_handle h,
|
|||
/*! Modify database provided an XML database key and an operation
|
||||
* @param[in] h CLICON handle
|
||||
* @param[in] db Database name
|
||||
* @param[in] xk XML Key, eg /aa/bb/17/name
|
||||
* @param[in] xk XML Key, eg /aa/bb=17/name
|
||||
* @param[in] val Key value, eg "17"
|
||||
* @param[in] op OP_MERGE, OP_REPLACE, OP_REMOVE, etc
|
||||
* @retval 0 OK
|
||||
|
|
|
|||
|
|
@ -326,7 +326,7 @@ xpath_parse(char *xpath,
|
|||
s = s0;
|
||||
if (strlen(s))
|
||||
nvec = 1;
|
||||
/* Chop up LocatoinPath in Steps delimited by '/' (unless [] predicate)
|
||||
/* Chop up LocationPath in Steps delimited by '/' (unless [] predicate)
|
||||
* Eg, "/a/b[/c]/d" -> "a" "b[/c]" "d"
|
||||
*/
|
||||
esc = 0;
|
||||
|
|
@ -358,12 +358,12 @@ xpath_parse(char *xpath,
|
|||
else if (strncmp(s,"descendant-or-self::", strlen("descendant-or-self::"))==0){
|
||||
xpath_element_new(A_DESCENDANT_OR_SELF, s+strlen("descendant-or-self::"), &xpnext);
|
||||
}
|
||||
else if (strncmp(s,".", strlen("."))==0)
|
||||
xpath_element_new(A_SELF, s+strlen("."), &xpnext);
|
||||
else if (strncmp(s,".", strlen(s))==0) /* abbreviatedstep */
|
||||
xpath_element_new(A_SELF, NULL, &xpnext);
|
||||
else if (strncmp(s,"self::", strlen("self::"))==0)
|
||||
xpath_element_new(A_SELF, s+strlen("self::"), &xpnext);
|
||||
else if (strncmp(s,"..", strlen(".."))==0)
|
||||
xpath_element_new(A_PARENT, s+strlen(".."), &xpnext);
|
||||
else if (strncmp(s,"..", strlen(s))==0) /* abbreviatedstep */
|
||||
xpath_element_new(A_PARENT, NULL, &xpnext);
|
||||
else if (strncmp(s,"parent::", strlen("parent::"))==0)
|
||||
xpath_element_new(A_PARENT, s+strlen("parent::"), &xpnext);
|
||||
else if (strncmp(s,"ancestor::", strlen("ancestor::"))==0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue