cdb_set_object is returning -1

Hi All, I am a new bee to confd.I am writing my application of reading a string from a file and storing it in the cdb database.Here is my yang module:

module myown {
namespace “”;
prefix myown;

import tailf-common {
prefix tailf;

revision “2016-02-02” {
description “latest”;

container Surabhi{
config false;
list new_entry{
key name;
leaf name {
type string;


my text file contains only one string “hello!” from where i will be storing it to the database.
Here is my application for that:-

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/poll.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <stdio.h>

#include <confd_lib.h>
#include <confd_cdb.h>
#include “myown.h”

#define INTERVAL 10

static int update_status(int sock)
FILE *proc;
int ret = 0, res = 0;
char buf[BUFSIZ], ch;
char *p;
confd_value_t val[2];
confd_value_t * ptr = val;
int i = 0;
if ((ret = cdb_start_session(sock, CDB_OPERATIONAL)) != CONFD_OK)
return ret;

if ((ret = cdb_set_namespace(sock, myown__ns)) != CONFD_OK)
return ret;

printf(“update_status : opening file\n”);
if ((proc = fopen("/home/surabhi/Confd/hello.txt", “r”)) == NULL)
return CONFD_ERR;

while (ret == CONFD_OK && fgets(buf, sizeof(buf), proc) != NULL) {
            printf("value of buf = %s\n",buf); 
            p = strchr(buf,(ch = fgetc(proc))); 
  CONFD_SET_XMLTAG(&val[i], myown_Surabhi, myown__ns);

    res = cdb_set_object(sock,ptr,i,"/Surabhi/new_entry{%s}", p);
                       printf("value of res is: %d\n", res);       
printf("update_status value buffer at the end : buf = %s\n",buf); 


return ret;


int main(int argc, char **argv)
int interval = 0;
struct sockaddr_in addr;
int sock;

if (argc > 1)
    interval = atoi(argv[1]);
if (interval == 0)
    interval = INTERVAL;

addr.sin_addr.s_addr = inet_addr("");
addr.sin_family = AF_INET;
addr.sin_port = htons(CONFD_PORT);

confd_init(argv[0], stderr, CONFD_SILENT);
if (confd_load_schemas((struct sockaddr*)&addr,
                       sizeof (struct sockaddr_in)) != CONFD_OK)
    confd_fatal("%s: Failed to load schemas from confd\n", argv[0]);
if ((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0)
    confd_fatal("%s: Failed to create socket", argv[0]);
if (cdb_connect(sock, CDB_DATA_SOCKET, (struct sockaddr *)&addr,
                sizeof(struct sockaddr_in)) < 0)
    confd_fatal("%s: Failed to connect to ConfD", argv[0]);

while (1) {
    if (update_status(sock) != CONFD_OK)
        confd_fatal("%s: Failed to update status\n", argv[0]);


Now, the problem is with the cdb_set_object() function which is giving -1 in res, due to which when I check through cli then it doesnt show any value stored in the leaf: name (type string) in the container Surabhi.
Can anybody please tell where is the mistake in my application??
Thanks in advance.
Please help.

cdb_set_object() takes a value array and not a tagged value array. i.e. CONFD_SET_XMLTAG() is unneeded

Increment bug.

However, most importantly, you can’t use cdb_set_object() here. You need to first create the list entry with cdb_create(). Then if your list entry consisted of more than just the key leaf, you’d then use cdb_set_object() to set the remaining part of the created list entry.

CONFD_SET_XMLTAG() sets a value, not a tagged value. It is used to indicate a leaf of type empty, or the start of a container, in a value array. But since there are neither in the list in the model, it should not be used here. The parent container for the list is given in the path.

Actually cdb_set_object() will create the list entry if needed - from confd_lib_cdb(3):

  If the container or list entry itself, or any sub-elements that are
   specified as existing, do not exist before this call, they will be

But of course it is pointless to use it when there are no leafs beside the key - cdb_create() is sufficient and simpler in that case.

Also, please refer to the section ERRORS in the confd_lib_lib(3) manual page regarding error handling when using libconfd. Just checking whether the return value is CONFD_OK or not gives only the absolute minimum of information.