]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
iptables: flush stdout after every verbose log.
authorMaciej Żenczykowski <maze@google.com>
Tue, 21 Apr 2020 08:15:42 +0000 (01:15 -0700)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 11 May 2020 12:08:24 +0000 (14:08 +0200)
Ensures that each logged line is flushed to stdout after it's
written, and not held in any buffer.

Places to modify found via:
  git grep -C5 'fputs[(]buffer, stdout[)];'

On Android iptables-restore -v is run as netd daemon's child process
and fed actions via pipe.  '#PING' is used to verify the child
is still responsive, and thus needs to be unbuffered.

Luckily if you're running iptables-restore in verbose mode you
probably either don't care about performance or - like Android
- actually need this.

Test: builds, required on Android for ip6?tables-restore netd
  subprocess health monitoring.
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
iptables/iptables-restore.c
iptables/xtables-restore.c

index b0a51d491c5081b2330c168a94be6c2f2af0424d..fea04842d38c80347b98871b74054cd8b7e7bfaa 100644 (file)
@@ -178,8 +178,10 @@ ip46tables_restore_main(const struct iptables_restore_cb *cb,
                if (buffer[0] == '\n')
                        continue;
                else if (buffer[0] == '#') {
-                       if (verbose)
+                       if (verbose) {
                                fputs(buffer, stdout);
+                               fflush(stdout);
+                       }
                        continue;
                } else if ((strcmp(buffer, "COMMIT\n") == 0) && (in_table)) {
                        if (!testing) {
index c472ac9bf651b3f85bd1db925b3a197ca46dbef8..8c25e5b29d4314e5ad5bf85795cb4e585f04fe35 100644 (file)
@@ -85,8 +85,10 @@ static void xtables_restore_parse_line(struct nft_handle *h,
        if (buffer[0] == '\n')
                return;
        else if (buffer[0] == '#') {
-               if (verbose)
+               if (verbose) {
                        fputs(buffer, stdout);
+                       fflush(stdout);
+               }
                return;
        } else if (state->in_table &&
                   (strncmp(buffer, "COMMIT", 6) == 0) &&