]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
dhcpcd: stdout output sometimes empty when redirected to a file (#364)
authorDiego Santa cruz <diego.santacruz@spinetix.com>
Thu, 10 Oct 2024 10:45:34 +0000 (12:45 +0200)
committerGitHub <noreply@github.com>
Thu, 10 Oct 2024 10:45:34 +0000 (11:45 +0100)
Running dhpcd --dumplease with input from stdin and redirecting stdout
to a file outputs nothing to the output. The reason is that printf /
fprintf is used to write the output but it is not explicitly flushed
when done, or before exiting, and stdout to files is fully buffered by
default while stdout to terminals is line buffered by default.

This adds calls to fflush() at the end of dhcp_print_option_encoding()
and script_dump(), plus one just before exiting dhcpcd.

Signed-off-by: Diego Santa Cruz <diego.santacruz@spinetix.com>
src/dhcp-common.c
src/dhcpcd.c
src/script.c

index 2130cb09108fbd47191ec1f4f24cda145a6b36fb..295ef74fc041b96702038d95f085e4021a1dc43d 100644 (file)
@@ -136,6 +136,7 @@ dhcp_print_option_encoding(const struct dhcp_opt *opt, int cols)
        if (opt->type & OT_NOREQ)
                printf(" norequest");
        putchar('\n');
+       fflush(stdout);
 }
 
 struct dhcp_opt *
index 654e1c0fd88ced567d1fce1e2e48c10b66ee201b..5fee26aa53bf1b0a9b7a0f16b58a3f39b5c4340b 100644 (file)
@@ -2719,6 +2719,7 @@ exit1:
        eloop_free(ctx.eloop);
        logclose();
        free(ctx.logfile);
+       fflush(stdout);
        free(ctx.ctl_buf);
 #ifdef SETPROCTITLE_H
        setproctitle_fini();
index 4c71b8d092ba053ac44930465afb3513dc240bc4..3ee2eaa461d9ebcebe63e2ad5018e826ded8a508 100644 (file)
@@ -738,6 +738,7 @@ script_dump(const char *env, size_t len)
                        env += 4;
                printf("%s\n", env);
        }
+       fflush(stdout);
        return 0;
 }