From: John Crispin Date: Mon, 9 Dec 2013 18:12:15 +0000 (+0100) Subject: logread: fix initial connect. we really need a better reconnect logic X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=0c6d5bd1fc1fd28c71290610faeee11b399c869a;p=oweals%2Fubox.git logread: fix initial connect. we really need a better reconnect logic Signed-off-by: John Crispin --- diff --git a/log/logread.c b/log/logread.c index e8749f8..8c9fda8 100644 --- a/log/logread.c +++ b/log/logread.c @@ -303,6 +303,7 @@ int main(int argc, char **argv) const char *ubus_socket = NULL; int ch, ret, subscribe = 0, lines = 0; static struct blob_buf b; + int retry = 5; while ((ch = getopt(argc, argv, "ufcs:l:r:F:p:S:P:h:")) != -1) { switch (ch) { @@ -351,19 +352,24 @@ int main(int argc, char **argv) return -1; } - ret = ubus_lookup_id(ctx, "log", &id); - if (ret) - fprintf(stderr, "Failed to find log object: %s\n", ubus_strerror(ret)); - - if (!subscribe || lines) { - blob_buf_init(&b, 0); - if (lines) - blobmsg_add_u32(&b, "lines", lines); - ubus_invoke(ctx, id, "read", b.head, read_cb, 0, 3000); - } + /* ugly ugly ugly ... we need a real reconnect logic */ + do { + ret = ubus_lookup_id(ctx, "log", &id); + if (ret) { + fprintf(stderr, "Failed to find log object: %s\n", ubus_strerror(ret)); + sleep(1); + continue; + } + if (!subscribe || lines) { + blob_buf_init(&b, 0); + if (lines) + blobmsg_add_u32(&b, "lines", lines); + ubus_invoke(ctx, id, "read", b.head, read_cb, 0, 3000); + } - if (subscribe) - follow_log(ctx, id); + if (subscribe) + follow_log(ctx, id); + } while (ret && retry--); return 0; }