diff options
author | Alexandru Ardelean <aardelean@riverbed.com> | 2016-05-05 14:03:30 +0300 |
---|---|---|
committer | Felix Fietkau <nbd@nbd.name> | 2016-10-12 20:00:35 +0200 |
commit | 312448a5b147c221836827a7a641e76a4514db44 (patch) | |
tree | e168eb7db0958f9440f3587cd2668478d2fe7511 | |
parent | ba45b27f8c1c4d56ebff7c584a471cdbce232ec8 (diff) | |
download | ubus-312448a5b147c221836827a7a641e76a4514db44.tar.gz |
cli: register event handler first, then do lookup
We seem to be getting timeout for ubus wait_for calls
every now and then.
And it's not reliably reproducible.
Looking at the code the only thing that would look like
a potetntial reason, is that between the ubus_lookup() and
ubus_register_event_handler() calls, there's a very narrow
window where the event would get sent out and we would not
get it, thus having to timeout.
It doesn't look like registering the event handler first
is a big problem for the whole wait_check_object() logic.
Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
-rw-r--r-- | cli.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -293,17 +293,20 @@ static int ubus_cli_wait_for(struct ubus_context *ctx, int argc, char **argv) uloop_init(); ubus_add_uloop(ctx); - ret = ubus_lookup(ctx, NULL, wait_list_cb, &data); + ret = ubus_register_event_handler(ctx, &data.ev, "ubus.object.add"); if (ret) return ret; if (!data.n_pending) return ret; - ret = ubus_register_event_handler(ctx, &data.ev, "ubus.object.add"); + ret = ubus_lookup(ctx, NULL, wait_list_cb, &data); if (ret) return ret; + if (!data.n_pending) + return ret; + uloop_timeout_set(&data.timeout, timeout * 1000); uloop_run(); uloop_done(); |