incremental debuggung
This commit is contained in:
parent
6d8acdea9f
commit
6169ea6bed
17 changed files with 203 additions and 64 deletions
|
|
@ -307,17 +307,17 @@ clicon_file_copy(char *src,
|
|||
return -1;
|
||||
}
|
||||
if((inF = open(src, O_RDONLY)) == -1) {
|
||||
clicon_err(OE_UNIX, errno, "open");
|
||||
clicon_err(OE_UNIX, errno, "open(%s) for read", src);
|
||||
return -1;
|
||||
}
|
||||
if((ouF = open(target, O_WRONLY | O_CREAT | O_TRUNC, st.st_mode)) == -1) {
|
||||
clicon_err(OE_UNIX, errno, "open");
|
||||
clicon_err(OE_UNIX, errno, "open(%s) for write", target);
|
||||
err = errno;
|
||||
goto error;
|
||||
}
|
||||
while((bytes = read(inF, line, sizeof(line))) > 0)
|
||||
if (write(ouF, line, bytes) < 0){
|
||||
clicon_err(OE_UNIX, errno, "write");
|
||||
clicon_err(OE_UNIX, errno, "write(%s)", src);
|
||||
err = errno;
|
||||
goto error;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -171,6 +171,7 @@ clicon_rpc_validate(clicon_handle h,
|
|||
* @param[in] value value as string
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @note special case: remove all: key:"/" op:OP_REMOVE
|
||||
*/
|
||||
int
|
||||
clicon_rpc_change(clicon_handle h,
|
||||
|
|
@ -284,6 +285,32 @@ clicon_rpc_load(clicon_handle h,
|
|||
return retval;
|
||||
}
|
||||
|
||||
/*! Send a request to backend to copy a file from one location to another
|
||||
* Note this assumes the backend can access these files and (usually) assumes
|
||||
* clients and servers have the access to the same filesystem.
|
||||
* @param[in] h CLICON handle
|
||||
* @param[in] db1 src database, eg "candidate"
|
||||
* @param[in] db2 dst database, eg "running"
|
||||
*/
|
||||
int
|
||||
clicon_rpc_copy(clicon_handle h,
|
||||
char *db1,
|
||||
char *db2)
|
||||
{
|
||||
int retval = -1;
|
||||
struct clicon_msg *msg;
|
||||
|
||||
if ((msg=clicon_msg_copy_encode(db1, db2, __FUNCTION__)) == NULL)
|
||||
goto done;
|
||||
if (clicon_rpc_msg(h, msg, NULL, NULL, NULL, __FUNCTION__) < 0)
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
unchunk_group(__FUNCTION__);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
/*! Send a kill session request to backend server
|
||||
* @param[in] h CLICON handle
|
||||
* @param[in] session_id Id of session to kill
|
||||
|
|
|
|||
|
|
@ -498,6 +498,64 @@ clicon_msg_load_decode(struct clicon_msg *msg,
|
|||
return 0;
|
||||
}
|
||||
|
||||
struct clicon_msg *
|
||||
clicon_msg_copy_encode(char *db_src, char *db_dst,
|
||||
const char *label)
|
||||
{
|
||||
struct clicon_msg *msg;
|
||||
int hdrlen = sizeof(*msg);
|
||||
uint16_t len;
|
||||
int p;
|
||||
|
||||
clicon_debug(2, "%s: db_src: %s db_dst: %s",
|
||||
__FUNCTION__,
|
||||
db_src, db_dst);
|
||||
p = 0;
|
||||
len = hdrlen + strlen(db_src) + 1 + strlen(db_dst) + 1;
|
||||
if ((msg = (struct clicon_msg *)chunk(len, label)) == NULL){
|
||||
clicon_err(OE_PROTO, errno, "%s: chunk", __FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
memset(msg, 0, len);
|
||||
/* hdr */
|
||||
msg->op_type = htons(CLICON_MSG_COPY);
|
||||
msg->op_len = htons(len);
|
||||
/* body */
|
||||
strncpy(msg->op_body+p, db_src, len-p-hdrlen);
|
||||
p += strlen(db_src)+1;
|
||||
strncpy(msg->op_body+p, db_dst, len-p-hdrlen);
|
||||
p += strlen(db_dst)+1;
|
||||
return msg;
|
||||
}
|
||||
|
||||
int
|
||||
clicon_msg_copy_decode(struct clicon_msg *msg,
|
||||
char **db_src, char **db_dst,
|
||||
const char *label)
|
||||
{
|
||||
int p;
|
||||
|
||||
p = 0;
|
||||
/* body */
|
||||
if ((*db_src = chunk_sprintf(label, "%s", msg->op_body+p)) == NULL){
|
||||
clicon_err(OE_PROTO, errno, "%s: chunk_sprintf",
|
||||
__FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
p += strlen(*db_src)+1;
|
||||
|
||||
if ((*db_dst = chunk_sprintf(label, "%s", msg->op_body+p)) == NULL){
|
||||
clicon_err(OE_PROTO, errno, "%s: chunk_sprintf",
|
||||
__FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
p += strlen(*db_dst)+1;
|
||||
clicon_debug(2, "%s: db_src: %s db_dst: %s",
|
||||
__FUNCTION__,
|
||||
*db_src, *db_dst);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct clicon_msg *
|
||||
clicon_msg_kill_encode(uint32_t session_id, const char *label)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -105,9 +105,17 @@ db_init(char *file)
|
|||
return db_init_mode(file, DP_OWRITER | DP_OCREAT ); /* DP_OTRUNC? */
|
||||
}
|
||||
|
||||
/*! Remove database by removing file, if it exists *
|
||||
* @param[in] file database file
|
||||
*/
|
||||
int
|
||||
db_delete(char *file)
|
||||
{
|
||||
struct stat sb;
|
||||
|
||||
if (stat(file, &sb) < 0){
|
||||
return 0;
|
||||
}
|
||||
if (unlink(file) < 0){
|
||||
clicon_err(OE_DB, errno, "unlink %s", file);
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -594,22 +594,20 @@ get(char *dbname,
|
|||
clicon_err(OE_XML, 0, "Malformed key: %s", xk);
|
||||
goto done;
|
||||
}
|
||||
name = vec[1];
|
||||
if ((y = yang_find_topnode(ys, name)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "No yang node found: %s", name);
|
||||
goto done;
|
||||
}
|
||||
if ((xc = xml_find(x, name))==NULL)
|
||||
if ((xc = xml_new_spec(name, x, y)) == NULL)
|
||||
goto done;
|
||||
x = xc;
|
||||
i = 2;
|
||||
i = 1;
|
||||
while (i<nvec){
|
||||
name = vec[i];
|
||||
if ((y = yang_find_syntax((yang_node*)y, name)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "No yang node found: %s", name);
|
||||
goto done;
|
||||
if (i == 1){ /* spec->module->node */
|
||||
if ((y = yang_find_topnode(ys, name)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "No yang node found: %s", name);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
else
|
||||
if ((y = yang_find_syntax((yang_node*)y, name)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "No yang node found: %s", name);
|
||||
goto done;
|
||||
}
|
||||
switch (y->ys_keyword){
|
||||
case Y_LEAF_LIST:
|
||||
/*
|
||||
|
|
@ -664,7 +662,9 @@ get(char *dbname,
|
|||
x = xc;
|
||||
} /* while */
|
||||
break;
|
||||
default:
|
||||
case Y_LEAF:
|
||||
case Y_CONTAINER:
|
||||
default:
|
||||
if ((xc = xml_find(x, name))==NULL)
|
||||
if ((xc = xml_new_spec(name, x, y)) == NULL)
|
||||
goto done;
|
||||
|
|
@ -1158,7 +1158,6 @@ xmldb_put_local(clicon_handle h,
|
|||
return retval;
|
||||
}
|
||||
|
||||
|
||||
/*! Modify database provided an xml tree and an operation
|
||||
* @param[in] dbname Name of database to search in (filename including dir path)
|
||||
* @param[in] h CLICON handle
|
||||
|
|
@ -1239,8 +1238,14 @@ xmldb_put_xkey_local(clicon_handle h,
|
|||
while (i<nvec){
|
||||
name = vec[i];
|
||||
if (i==1){
|
||||
if (!strlen(name) && (op==OP_DELETE || op == OP_REMOVE)){
|
||||
/* Special handling of "/" */
|
||||
cprintf(ckey, "/%s", name);
|
||||
break;
|
||||
}
|
||||
else
|
||||
if ((y = yang_find_topnode(yspec, name)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "No yang node found: %s", xml_name(x));
|
||||
clicon_err(OE_UNIX, errno, "No yang node found: %s", x?xml_name(x):"");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -1281,7 +1286,7 @@ xmldb_put_xkey_local(clicon_handle h,
|
|||
while ((cvi = cvec_each(cvk, cvi)) != NULL) {
|
||||
keyname = cv_string_get(cvi);
|
||||
val2 = vec[i++];
|
||||
if (i>=nvec){
|
||||
if (i>nvec){ /* XXX >= ? */
|
||||
clicon_err(OE_XML, errno, "List %s without argument", name);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1291,8 +1296,8 @@ xmldb_put_xkey_local(clicon_handle h,
|
|||
if (op == OP_MERGE || op == OP_REPLACE || op == OP_CREATE)
|
||||
if (db_set(filename, cbuf_get(csubkey), val2, strlen(val2)+1) < 0)
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (op == OP_MERGE || op == OP_REPLACE || op == OP_CREATE)
|
||||
if (db_set(filename, cbuf_get(ckey), NULL, 0) < 0)
|
||||
|
|
@ -1390,9 +1395,9 @@ xmldb_put_xkey(clicon_handle h,
|
|||
* @note This function can only be called locally.
|
||||
*/
|
||||
int
|
||||
xmldb_dump(FILE *f,
|
||||
char *dbfilename,
|
||||
char *rxkey)
|
||||
xmldb_dump_local(FILE *f,
|
||||
char *dbfilename,
|
||||
char *rxkey)
|
||||
{
|
||||
int retval = -1;
|
||||
int npairs;
|
||||
|
|
@ -1415,6 +1420,7 @@ xmldb_dump(FILE *f,
|
|||
return retval;
|
||||
}
|
||||
|
||||
|
||||
/*! Local variant of xmldb_copy */
|
||||
static int
|
||||
xmldb_copy_local(clicon_handle h,
|
||||
|
|
@ -1619,7 +1625,9 @@ xmldb_delete_local(clicon_handle h,
|
|||
return retval;
|
||||
}
|
||||
|
||||
/*! Delete database. Remove file */
|
||||
/*! Delete database. Remove file
|
||||
* Should not be called from client. Use change("/", OP_REMOVE) instead.
|
||||
*/
|
||||
int
|
||||
xmldb_delete(clicon_handle h,
|
||||
char *db)
|
||||
|
|
|
|||
|
|
@ -448,9 +448,9 @@ yang_find_syntax(yang_node *yn, char *argument)
|
|||
return ysmatch;
|
||||
}
|
||||
|
||||
/*! Help function to check find 'top-node', eg first 'syntax node in a spec
|
||||
/*! Help function to check find 'top-node', eg first 'syntax' node in a spec
|
||||
* A yang specification has modules as children which in turn can have
|
||||
* syntax-nodes as children. This function goes through all the modulers to
|
||||
* syntax-nodes as children. This function goes through all the modules to
|
||||
* look for syntax-nodes. Note that if a child to a module is a choice,
|
||||
* the search is made recursively made to the choice's children.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue