summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Crispin <blogic@openwrt.org>2013-06-27 19:09:12 +0200
committerJohn Crispin <blogic@openwrt.org>2013-06-27 20:20:18 +0200
commit7f31a19db4c88ca17837a2aaa9144622522d0726 (patch)
treea4bc025998e55a3fa4504cec14fee21c1a8c0337
parentbdac146facb72ce3f88f682d598d3124ec73fe78 (diff)
downloadunitd-7f31a19db4c88ca17837a2aaa9144622522d0726.tar
unitd-7f31a19db4c88ca17837a2aaa9144622522d0726.zip
make ubus handling use uloop timers
Signed-off-by: John Crispin <blogic@openwrt.org>
-rw-r--r--ubus.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/ubus.c b/ubus.c
index 202646a..54ead33 100644
--- a/ubus.c
+++ b/ubus.c
@@ -23,6 +23,7 @@ char *ubus_socket = NULL;
static struct ubus_context *ctx;
static struct uloop_process ubus_proc;
static bool ubus_connected = false;
+static struct uloop_timeout retry;
static int reconnect = 1;
static void procd_ubus_connection_lost(struct ubus_context *old_ctx);
@@ -67,9 +68,9 @@ static void procd_ubus_try_connect(void)
ubus_connected = !ubus_reconnect(ctx, ubus_socket);
return;
}
-
ctx = ubus_connect(ubus_socket);
if (!ctx) {
+ ubus_connected = false;
DEBUG(2, "Connection to ubus failed\n");
return;
}
@@ -82,20 +83,25 @@ static void procd_ubus_try_connect(void)
ubus_init_log(ctx);
}
-static void procd_ubus_connection_lost(struct ubus_context *old_ctx)
+static void
+procd_ubus_reconnect_timer(struct uloop_timeout *timeout)
{
- if (!reconnect)
- return;
-
procd_ubus_try_connect();
- while (!ubus_connected) {
- procd_restart_ubus();
- sleep(1);
- procd_ubus_try_connect();
+ if (ubus_connected) {
+ DEBUG(1, "Connected to ubus, id=%08x\n", ctx->local_id);
+ ubus_add_uloop(ctx);
+ return;
}
- DEBUG(1, "Connected to ubus, id=%08x\n", ctx->local_id);
- ubus_add_uloop(ctx);
+ uloop_timeout_set(&retry, 1000);
+ procd_restart_ubus();
+}
+
+static void procd_ubus_connection_lost(struct ubus_context *old_ctx)
+{
+ retry.cb = procd_ubus_reconnect_timer;
+ procd_restart_ubus();
+ uloop_timeout_set(&retry, 1000);
}
void procd_connect_ubus(void)