CONFD_ERR_BADPATH when using cdb_load_file for operational data

My yang is :

module Collection { 
    namespace "http://com/company/Collection";
    prefix Collection;
    list Collection {
        config false;
        key network;
        leaf network {
            type string;
        container Database {

The XML that i am uploading using cdb_load_file is:

<Collection xmlns="http://com/company/Collection">
    <Database xmlns="http://com/company/Collection">

My C++ code looks like this:

void writeToConfDataStore(std::string fileName) {
    struct in_addr in;
    struct sockaddr_in addr;
    int subsock;

    inet_aton("", &in);
    addr.sin_addr.s_addr = in.s_addr;
    addr.sin_family = AF_INET;
    addr.sin_port = htons(CONFD_PORT); //4565
    confd_init(“my_prog”, stderr, CONFD_SILENT);
    if (confd_load_schemas((struct sockaddr*)&addr,
                           sizeof (struct sockaddr_in)) != CONFD_OK)
        std::cout<<"Failed to load schemas from confd\n";
    if ((subsock = socket(PF_INET, SOCK_STREAM, 0)) < 0 ) {
        std::cout<<"Unable to open socket"<<std::endl;
    if (cdb_connect(subsock, CDB_DATA_SOCKET, (struct sockaddr*)&addr,
                    sizeof (struct sockaddr_in)) < 0) {
        std::cout<<"Unable to connect"<<std::endl;
    int cdb_load_flags = 0;
    int ret;
    if((ret = cdb_start_session2(subsock, CDB_OPERATIONAL, cdb_load_flags)) != CONFD_OK) {
        std::cout<<"Unable to start session"<<std::endl;

    if((ret = cdb_load_file(subsock, fileName.c_str(), 0)) != CONFD_OK) {
        std::cout<<"Failed to load file with error:"<<confd_errno<<std::endl;

Output i see is:

Failed to load file with error:8

Please help me fix this


Check the path to your file, the file you pointed to could not be opened.
You can print the string that confd_strerror(int code) return to get a description of a particular error code. If you want to make sure you get it all when printing error information you can do something like:


where the OK() macro expands to something like:

#define ERR(s, doexit) do {                              \
        fatal(0, doexit, "%d: %s failed: %s (%d): %s",   \
              __LINE__, (s),                             \
              confd_strerror(confd_errno),               \
              confd_errno, confd_lasterr());             \
    } while (0)

#define OK(E) do {                                      \
        if ((E) != CONFD_OK) {                          \
            ERR(#E, 1);                                 \
        }                                               \
    } while (0)

static void fatal(int err, int doexit, char *fmt, ...)
    va_list ap;

    fprintf(stderr, "%s: ", progname);
    va_start(ap, fmt);
    vfprintf(stderr, fmt, ap);
    if (err != 0)
        fprintf(stderr, ": %s", strerror(err));
    fprintf(stderr, "\n");
    if (doexit)

Thank you. It helped me to find out the problem. I was passing in the file name instead of the full path of the file.
cdb_load_file(subsock, fileName.c_str(), 0) failed: badly formatted or nonexistent path (8): Couldn’t open file out.xml: no such file or directory