logread: fix initial connect. we really need a better reconnect logic
authorJohn Crispin <blogic@openwrt.org>
Mon, 9 Dec 2013 18:12:15 +0000 (19:12 +0100)
committerJohn Crispin <blogic@openwrt.org>
Mon, 9 Dec 2013 18:17:36 +0000 (19:17 +0100)
Signed-off-by: John Crispin <blogic@openwrt.org>
log/logread.c

index e8749f8ab24aa7d05d7ab1742731aa2b45546c48..8c9fda8ec06c42d369d54264519f585aac7c9710 100644 (file)
@@ -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;
 }