ConfD User Community

Cdb_get_object issue

Hi ,
We are seeing an issue while fetching the data from Confd DB from the given path using cdb_get_object .

 int init_data(void)
 42 {
 43     INFO_ENTER("");
 44     static int subscr_socket1 = -1;
 45
 46     int ret = CONFD_ERR;
 47
 48     confd_init(DAEMON_NAME, stderr, CONFD_TRACE);
 49
 50     struct sockaddr_in addr_in;
 51     addr_in.sin_addr.s_addr = inet_addr("127.0.0.1");
 52     addr_in.sin_family = AF_INET;
 53     addr_in.sin_port = htons(CONFD_PORT);
 54
 55     struct sockaddr *addr = (struct sockaddr *)&addr_in;
 56
 57     ret = confd_load_schemas(addr, sizeof(*addr));
 58     if (CONFD_OK != ret) {
 59         confd_fatal("Failed to load schemas from ConfD\n");
 60     }
 61
 62     if ((subscr_socket1 = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
 63         FATAL("Failed to open socket\n");
 64         INFO_EXIT("(%i)", ret);
 65         return ret;
 66     }
 67
 68     ret = cdb_connect(subscr_socket1, CDB_DATA_SOCKET,
 69             addr, sizeof(*addr));
 70     if (CONFD_OK != ret) {
71         FATAL("Failed to cdb_connect() to ConfD\n");
 72         INFO_EXIT("(%i)", ret);
 73         return ret;
 74     }
 75
 76     struct confd_cs_node *start = confd_cs_node_cd(NULL, ROOT_PATH);
 77     int max_elems = max_object_elems(start);
 78     confd_value_t val[max_elems];
 79     printf("=== max_elems : %d\n", max_elems);
 80     ret = cdb_get_object(subscr_socket1, val, max_elems, ROOT_PATH);
 81     if (CONFD_OK != ret) {
 82         FATAL("Failed to cdb_get_object() to ConfD\n");
 83         INFO_EXIT("(%i)", ret);
 84         return ret;
 85     }
 86     //print_value_array(start, val, ret, 0, "\n");
 87     //free_values(val, ret);
 88     return ret;
 89 }

we are getting error ,

TRACE CDB_GET_OBJECT /folder-container/folder-userDEBUG Bad protocol usage or unexpected retval - Expected NEW_SESSION or SUBSCRIBE
 --> CONFD_ERR

Is the error is expected, or any way to fetch the data from container/list path from CDB ?

According to error message, it looks like you did not initiate session for reading the CDB datastore.

See e.g. basic example in ConfD user guide - chapter CDB - 7.3. An example (cdb_start_session() used in read_conf() procedure in the chapter…)