summaryrefslogtreecommitdiff
path: root/log
diff options
context:
space:
mode:
authorJohn Crispin <blogic@openwrt.org>2014-01-22 16:35:21 +0000
committerJohn Crispin <blogic@openwrt.org>2014-01-22 16:35:21 +0000
commitf3b07dd3c6eca504cf082e2cf6c0d9e9aa1e91a6 (patch)
tree9f96e0efaca1bad381d8d5bd3487d96d32e0d989 /log
parentcb6425ce059ddcd4ade45200fdcc39234ff500ad (diff)
downloadubox-f3b07dd3c6eca504cf082e2cf6c0d9e9aa1e91a6.tar.gz
ubox: make logd use new ubus autoconnect
Signed-off-by: John Crispin <blogic@openwrt.org>
Diffstat (limited to 'log')
-rw-r--r--log/logd.c39
1 files changed, 6 insertions, 33 deletions
diff --git a/log/logd.c b/log/logd.c
index 978d7d1..eda3a7d 100644
--- a/log/logd.c
+++ b/log/logd.c
@@ -25,8 +25,7 @@
int debug = 0;
static int notify;
static struct blob_buf b;
-static struct ubus_context *_ctx;
-static struct uloop_timeout ubus_timer;
+static struct ubus_auto_conn conn;
static const struct blobmsg_policy read_policy =
{ .name = "lines", .type = BLOBMSG_TYPE_INT32 };
@@ -126,44 +125,20 @@ ubus_notify_log(struct log_head *l)
blobmsg_add_u32(&b, "source", l->source);
blobmsg_add_u64(&b, "time", (((__u64) l->ts.tv_sec) * 1000) + (l->ts.tv_nsec / 1000000));
- ret = ubus_notify(_ctx, &log_object, l->data, b.head, -1);
+ ret = ubus_notify(&conn.ctx, &log_object, l->data, b.head, -1);
if (ret)
fprintf(stderr, "Failed to notify log: %s\n", ubus_strerror(ret));
}
static void
-ubus_reconnect_cb(struct uloop_timeout *timeout)
-{
- if (!ubus_reconnect(_ctx, NULL))
- ubus_add_uloop(_ctx);
- else
- uloop_timeout_set(timeout, 1000);
-}
-
-static void
-ubus_disconnect_cb(struct ubus_context *ctx)
-{
- ubus_timer.cb = ubus_reconnect_cb;
- uloop_timeout_set(&ubus_timer, 1000);
-}
-
-static void
-ubus_connect_cb(struct uloop_timeout *timeout)
+ubus_connect_handler(struct ubus_context *ctx)
{
int ret;
- _ctx = ubus_connect(NULL);
- if (!_ctx) {
- uloop_timeout_set(timeout, 1000);
- fprintf(stderr, "failed to connect to ubus\n");
- return;
- }
- _ctx->connection_lost = ubus_disconnect_cb;
- ret = ubus_add_object(_ctx, &log_object);
+ ret = ubus_add_object(ctx, &log_object);
if (ret)
fprintf(stderr, "Failed to add object: %s\n", ubus_strerror(ret));
fprintf(stderr, "log: connected to ubus\n");
- ubus_add_uloop(_ctx);
}
int
@@ -172,12 +147,10 @@ main(int argc, char **argv)
signal(SIGPIPE, SIG_IGN);
uloop_init();
- ubus_timer.cb = ubus_connect_cb;
- uloop_timeout_set(&ubus_timer, 1000);
log_init();
+ conn.cb = ubus_connect_handler;
+ ubus_auto_connect(&conn);
uloop_run();
- if (_ctx)
- ubus_free(_ctx);
log_shutdown();
uloop_done();