Why get_next cb is called twice for the same keypath?

Hi,

I have tried to modify 5-c_stats example for operational data. I have noticed (from the trace calls and using gdb) that in the begging get_next is called twice for a single query(only one show cli connand). Why does this happen? And in an other case the second time get_next_object is called instead of simple get_next despite that I haven’t implement get_next_object! How is this possible?

Thank you,
Olia

The CLI (and possibly other NB agents) will sometimes do a get_next() call with next == -1 to find out whether the list is empty or not. Just implement your callbacks according to the documentation, without speculating on how/when/why they will get invoked. Thus whenever you get a get_next() invocation with next == -1, you should just return the keys for the first list entry and a next value that you can use for the second entry - or NULL for the keys if there are no entries. Just like the example does.

Good question - of course I’ll have to ask how you could determine that the get_next_object callback was invoked when you don’t have one… I could venture a guess that you called confd_register_data_cb() with a struct confd_data_cbs that had some random data for the get_next_object element. Perhaps you have the struct on the stack and don’t zero it out like the example does?

Yes, you are right.
Thank you very much for your help!