]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
client: flush output after each block
authorVincent Bernat <vincent@bernat.im>
Wed, 22 Jun 2016 16:06:08 +0000 (18:06 +0200)
committerVincent Bernat <vincent@bernat.im>
Wed, 22 Jun 2016 16:06:08 +0000 (18:06 +0200)
This enables to get realtime output from "lldpcli watch".

See #187.

src/client/jansson_writer.c
src/client/jsonc_writer.c
src/client/kv_writer.c
src/client/text_writer.c
src/client/xml_writer.c

index 0fb179d9034e591cbc751d65e9beddd529eff1d5..6181518c68e2ca63d867a2cbb0b97d76a5f0735b 100644 (file)
@@ -169,6 +169,7 @@ jansson_end(struct writer *w)
                        JSON_INDENT(2) | JSON_PRESERVE_ORDER) == -1)
                        log_warnx("lldpctl", "unable to output JSON");
                fprintf(p->fh,"\n");
+               fflush(p->fh);
                json_decref(export);
                json_decref(root->el);
                root->el = json_object();
index 332712e7ae2e3d41808d06683cf2c1e1abf35f91..2e83f0251f30783b785dafc80ebf2776ce0746dc 100644 (file)
@@ -163,6 +163,7 @@ jsonc_end(struct writer *w)
                int json_flags = (JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED);
                const char *s = json_object_to_json_string_ext(export, json_flags);
                fprintf(p->fh, "%s\n", s?s:"{}");
+               fflush(p->fh);
                json_object_put(export);
                json_object_put(root->el);
                root->el = json_object_new_object();
index 9df3c90380f5b94ce8b208df4c2d6bc9c66f32af..68a50adf8fa140cf658806ffce52636886827c82 100644 (file)
@@ -76,9 +76,10 @@ kv_end(struct writer *w)
        struct kv_writer_private *p = w->priv;
        char *dot;
 
-       if ((dot = strrchr(p->prefix, '\1')) == NULL)
+       if ((dot = strrchr(p->prefix, '\1')) == NULL) {
                p->prefix[0] = '\0';
-       else
+               fflush(p->fh);
+       } else
                *dot = '\0';
 }
 
index 02dbdf9a9f187863b2992c68a44f041cd0d892b6..7552c63f4c61ad830db6da2ff5fd791f0675cef6 100644 (file)
@@ -102,8 +102,10 @@ txt_end(struct writer *w) {
        struct txt_writer_private *p = w->priv;
        p->level--;
 
-       if (p->level == 1)
+       if (p->level == 1) {
                fprintf(p->fh, "\n%s", sep);
+               fflush(p->fh);
+       }
 }
 
 static void
index 3441866b03e2f5de6d14e47166e522576918f120..15638845996dd3f1063856fbc5374b0e79a6487f 100644 (file)
@@ -96,8 +96,10 @@ void xml_end(struct writer *w) {
                }
 
                xmlFreeTextWriter(p->xw);
-               if (!failed)
+               if (!failed) {
                        xmlDocDump(p->fh, p->doc);
+                       fflush(p->fh);
+               }
                xmlFreeDoc(p->doc);
        }
 }