We’re working on an app that listens for digital input changes and then records them with a timestamp. At a later time, a separate app makes IPC calls to retrieve this data and flush it out.
Every time the separate app makes a call to retrieve the data, the data retrieved is incorrect, and the digital inputs app seg faults immediately after finishing any of the IPC functions specified in brnkl_digital.api. As it stands, digital input values are stored in a fixed size, statically allocated array with no sanity checks. I understand that this is somewhat dangerous, however the plan for the future is to shift out old values to make room for new ones. For the time being we’ve been sure to test this with a low number of digital changes to avoid running out of memory.
This issue seems to go away when I comment out the contents of digital_changeHandler which leads me to believe this issue is caused by incorrect usage of the Legato event loop.
Anyone have any ideas on how to further debug this?
Run logread -f and then launch your apps. Set your apps to manual start for debugging to make it easier to capture clean logs.
Start the service app and make sure that sdir list doesn’t show any waiting clients
When you call le_digitalX_AddChangeEventHandler() an opaque “handle” is returned. Basically there are two things you can do with it. Pass it back to the le_digitalX_RemoveChangeEventHandler() function and check the value against NULL. If the handle is NULL, then the registration failed. Make sure that you log that failure or use LE_FATAL() so that it’s obvious if the registration fails.
Thanks for the suggestions. Turns out it’s related to something I was curious about in my last post.
Over the weekend I realized I was writing into an array without specifying the max size in the .api file. I added the max size specification and then received a compile time error for conflicting function definitions. I dug into the generated build files a bit and noticed the build system was automatically adding parameters for pointers to array sizes directly after each array pointer. After re-defining my functions to include these new pointers, everything seems to work as expected.
I must say, there was a decent amount to unravel here that wasn’t very obvious by reading the docs or sample apps (unless I missed something). Are the docs open sourced anywhere? I would be happy to spend sometime improving them. Additionally, I could open a pull request to include our example app in the MangOH repo if this is desirable.