libubox: How to terminate uloop orderly?
akoch at initse.com
Tue May 17 02:04:13 PDT 2022
I'm writing a small daemon in C that talks to a specific IC and shall offer its
functionality to other OpenWRT components via ubus.
It spawns a separate pthread for all ubus related things, which ends up calling
`uloop_run()`. So far everything works fine and I can see all objects exposed by
my daemon on the bus.
The issue I'm facing now is that I cannot seem to find a way of orderly shutting
down the daemon, as the thread calling `uloop_run()` never returns from it. I've
tried calling `uloop_end()` as well as replacing `uloop_run()` by
`uloop_run_timeout(10)` but that didn't help.
So I'm wondering: what is the correct way to terminate the uloop?
One thing that does seem to work is sending the thread a SIGTERM via
`pthread_kill()`. But that makes `uloop_run()` return a non-zero value (15) and,
as signals are delivered to the entire process, can have side-effects on other
parts of the daemon, so I'd prefer to avoid this method.
Thanks in advance for any hints!
More information about the openwrt-devel